Jump to content
  • Advertisement
Sign in to follow this  

osg keyboardhandler class

This topic is 2991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm new to this forum and 3d programming. Sorry if I've posted this in the wrong section. My task is loading a number of 3ds files and creating rotation of the different parts of the object or moving the entire object. I am referring to the sample code I got from the osg tutorials page: The problem description is: I have nodes defined in my main() and functions such as moveForward that affect the nodes in main. The keyboardeventhandler uses function pointers and I have left that code more or less unchanged except for adding parameters. I wanted some tips on how I can modify my keyboardeventhandler to allow me to do this. (I am also looking at SDL side by side but wanted to know if this thing below is a less useful path than using SDL). My code is as follows: //Main file: edited to include important parts: int main( int argc, char **argv ) { double horizontalPosition = 0; double boomAngle = -30.0; osg::Group* Backhoe = NULL; osg::PositionAttitudeTransform* BackhoeXForm = new osg::PositionAttitudeTransform(); osg::Group* Crane = NULL; osg::Node* Stick = NULL; osg::PositionAttitudeTransform* StickXForm = new osg::PositionAttitudeTransform(); osg::MatrixTransform* sceneTilt = new osg::MatrixTransform; osgViewer::Viewer viewer; //ROOT NODE: osg::Group* root = NULL; root = new osg::Group(); //BACKHOE--load files from disk Backhoe = new osg::Group(); Stick = osgDB::readNodeFile("_BHStic_.lwo"); Boom = osgDB::readNodeFile("_BHBoom_.lwo"); //TRACKS: TrackXForm->setPosition(osg::Vec3(0,0,0)); Backhoe->addChild(TrackXForm); TrackXForm->addChild(Track); . . . . keyboardEventHandler* keh = new keyboardEventHandler(); keh->addFunction('q',keyboardEventHandler::KEY_DOWN,moveForward(BackhoeXForm, horizontalPosition)); . . }//end of main. ----------------------------------------------------------------------------- I have functions to cause rotation etc in Main.cpp: for example void moveForward(osg::PositionAttitudeTransform* PAT, double& value) { cout << "q"; value -= 1; PAT->setPosition(osg::Vec3(horizontalPosition,0,0)); } ------------------------------------------------------------------------------ The Keyboardhandler classes as provided by the osg tutorial is as: class keyboardEventHandler : public osgGA::GUIEventHandler { public: typedef void (*functionType) (osg::PositionAttitudeTransform* PAT, double& value); enum keyStatusType { KEY_UP, KEY_DOWN }; struct functionStatusType { functionStatusType() {keyState = KEY_UP; keyFunction = NULL;} functionType keyFunction; keyStatusType keyState; }; bool addFunction(int whatKey, functionType newFunction); -------------------------------------------------------------------------- The compile error comes up in the keyboardhandler.cpp in the function below: in the line keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey()); bool keyboardEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { bool newKeyDownEvent = false; bool newKeyUpEvent = false; switch(ea.getEventType()) { case(osgGA::GUIEventAdapter::KEYDOWN): { keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey()); if (itr != keyFuncMap.end()) { if ( (*itr).second.keyState == KEY_UP ) { (*itr).second.keyState = KEY_DOWN; newKeyDownEvent = true; } if (newKeyDownEvent) { (*itr).second.keyFunction(); newKeyDownEvent = false; } return true; } return false; } case(osgGA::GUIEventAdapter::KEYUP): { keyFunctionMap::iterator itr = keyFuncMap.find(ea.getKey()); if (itr != keyFuncMap.end() ) { (*itr).second.keyState = KEY_UP; } itr = keyUPFuncMap.find(ea.getKey()); if (itr != keyUPFuncMap.end()) { (*itr).second.keyFunction(); return true; } return false; } default: return false; } } Hoping for some pointers.... Thanks.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!