I am working on OpenSceneGraph for the first time, and I am a little lost, because the documentation is really not that clear ...
So, I have this code that loads the obj file with the house on it, and I drowned a small box where I need a “man”. So now, instead of having this box there, I would like to have a camera there, looking at the front, and then at something, to move the terrain around the stationary camera so that it looks like the camera is moving, but the landscape 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 field correctly, puts the box where I want, and can move with the mouse.
Now I just can’t find anything to put the camera where the box is. I just can not.
- , ? , , Viewer Camera .