Hi,
In my OSG application, I am trying to implement a functionality, that would
allow me to switch between usual manual movement and an automatic one (such as
spinning on spot), but I haven't had any success yet.
My last attempt was to set an update callback to the camera, that would spin it
around, such as this:
Code:
void CameraCallback::operator()(Node* node, NodeVisitor* nv)
{
Camera * cam = static_cast<Camera *>(node);
if(cam && Settings::Instantiate()->getCameraMode() == CAMERA_ROTATE)
{
Matrixd oldMatrix = cam->getViewMatrix();
Matrixd cameraRotation;
cameraRotation.makeRotate(oldMatrix.getRotate());
cameraRotation.rotate(DegreesToRadians(5.0), 0, 0, 1);
Matrixd cameraTrans;
cameraTrans.makeTranslate(oldMatrix.getTrans());
Matrixd newMatrix = cameraRotation * cameraTrans;
cam->setViewMatrix(newMatrix);
}
traverse(node, nv);
}
... and then I had the viewer object registered by the class that handles
keyboard events and tried to update it accordingly:
Code:
void registerViewer(Viewer* v) { viewer = v; man =
viewer->getCameraManipulator(); }
bool KeyboardEventHandler::handle(const GUIEventAdapter& ea, GUIActionAdapter&
aa)
{
...
case 'n':
case 'N':
Settings::Instantiate()->ToggleCamera();
if(Settings::Instantiate()->getCameraMode() == CAMERA_MANUAL)
{
viewer->setCameraManipulator(man);
viewer->getCamera()->setAllowEventFocus(true);
}
else
{
viewer->setCameraManipulator(NULL);
viewer->getCamera()->setAllowEventFocus(false);
}
break;
...
}
Hopefully these snippets are enough for someone to explain me, what I am doing
wrong and how to do it the right way.
Thank you!
Cheers,
Martin
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=53691#53691
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org