Hi Davide,

The OSG's (and most window systems) provide events sequentially for
cases where you press several keys at once.  So what you'll get is
separate calls for pressing and releasing of the different keys and
you'll need to track which ones are pressed at any one time yourself.

Robert.

On Sun, Aug 23, 2009 at 10:51 PM, Davide Byron<[email protected]> wrote:
> Hi everybody,
> I'm pretty sure the solution to my problem is simple, but i'm new to osg and 
> i'm having a lot of troubles with this...
> the problem is that i have to handle multiple key press at once, but for now 
> my code takes care of just one at a time (the last key you pressed).
> here's the code i'm using right now:
>
>
> Code:
> virtual bool handle(const osgGA::GUIEventAdapter& ea, 
> osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv)
>        {
>
>        switch (ea.getEventType())
>                {
>            // Possible events we can handle
>            case osgGA::GUIEventAdapter::PUSH: break;
>            case osgGA::GUIEventAdapter::RELEASE: break;
>            case osgGA::GUIEventAdapter::MOVE: break;
>            case osgGA::GUIEventAdapter::DRAG: break;
>            case osgGA::GUIEventAdapter::SCROLL: break;
>            case osgGA::GUIEventAdapter::KEYUP: break;
>                        // this one is really handled
>            case osgGA::GUIEventAdapter::KEYDOWN:
>                                {
>                                        switch (ea.getKey())
>                                        {
>                                                case 'w': { // Rotate upwards 
> for ROTATION degrees (and keep going forward)
>                                                        
> localSpadTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(-ROTATION),
>  osg::X_AXIS));
>                                                        
> localSpadTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                          } break; // <-- 
> useless
>
>                                                case 's': { // Rotate 
> downwards for ROTATION degrees (and keep going forward)
>                                                        
> localSpadTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(ROTATION),
>  osg::X_AXIS));
>                                                        
> localSpadTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>
>                                                case 'a': { // Rotate for 
> ROTATION degrees on the left (and keep going forward)
>                                                        
> localSpadTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(ROTATION),
>  osg::Y_AXIS));
>                                                        
> localSpadTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>
>                                                case 'd': { // Rotate for 
> ROTATION degrees on the right (and keep going forward)
>                                                        
> localSpadTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(-ROTATION),
>  osg::Y_AXIS));
>                                                        
> localSpadTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>
>
>
>
>                                                case 'i': { // Rotate upwards 
> for ROTATION degrees (and keep going forward)
>                                                        
> localFokkerTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(-ROTATION),
>  osg::X_AXIS));
>                                                        
> localFokkerTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                          } break; // <-- 
> useless
>
>                                                case 'k': { // Rotate 
> downwards for ROTATION degrees (and keep going forward)
>                                                        
> localFokkerTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(ROTATION),
>  osg::X_AXIS));
>                                                        
> localFokkerTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>
>                                                case 'j': { // Rotate for 
> ROTATION degrees on the left (and keep going forward)
>                                                        
> localFokkerTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(ROTATION),
>  osg::Y_AXIS));
>                                                        
> localFokkerTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>
>                                                case 'l': { // Rotate for 
> ROTATION degrees on the right (and keep going forward)
>                                                        
> localFokkerTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(-ROTATION),
>  osg::Y_AXIS));
>                                                        
> localFokkerTransform->preMult(osg::Matrix::translate(0, SPEED, 0));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>
>
>                                                case ' ': { // Reset the 
> transformation
>                                                        
> localSpadTransform->setMatrix(osg::Matrix::identity());
>                                                        
> localFokkerTransform->setMatrix(osg::Matrix::identity());
>                                                        
> localFokkerTransform->preMult(osg::Matrix::rotate(osg::DegreesToRadians(180.0f),
>  osg::Z_AXIS));
>                                                        return true;
>                                                                  } break; // 
> <-- useless
>                                        }
>                                        break;
>                        }//switch
>
>                        //default return
>                        return false;
>                }
>
>
>
>
> how can i make the program react to multiple key presses?
> Thanks in advance
>
> Davide
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=16617#16617
>
>
>
>
>
> _______________________________________________
> 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