[osg-users] Problems with tutorial on Handling Keyboard Input to Update a Callback

2009-06-24 Thread Nadia Comanici
Hi,

I've just started using osg, and i've tried the tutorials, like the Handling 
Keyboard Input to Update a Callback tutorial, and i wrote the following code:


Code:
osgViewer::Viewer viewer;
ObjectManipulator* displayHandler = new ObjectManipulator();
viewer.addEventHandler(displayHandler); 
viewer.setSceneData(geode);
viewer.setUpViewInWindow(100, 100, 800, 600); 
viewer.run();



and


Code:
#include osgGA/GUIEventHandler
class ObjectManipulator: public osgGA::GUIEventHandler
{
public:
virtual bool handle(const osgGA::GUIEventAdapter ea, 
osgGA::GUIActionAdapter aa);
virtual void accept(osgGA::GUIEventHandlerVisitor v)   { 
v.visit(*this); };
};

bool ObjectManipulator::handle(const osgGA::GUIEventAdapter 
ea,osgGA::GUIActionAdapter aa)
{   
  switch(ea.getEventType())
  {
case(osgGA::GUIEventAdapter::KEYDOWN):
{
   switch(ea.getKey())
  {
case 'w':
std::cout   w key pressed  std::endl;
return false;
break;
default:
return false;
  } 
}
default:
  return false;  
  }
}



The problem is that it never gets inside the 
case(osgGA::GUIEventAdapter::KEYDOWN) instruction; Do I need to include 
anything else? or why doesn't it work?

Thank you!
  Nadia[/code]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=14433#14433





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problems with tutorial on Handling Keyboard Input to Update a Callback

2009-06-24 Thread Ulrich Hertlein

Hi Nadia,

On 24/6/09 11:43 AM, Nadia Comanici wrote:

Code:
#includeosgGA/GUIEventHandler
class ObjectManipulator: public osgGA::GUIEventHandler
{
public:
virtual bool handle(const osgGA::GUIEventAdapter  ea, 
osgGA::GUIActionAdapter  aa);
virtual void accept(osgGA::GUIEventHandlerVisitor  v)   { 
v.visit(*this); };
};

bool ObjectManipulator::handle(const osgGA::GUIEventAdapter  
ea,osgGA::GUIActionAdapter  aa)
{   
   switch(ea.getEventType())
   {
 case(osgGA::GUIEventAdapter::KEYDOWN):
 {
switch(ea.getKey())
   {
 case 'w':
 std::cout   w key pressed  std::endl;
 return false;
 break;
 default:
 return false;
   }
 }
 default:
   return false;
   }
}


The problem is that it never gets inside the 
case(osgGA::GUIEventAdapter::KEYDOWN)
instruction; Do I need to include anything else? or why doesn't it work?


The handle() itself looks okay, but some things look odd:
- why did you overload the 'accept()' method?
  I don't know if it hurts but it's certainly not necessary.
- handle() should return 'true' when the event was handled

Cheers,
/ulrich
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problems with tutorial on Handling Keyboard Input to Update a Callback

2009-06-24 Thread Nadia Comanici
Thank you very much ulrich, it was exactly what i needed

Cheers,
Nadia

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=1#1





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org