Hi Christian,

The only reason I'd expect this not to work would be if a
CameraManipulator is attached to the viewer and this is overriding the
values you are setting.  Your code segment isn't attaching a
CameraManipulator so I wouldn't expect this to be an issue, however if
you call viewer.run() it will attach a TrackballManipultaor.

Robert.

On 21 June 2012 11:52, Christian Wolf <[email protected]> wrote:
> Hi,
>
> i have tried to move the Camera in my scene with the keyboard.
> I have created a subclass of the GUIEventHandler()-Class and i have 
> overridden the handle()-funtion. I want to use the UP/DOWN/LEFT/RIGHT 
> Buttons. I can see on the console that if i press one of these Buttons that i 
> get the correct cout Statement that i have implentet in the 
> switch/case-Statement for every button. But it seems that the 
> viewer->getCamera()->setViewMatrixAsLookAt(...) does not do anything.
>
> Can someone give me a hint what is wrong???
> Here is the Code. And sorry for my bad English. ;)
>
> class KeyboardEventHandler: public osgGA::GUIEventHandler {
> public:
>        KeyboardEventHandler(){}
>        ~KeyboardEventHandler(){}
>
> virtual bool handle(const osgGA::GUIEventAdapter& ea, 
> osgGA::GUIActionAdapter& us) {
>
> osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer*>(&us);
> viewer->getCamera()->setAllowEventFocus(false);
>                osg::Vec3 eye(1.0, 10.0, -3.0);
>                osg::Vec3 center(2.0, 0.0, -2.0);
>                osg::Vec3 up(1.0, 0.0, 0.0);
>
> viewer->getCamera()->setViewMatrixAsLookAt(eye, center, up);
> switch(ea.getKey()) {
>
> case(osgGA::GUIEventAdapter::KEY_Down): {
> viewer->getCamera()->setViewMatrixAsLookAt(osg::Vec3(1.0, 15.0, -3.0), 
> osg::Vec3(2.0, 0.0, -2.0), osg::Vec3(1.0, 0.0, 0.0));
>        std::cout << "down" << endl;
>              return true;
>        }
>
>        case(osgGA::GUIEventAdapter::KEY_Up): {
>        std::cout << "up" << endl;
>        return true;
>        }
>
>        case(osgGA::GUIEventAdapter::KEY_Left): {
>        cout << "left" << endl;
>        return true;
>        }
>
>        case(osgGA::GUIEventAdapter::KEY_Right): {
>        cout << "right" << endl;
>        return true;
>        }
>
>        default:
>        return false;
>        }
>        }
> };
>
> //main.cpp
>
>  osgViewer::Viewer viewer;
>   viewer.setSceneData(root);
>        viewer.addEventHandler(new KeyboardEventHandler);
>        viewer.realize();
>              while(!viewer.done()) {
>        viewer.frame();
>        }
>
>
>
> Thank you very much!
>
> Cheers,
> Christian Wolf
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=48405#48405
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to