Hi folks

 I switched from OSG 2.0 to version 2.2 and stumbled over the keyboard
handler. I add to my viewer some manipulators like in osgviewer:

        osgGA::KeySwitchMatrixManipulator* ksm = new
osgGA::KeySwitchMatrixManipulator();

        ksm->addMatrixManipulator( '1', "Trackball", new
osgGA::TrackballManipulator() );
        ksm->addMatrixManipulator( '2', "Flight", new
osgGA::FlightManipulator() );
        ksm->addMatrixManipulator( '3', "Drive", new
osgGA::DriveManipulator() );
        ksm->addMatrixManipulator( '4', "Terrain", new
osgGA::TerrainManipulator() );

        viewer.setCameraManipulator( ksm );

 After that I add for example the stats handler and my own keyboard
event handler (also like in the examples):

        viewer.addEventHandler( new osgViewer::StatsHandler );
        viewer.addEventHandler( new KeyboardEventHandler );

KeyboardEventHandler looks like this:

        class KeyboardEventHandler : public osgGA::GUIEventHandler
        {
        public:
                KeyboardEventHandler()  {}
                ~KeyboardEventHandler() {}

                virtual bool KeyboardEventHandler::handle(const
osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&)
                {
                        switch(ea.getEventType())
                        {
                                case(osgGA::GUIEventAdapter::KEYDOWN):
                                {
        
KeyboardEventHandler::handle_keyboard((char)ea.getKey());
                                        return true;
                                }
                                case(osgGA::GUIEventAdapter::KEYUP):
                                {
                                        return true;
                                }

                                default:
                                        return false;
                        }
                }

                virtual void
KeyboardEventHandler::accept(osgGA::GUIEventHandlerVisitor& v) {
v.visit(*this); }
                virtual void KeyboardEventHandler::handle_keyboard(char
lastkey)
                {
                        switch (lastkey)
                        {
                                case('x'):
                                {
                                        std::cout << "x" << std::endl;
                                        break;
                                }
        
                                default:
                                std::cout << "- '" << lastkey << "' ("
<< (int)lastkey << ") isn't maped jet" << std::endl;                    
                                break;
                        }
                };
        };

If I press in the running app the key 'x', "x" is printed. If I press
's' I see the stats. But if I press '1', '2', '3' or '4' nothing
happens, the manipulators don't switch. Without adding my own handler to
the viewer I can press '3' and drive around, pressing 's' and viewing
stats (and of cause don't print "x").
Can somebody tell me why a self-made keyboard handler in OSG 2.2 stops
only the manipulators from switching and how to cure this problem
(working on WinXP SP2)? Looking forward to your answers.
--  
Andreas Richter 
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to