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();
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With