28 #include "../../common/math/WMath.h"
29 #include "../../common/math/linearAlgebra/WVectorFixed.h"
31 #include "../../common/WTimer.h"
33 #include "WGEAnimationManipulator.h"
36 m_matrix( osg::Matrixd::identity() ),
38 m_homeOffsetTime( timer->elapsed() )
60 return osg::Matrixd::inverse(
m_matrix );
70 switch( ea.getEventType() )
72 case osgGA::GUIEventAdapter::FRAME:
75 case osgGA::GUIEventAdapter::KEYDOWN:
112 double degToRad(
double deg )
114 return deg * ( pi() / 180.0 );
117 double radToDeg(
double rad )
119 return rad * ( 180.0 / pi() );
122 template <
typename T >
136 template <
typename T >
137 T positive( T value )
139 return value > T( 0 ) ? 1 : 0;
152 double smooth(
double value,
double min,
double max )
163 double scaledValue = ( value - min ) / max;
164 return min + max * ( 0.5 * ( 1.0 + cos( pi() + ( scaledValue * pi() ) ) ) );
251 double rtime = positive( time - startTime ) * ( time - startTime );
252 double rangle = smooth( speed * rtime, 0.0, degree );
253 makeRotate( degToRad( rangle ), axes[0], axes[1], axes[2] );
272 Zoomer(
double time,
double startTime,
double factor,
double speed ):
276 double zfactor = std::abs( factor );
279 zfactor = 1.0 / factor;
286 double rtime = time - startTime;
287 double sfactor = 1.0 + smooth( ( speed * rtime ), 0.0, zfactor );
291 makeScale( 1.0 / sfactor, 1.0 / sfactor, 1.0 / sfactor );
295 makeScale( sfactor, sfactor, sfactor );
320 double rtime = time - startTime;
321 double scaler = smooth( speed * rtime, 0.0, 1.0 );
322 makeTranslate( ( direction * scaler ).
operator osg::Vec3d() );
334 osg::Matrixd mBBTranslate = osg::Matrixd::translate( -159.0 / 2.0, -199.0 / 2.0, -159.0 / 2.0 );
335 osg::Matrixd mBBScale = osg::Matrixd::scale( 1.5, 1.5, 1.5 );
336 osg::Matrixd mBBRotate = osg::Matrixd::rotate( -pi() / 2.0, 1.0, 0.0, 0.0 ) *
337 osg::Matrixd::rotate( pi(), 0.0, 1.0, 0.0 );
349 m_matrix = mBBTranslate * mBBScale * mBBRotate * rotateToBack
Provides a time dependent rotation around a specified axis.
Rotator(double time, double startTime, WVector3d axes, double degree, double speed)
Create a rotation matrix which rotates a certain number of degrees with a given speed.
Provides a time-dependent translation.
Translator(double time, double startTime, WVector3d direction, double speed)
Translates the scene using the given direction.
virtual void setByMatrix(const osg::Matrixd &matrix)
Sets the current matrix of this animation manipulator.
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Handles incoming events send by the event dispatcher of the view.
void handleFrame()
This method updates m_matrix per frame according to time elapsed.
virtual osg::Matrixd getMatrix() const
Gets the current animation matrix for the current time-step.
virtual ~WGEAnimationManipulator()
Destructor.
double m_homeOffsetTime
If home() is called, the homeOffsetTime stores the timers current value.
virtual void init(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Initializes this manipulator.
WTimer::ConstSPtr m_timer
This timer keeps track of the current animation-time.
virtual void setTimer(WTimer::ConstSPtr timer)
Allows to switch the timer type.
osg::Matrixd m_matrix
The view matrix.
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
Sets the current inverse matrix of this animation manipulator.
virtual osg::Matrixd getInverseMatrix() const
Gets the current inverse animation matrix for the current time-step.
virtual void home(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Sets the manipulator back to its default.
WGEAnimationManipulator(WTimer::ConstSPtr timer=WTimer::ConstSPtr(new WRealtimeTimer()))
Constructs a animation path manipulator using a realtime timer if not specified.
std::shared_ptr< const WTimer > ConstSPtr
Convenience typedef for a const shared_ptr.
Provides a comfortable zoomer lens.
Zoomer(double time, double startTime, double factor, double speed)
Zooms the scene with the given factor.