Changeset 10419

Show
Ignore:
Timestamp:
06/25/09 20:11:29 (5 years ago)
Author:
robert
Message:

From Lee Bulter, "I noticed that when "throwing" things the rate of motion once thrown was
dependent on the complexity of the geometry. For complex scenes this
meant that it looked like you were "throwing" the display into molasses.
For simple geometry things get over-excited once thrown.

The fix is to factor in the frame rendering time to the caluclated
motion. I've implemented this for rotation and panning.

Now when things are thrown they maintain a rate very close to what was
happening when the mouse button was released."

Location:
OpenSceneGraph/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgGA/TrackballManipulator

    r10002 r10419  
    150150        bool _thrown; 
    151151         
     152 
     153        /** Indicates whether "thrown" display should match rate of motion at time of throw. 
     154          * This is significant on systems where the delta between mouse events can be radically different 
     155          * from the delta in display update events. 
     156          */ 
     157        bool _rate_sensitive; 
     158 
     159        /** The approximate amount of time it is currently taking to draw a frame.  
     160          * This is used to compute the delta in translation/rotation during a thrown display update. 
     161          * It allows us to match an delta in position/rotation independent of the rendering frame rate. 
     162          */ 
     163        double _delta_frame_time;  
     164 
     165        /** The time the last frame started. 
     166          * Used when _rate_sensitive is true so that we can match display update rate to rotation/translation rate. 
     167          */ 
     168        double _last_frame_time; 
     169 
    152170        osg::Vec3d   _center; 
    153171        osg::Quat    _rotation; 
  • OpenSceneGraph/trunk/src/osgGA/TrackballManipulator.cpp

    r10209 r10419  
    1313    _allowThrow = true; 
    1414    _thrown = false; 
     15    _rate_sensitive = true; 
    1516 
    1617    _distance = 1.0f; 
     
    8283    { 
    8384        case(GUIEventAdapter::FRAME): 
     85        { 
     86            double current_frame_time = ea.getTime(); 
     87 
     88            _delta_frame_time = current_frame_time - _last_frame_time; 
     89            _last_frame_time = current_frame_time; 
     90 
    8491            if (_thrown && _allowThrow) 
    8592            { 
     
    8794            } 
    8895            return false; 
     96        } 
    8997        default: 
    9098            break; 
     
    322330 
    323331        osg::Quat new_rotate; 
    324         new_rotate.makeRotate(angle,axis); 
     332 
     333        if (_thrown && _rate_sensitive && _ga_t0.valid() && _ga_t1.valid()) 
     334        { 
     335            // frame_time / delta_event_time 
     336            double rate = _delta_frame_time / (_ga_t0->getTime() - _ga_t1->getTime()); 
     337            new_rotate.makeRotate(angle * rate,axis); 
     338        } else { 
     339            new_rotate.makeRotate(angle,axis); 
     340        } 
    325341         
    326342        _rotation = _rotation*new_rotate; 
     
    339355        osg::Matrix rotation_matrix; 
    340356        rotation_matrix.makeRotate(_rotation); 
     357 
     358        if (_thrown && _rate_sensitive && _ga_t0.valid() && _ga_t1.valid()) 
     359        { 
     360            // frame_time / delta_event_time 
     361            double rate = _delta_frame_time / (_ga_t0->getTime() - _ga_t1->getTime()); 
     362            scale *= rate; 
     363        } 
    341364 
    342365        osg::Vec3 dv(dx*scale,dy*scale,0.0f);