Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ OpenSceneGraph Change Camera Eye Height

Writing a small openscenegraph application, and in need of a way to change the Camera height. Essentially, the eye is looking straight at a Ball in the space. What I want to do is be able to lower the Camera height so I am able at the ball from below, and also raise the camera height if I need to. How do I achieve this either with oPengl code or OpenScenegraph?

int main(int argc, char* argv[])
{ 
    osg::ref_ptr<osg::ShapeDrawable> shape2 = new osg::ShapeDrawable; 
    shape2->setShape( new osg::Sphere(osg::Vec3(3.0f, 0.0f, 0.0f),1.0f) ); 
    shape2->setColor( osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); 
    osg::ref_ptr<osg::Geode> root = new osg::Geode; 
    root->addDrawable( shape2.get() );///add first osgshapeDrawable2  
    osgViewer::Viewer viewer;
    viewer.setSceneData( root.get() );///set the Geode as scenedata for the viewer
    return viewer.run();
}
like image 745
Kobojunkie Avatar asked Nov 03 '22 10:11

Kobojunkie


1 Answers

You need to take over control of the osgViewer::Camera, you should not try to do this with basic OpenGL.

osgViewer::Viewer::getCameraWithFocus should get you the Camera. From here you can set the position and lookat of the Camera.

Keep in mind, in a basic app like you have there, the Camera Manipulator is setting the position of the camera (based on mouse interaction) once per frame.

You will need to decide how you want to deal with mouse input and possibly take over the task the Camera Manipulator is doing.

like image 160
XenonofArcticus Avatar answered Nov 12 '22 10:11

XenonofArcticus