Robert Osfield wrote:
Hi Ben,

On Sat, Sep 6, 2008 at 8:28 AM, benben <[EMAIL PROTECTED]> wrote:
Can I add an osg::Camera to an osg::PositionAttitudeTransform node to render
the scene? The idea is to use the transform node to move and orientate the
camera.

The Camera isn't an ordinary object like a car or house that you
position in the scene, the relationship is that the Camera sits above
the scene that you wish to render, this applies to high level Viewe
Camera's just as it does to ones in the scene graph.  The next special
relationship is that the OpenGL modelview matrix the world underneath
the camera positions the world in the local coordinates of the camera,
rather than positioning the camera in world coordinates - this is just
how OpenGL works and OSG works with.

Yes I understand this. But the fact that osg::Camera class is a derivation of the transform node makes me think this can be done that way.


In your own application you need to Camera to contain the scene you
want to render, if it was a leaf of your scene graph then it wouldn't
have anything to render.  You could add you scene to the Camera but
this would cause a circular cycle in the scene graph and bag you'd end
up reccursing till your memory blows... so that certainly work either.

Second you want to set the Camera's view matrix to be the inverse of
the model matrix, rather than the the model matrix that will be
inherited down to the Camera that you have in your setup.  So again we
are getting the opposite of what you want by placing the Camera as a
leaf.

So this brings us to how do you solve the task of following nodes in
the scene?  The osgGA::NodeTrackerManipulator is one solution, as is
holding the NodePath from the root of your scene to the node you want
to set the position by, and then computing the world to local
transform using osg::computeWorldToLocal(NodePath) (this is what
NodeTracker does internally).  If you set the viewer's Camera's view
matrix yourself don't attach a camera manipulator, and just set the
view matrix each frame like:

[snip]

And so I didn't end up writing any sort of manipulator but instead I manually calculate the transformation matrix and update the camera view matrix with setViewMatrix() function.

But there is still one problem nagging me. In my application I wish to view from a local coordinate so the x axis goes into the screen, y-axis to the right, and z-axis down. I ended up having to transform it like this:

    const static vec3 x_axis(1.0, 0.0, 0.0);
    const static vec3 y_axis(0.0, 1.0, 0.0);
    const static vec3 z_axis(0.0, 0.0, 1.0);

    const static double right_angle = -M_PI/2.0;

    static matrix rs1; rs1.makeRotate(right_angle, z_axis);
    static matrix rs2; rs2.makeRotate(-right_angle, x_axis);
    static matrix rs3; rs3.makeRotate(M_PI, z_axis);
    const static matrix rs = rs3*rs2*rs1;

    matrix camview = matrix::inverse(rs*ts*rotation*translation);

    v.getCamera()->setViewMatrix(camview);

but the last few rotations (rs1, rs2, rs3) are not changing from {x-front, y-right, z-down} to {x-right, y-front, z-up}

Would you enlighten me on this?

Yours,
Ben

_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to