From 214e1b81ed4f0ff79cc8693145561d2d8b92c133 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 25 Jun 2009 18:31:43 +0000 Subject: [PATCH] Simplified throw rate code, and add throw rate compensation into zoom in/out code. --- include/osgGA/TrackballManipulator | 9 +-------- src/osgGA/TrackballManipulator.cpp | 30 ++++++++++-------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/include/osgGA/TrackballManipulator b/include/osgGA/TrackballManipulator index 1cae1676a..061882671 100644 --- a/include/osgGA/TrackballManipulator +++ b/include/osgGA/TrackballManipulator @@ -148,15 +148,8 @@ class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator bool _allowThrow; bool _thrown; - - /** Indicates whether "thrown" display should match rate of motion at time of throw. - * This is significant on systems where the delta between mouse events can be radically different - * from the delta in display update events. - */ - bool _rate_sensitive; - - /** The approximate amount of time it is currently taking to draw a frame. + /** The approximate amount of time it is currently taking to draw a frame. * This is used to compute the delta in translation/rotation during a thrown display update. * It allows us to match an delta in position/rotation independent of the rendering frame rate. */ diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index d01da3bef..da31ba17b 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -12,7 +12,6 @@ TrackballManipulator::TrackballManipulator() _minimumZoomScale = 0.05f; _allowThrow = true; _thrown = false; - _rate_sensitive = true; _distance = 1.0f; _trackballSize = 0.8f; @@ -310,7 +309,12 @@ bool TrackballManipulator::calcMovement() buttonMask = _ga_t1->getButtonMask(); } - + + + double throwScale = (_thrown && _ga_t0.valid() && _ga_t1.valid()) ? + _delta_frame_time / (_ga_t0->getTime() - _ga_t1->getTime()) : + 1.0; + if (buttonMask==GUIEventAdapter::LEFT_MOUSE_BUTTON) { @@ -330,15 +334,8 @@ bool TrackballManipulator::calcMovement() osg::Quat new_rotate; - if (_thrown && _rate_sensitive && _ga_t0.valid() && _ga_t1.valid()) - { - // frame_time / delta_event_time - double rate = _delta_frame_time / (_ga_t0->getTime() - _ga_t1->getTime()); - new_rotate.makeRotate(angle * rate,axis); - } else { - new_rotate.makeRotate(angle,axis); - } - + new_rotate.makeRotate(angle * throwScale,axis); + _rotation = _rotation*new_rotate; return true; @@ -350,18 +347,11 @@ bool TrackballManipulator::calcMovement() // pan model. - float scale = -0.3f*_distance; + float scale = -0.3f * _distance * throwScale; osg::Matrix rotation_matrix; rotation_matrix.makeRotate(_rotation); - if (_thrown && _rate_sensitive && _ga_t0.valid() && _ga_t1.valid()) - { - // frame_time / delta_event_time - double rate = _delta_frame_time / (_ga_t0->getTime() - _ga_t1->getTime()); - scale *= rate; - } - osg::Vec3 dv(dx*scale,dy*scale,0.0f); _center += dv*rotation_matrix; @@ -375,7 +365,7 @@ bool TrackballManipulator::calcMovement() // zoom model. float fd = _distance; - float scale = 1.0f+dy; + float scale = 1.0f+ dy * throwScale; if (fd*scale>_modelScale*_minimumZoomScale) {