From Wang Rui, "For a long time, the osgviewerMFC example uses addSlave() to setup the

graphics context and link it with a slave camera. I don't know the
reason we perform like that, which will cause a problem that the
GUIEventHandler may not obtain correct window coordinates because the
main camera will use a default input range to receive events from the
slave camera's graphics context. It is also weird to see the
addSlave() used in non-cluster applications, which beginners will be
confused with.

I've make a slightly modification to the osgviewerMFC example to make
it work without setting slave cameras. I've tested with the MDI
framework and everything seems fine."
This commit is contained in:
Robert Osfield 2010-06-14 15:25:05 +00:00
parent f2f085bc3f
commit e601bb9cc3

View File

@ -105,8 +105,15 @@ void cOSG::InitCameraConfig(void)
// Set the viewport for the Camera
camera->setViewport(new osg::Viewport(traits->x, traits->y, traits->width, traits->height));
// Set projection matrix and camera attribtues
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
camera->setClearColor(osg::Vec4f(0.2f, 0.2f, 0.4f, 1.0f));
camera->setProjectionMatrixAsPerspective(
30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0, 1000.0);
// Add the Camera to the Viewer
mViewer->addSlave(camera.get());
//mViewer->addSlave(camera.get());
mViewer->setCamera(camera.get());
// Add the Camera Manipulator to the Viewer
mViewer->setCameraManipulator(keyswitchManipulator.get());
@ -118,10 +125,10 @@ void cOSG::InitCameraConfig(void)
mViewer->realize();
// Correct aspect ratio
double fovy,aspectRatio,z1,z2;
/*double fovy,aspectRatio,z1,z2;
mViewer->getCamera()->getProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
aspectRatio=double(traits->width)/double(traits->height);
mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);
mViewer->getCamera()->setProjectionMatrixAsPerspective(fovy,aspectRatio,z1,z2);*/
}
void cOSG::PreFrameUpdate()