Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Robert Osfield
Hi Paulo,

Possible the easiest way to do this would be modify the
osgGA::TrackballManipulator itself (and see in the changes so we can
all benefit :-), or subclass from it and override the handle method to
add the handling of the mouse wheel events.  Once you've done this
you'd need to pass in the mouse wheel events via the
osgGA::EventQueue.

Robert.

On Thu, Feb 26, 2009 at 1:00 PM, Paulo Jnkml paulo.jn...@gmail.com wrote:
 Hi,
 I was writing an application using Qt and osg.
 I would like to zoom in and out on mouse scroll.
 I could not find a good way to do this, so I came up with:

 void osgWidget::wheelEvent(QWheelEvent *event) {

     const float delta(event-delta() / (8.0f * 15.0f));

     const float x(event-x());

     const float y(event-y());

     const float ydy(y + delta);

     const int b(osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON

         | osgGA::GUIEventAdapter::MIDDLE_MOUSE_BUTTON);


     _gw-getEventQueue()-mouseButtonPress(x, y, b);


     _gw-getEventQueue()-mouseMotion(x, ydy);


     _gw-getEventQueue()-mouseButtonRelease(x, ydy, b);

 }

 which actually works but it's not so elegant.
 Is there a obj-zoom(0.9f); to get 10% closer or obj-zoom(1.1f); to get 10%
 further for example?

 thank you.

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


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


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Jean-Sébastien Guay

Hi Martin,


I had a try at doing this through TrackBallManipulator
This seems to work, tested on Windows with viewerQT and viewer.Each mouseWheel 
click zooms in/out by 10%

I'm not an expert and would welcome any suggestions about better ways to do 
this.


That looks a bit like how we did it in our local codebase, except that 
instead of acting directly on _distance, in our case we set dy to 0.1 or 
-0.1 (depending on scroll up or down) and then let the normal mouse 
zooming functionality do the zooming calculations:


if (_ga_t0-getEventType() == osgGA::GUIEventAdapter::SCROLL)
{
dy = _ga_t0-getScrollingMotion() == 
osgGA::GUIEventAdapter::SCROLL_DOWN ? 0.1 : -0.1;

}

It works well too, perhaps you can compare the two and see which one you 
like best in terms of behavior. I don't know if zooming in/out by 10% 
per mouse wheel click is too much or too little, I haven't tested your 
code directly...


And in our case, we didn't add a completely separate case for SCROLL in 
the handle() method, just piggybacked on top of the DRAG case:


case (osgGA::GUIEventAdapter::SCROLL):
case (osgGA::GUIEventAdapter::DRAG):
{
// ...
}

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Martin Beckett
I had a try at doing this through TrackBallManipulator
This seems to work, tested on Windows with viewerQT and viewer.Each mouseWheel 
click zooms in/out by 10%

I'm not an expert and would welcome any suggestions about better ways to do 
this.

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





TrackballManipulator.cpp
Description: Binary data
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Martin Beckett
Thanks Jean-Sébastien,
You can't reuse (osgGA::GUIEventAdapter::DRAG) case in handle() because the 
scroll event needs to be cleared. 

I like the idea of reusing the drag and 'dy' - I have rewritten it with that 
approach. It does lead to having to declare a couple of variables before they 
can be set which seems to be against OSG house style (and is generally a bad 
idea)

I can only test on windows, but so long as the other windows toolkits add mouse 
wheel events to the GUIEventAdapter it should just work.

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





TrackballManipulator.cpp
Description: Binary data
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Jean-Sébastien Guay

Hi Martin,

You can't reuse (osgGA::GUIEventAdapter::DRAG) case in handle() because the scroll event needs to be cleared. 


That's how we do it, and I didn't see any problems... Our code is quite 
close to:


case (osgGA::GUIEventAdapter::SCROLL):
case (osgGA::GUIEventAdapter::DRAG):
{
addMouseEvent(ea);
if (calcMovement()) aa.requestRedraw();
aa.requestContinuousUpdate(false);
_thrown = false;
return true;
}

and it works great. Perhaps there's something else that is different. 
We've subclassed TrackballManipulator and replaced most of its 
functionality with similar (but not quite identical) code...



I like the idea of reusing the drag and 'dy' - I have rewritten it with that 
approach. It does lead to having to declare a couple of variables before they 
can be set which seems to be against OSG house style (and is generally a bad 
idea)


It's not that bad, since you only have an if and an else it can't really 
fall through the cracks. As with any programming convention I tend to be 
pragmatic...


J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Martin Beckett

Skylark wrote:
 
 case (osgGA::GUIEventAdapter::SCROLL):
 case (osgGA::GUIEventAdapter::DRAG):
 {
 addMouseEvent(ea);
 if (calcMovement()) aa.requestRedraw();
 aa.requestContinuousUpdate(false);
 _thrown = false;
 return true;
 }
 

On Windows at least with viewer/viewerQT if you don't call 
flushMouseEventStack() the handle() gets called repeatedly.
I suppose because there isn't really an end event for a mouse scroll.

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





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


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Jean-Sébastien Guay

Hi Martin,


On Windows at least with viewer/viewerQT if you don't call 
flushMouseEventStack() the handle() gets called repeatedly.
I suppose because there isn't really an end event for a mouse scroll.


We're on Windows, and we have a Qt-based application running this (among 
others)... But we don't need to call flushMouseEventStack()... I don't 
know what to say. :-)


J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Qt mouse wheel zoom howto

2009-02-26 Thread Martin Beckett
Aha - I had _thrown=true in my scroll case !
For simplicity I will have SCROLL and DRAG together as you do.
If somebody needs scroll to do more/different it is easy to add as a special 
case.

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





TrackballManipulator.cpp
Description: Binary data
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org