[osg-users] [forum] Change the position and rotation angle of the camera

61 views
Skip to first unread message

ying song

unread,
Apr 1, 2014, 5:37:24 AM4/1/14
to osg-...@lists.openscenegraph.org
Hi,

I draw a box using addDrawable. Then I want to change the position and rotation angle of the camera by:

viewer->getCamera()->setViewMatrix(cameraTranslationMatrix);

But actually it makes no change to the camera. The cube is still in the center of the screen after run the scene.

I also tried to update the frame by using the following code, but also failed:

while(!viewer->done())
{
viewer->getCamera()->setViewMatrixAsLookAt(eye,center,up);
viewer->frame();
}


Would anyone tell me what could I do to move the camera?

Thank you!

Cheers,
Becky

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=58769#58769





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

Robert Osfield

unread,
Apr 17, 2014, 4:22:32 AM4/17/14
to OpenSceneGraph Users
Hi Becky,

If you viewer has a CameraManipulator attached to it he manipulator
will keep overriding the matrix you set on each frame, simply don't
assigned a CameraManipulator and you should be fine.

Robert.

Rodrigo Dias

unread,
May 12, 2020, 1:19:02 PM5/12/20
to OpenSceneGraph Users
Dear Robert,

this doesn't answer the question. Most of us use a manipulator, so the question is: how to change camera position using a
CameraManipulator. Is this possible?

Rodrigo.

Rodrigo Dias

unread,
May 12, 2020, 3:06:25 PM5/12/20
to OpenSceneGraph Users
Hi Becky,

I managed to change the camera position using a manipulator called controller.

    viewer.setCameraManipulator(controller);
    viewer.realize();
    // osg::Matrix matrix;
    // matrix.makeLookAt( osg::Vec3(), osg::Vec3(), osg::Vec3() );
    osg::Quat quad;
    // matrix.get(quad);
    controller->setTransformation(osg::Vec3(-54.4f,-14.3f,80.0f), quad );
    while ( !viewer.done() )
    {
        viewer.frame();
    }
    return 0;

The commented lines were not necessary for me, but may be in other situations.

Best,
Rodrigo.
Reply all
Reply to author
Forward
0 new messages