Hi Martin,
what are you experiencing, where you see the problems? It is sort of not
stated in your email. in your first code snipped in the update I would do
this to have the matrices in the world space:
Matrixd oldMatrix = cam->getInverseViewMatrix();
.
.
cam->setViewMatrix(osg::Matrixd::inverse(newMatrix));
This should setup your matrices correctly. Also once the matrixes are in
world space then you can easelly transition from automatic to manual state
by setting the camera manipulator by matrix. I think when you add and
remove camera manipulators, it goes to your home position of the
manipulator (see CameraManipulator::setHomePosition), so you have to take
into account this as well. If you want to spin it around between two
rotations try using quaternions (from the matrix, it is getRotate()) and
slerp (quaternion method) between two different orientation. These above is
just guessing since you havn't stated your problem. Maybe the best would be
if you put your whole code into sample and post it here, someone might have
time to look and help
Nick
On Thu, Apr 18, 2013 at 6:53 PM, Martin Záleta wrote:
> 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(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
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
--
trajce nikolov nick
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org