I am working on OpenSceneGraph for the first time and I'm a bit lost cause the documentation is really not that clear...
So, I have this code that load a obj file with a house on it, and I have drown a little box where I want the "person" to be. So now, instead of having that box there, I would like to have the camera there, looking at the front and later on I'll to something to move the terrain around the fixed camera so that it looks like the camera is moving but the terrain is moving.
So, here is my code:
int main()
{
osgViewer::Viewer viewer;
viewer.setUpViewInWindow(0,0,800,800);
osg::ref_ptr<osg::Group> root (new osg::Group);
osg::Node* terrain = osgDB::readNodeFile(".terrain.obj");
if(terrain == NULL) {
return -1;
}
Geode* gbox = new Geode();
gbox->addDrawable(new ShapeDrawable(new Box()));
PositionAttitudeTransform* terrainT = new PositionAttitudeTransform();
PositionAttitudeTransform* boxT = new PositionAttitudeTransform();
boxT->setScale(Vec3d(50,50,50));
boxT->setPosition(Vec3d(1000,1000,0));
root->addChild(terrainT);
root->addChild(boxT);
terrainT->addChild(terrain);
boxT->addChild(gbox);
viewer.setSceneData( root.get() );
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.realize();
while(!viewer.done()) {
viewer.frame();
}
return 0;
}
So this code works, it loads the the fiel correctly, puts the box where I want and I can navigate with the mouse.
Now, I just really cannot find anything to place the camera where the box is. I just can't.
Can anyone give me a hint of how to do it? It shouldn't be very hard, but I cannot find any good tutorial and the documentation the Viewer and Camera classes is really not very helpful.