Hi,
no need to go into this hassle here is a snippet how to use the scroll info 
from the mouse.
A modified example from Leandro Motta Barros.

Good luck
Dimi

#include <iostream>
#include <string>
#include <sstream>
#include <osg/Geometry>
#include <osgGA/GUIEventHandler>
#include <osgViewer/Viewer> 
#include <osgGA/TrackballManipulator>

// - TranslateScrollData -------------------------------------------------------
std::string TranslateScrollData (const osgGA::GUIEventAdapter& ea)
{
   std::string ret;

   switch (ea.getScrollingMotion())
   {
      case osgGA::GUIEventAdapter::SCROLL_NONE:
         ret += "SCROLL_NONE";
         break;
      case osgGA::GUIEventAdapter::SCROLL_LEFT:
         ret += "SCROLL_LEFT";
         break;
      case osgGA::GUIEventAdapter::SCROLL_RIGHT:
         ret += "SCROLL_RIGHT";
         break;
      case osgGA::GUIEventAdapter::SCROLL_UP:
         ret += "SCROLL_UP";
         break;
      case osgGA::GUIEventAdapter::SCROLL_DOWN:
         ret += "SCROLL_DOWN";
         break;
      case osgGA::GUIEventAdapter::SCROLL_2D:
         ret += "SCROLL_2D";
         break;
   }
   
   std::stringstream sstr;
   sstr << ea.getScrollingDeltaX()<<" "<<ea.getScrollingDeltaY()<<")";
   
   ret += "  Delta = (" + sstr.str();
   return ret;
}

// - MyEventHandler ------------------------------------------------------------
class MyEventHandler: public osgGA::GUIEventHandler
{
   public:
      virtual bool handle (const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter&)
      {
         switch (ea.getEventType())
         {
            case osgGA::GUIEventAdapter::NONE:
            {
               std::cout << "NONE\n\n";
               break;
            }

            case osgGA::GUIEventAdapter::SCROLL:
            {
               std::cout << "SCROLL\n"
                         << "Event data: " << TranslateScrollData (ea) << '\n';
               break;
            }

            default:
            {
                      return false;
            }
         } // switch (...)

         // Time in seconds since the program started
         std::cout << "Time = " << ea.time() << "\n\n";
         return true;
      }
};

// - main ----------------------------------------------------------------------
int main (int argc, char* argv[])
{

   // Create a Producer-based viewer
   osgViewer::Viewer viewer; 
   viewer.setCameraManipulator(new osgGA::TrackballManipulator());
   viewer.setUpViewInWindow (10, 10, 640, 480);

   // A geode is a "geometry node". It is-a 'Node' and contains 'Drawable's.
   osg::ref_ptr<osg::Geode> geode (new osg::Geode());

   // Set scene graph root (the geode, since it is the only 'osg::Node' around)
   viewer.setSceneData (geode.get());

   osg::ref_ptr<osgGA::GUIEventHandler> eh (new MyEventHandler);
   viewer.addEventHandler (eh.get());

   // Enter rendering loop
   viewer.realize();

   while (!viewer.done())
   {
    
      viewer.frame();
   }

}









----- Original Message ----
From: Robert Osfield <[email protected]>
To: OpenSceneGraph Users <[email protected]>
Sent: Monday, April 27, 2009 5:51:04 PM
Subject: Re: [osg-users] Use the mouse scroll button?

Hi Julio,

The TrackballManipulator now has support for mouse wheel, but as it
was added in March you'll need to grab one of the 2.9.x dev release
series or svn/trunk to get access to it.  Potentially you could
backport it to the version of the OSG you are using if it's not one of
the above.

Robert.

On Mon, Apr 27, 2009 at 3:14 PM, Julio Campos Alvarez
<[email protected]> wrote:
> Hello,
>
> I'm trying to use the mouse scroll button as if it was the right mouse
> button. All I want to do is move the camera closer and further with the
> mouse scroll button...
> The problem is that I don't receive the events by just moving the
>
> scroll. In order to get the event I need to press a button (either
> keyboard or mouse), once a button is pressed I will get all the events
> in the queue.
>
> Has anyone done something like this?
>
> Here is the code from my modified trackball manipulator:
>
>
> bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us)
>         {
>             switch(ea.getEventType())
>             {
>                 case(osgGA::GUIEventAdapter::FRAME):
>                     if (_thrown)
>                     {
>                         if (calcMovement()) us.requestRedraw();
>
>                     }
>                     return false;
>                 default:
>                     break;
>             }
>
>             if (ea.getHandled()) return false;
>
>             switch(ea.getEventType())
>             {
>                 case(osgGA::GUIEventAdapter::PUSH):
>                 {
>                     flushMouseEventStack();
>
>                     addMouseEvent(ea);
>                     if (calcMovement()) us.requestRedraw();
>                     us.requestContinuousUpdate(false);
>                     _thrown = false;
>                     return true;
>                 }
>
>                 case(osgGA::GUIEventAdapter::SCROLL):
>
>                 {
>                     int x = 0;
>                                         //Here I have a brakpoint  :)
>                     //_distance += 100.0f;
>                     return true;
>                 }
>                 //
>
>                 case(osgGA::GUIEventAdapter::KEYDOWN):
>                     if (ea.getKey()== osgGA::GUIEventAdapter::KEY_Space)
>                     {
>                         flushMouseEventStack();
>                         _thrown = false;
>                         home(ea,us);
>                         return true;
>                     }
>
>                     return false;
>
>
> Thank you very much
>
> _______________________________________________
> 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



      
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to