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() ),
61 return osg::Matrixd::inverse(
m_matrix );
71 switch( ea.getEventType() )
73 case osgGA::GUIEventAdapter::FRAME:
76 case osgGA::GUIEventAdapter::KEYDOWN:
113 double degToRad(
double deg )
115 return deg * ( piDouble / 180.0 );
118 double radToDeg(
double rad )
120 return rad * ( 180.0 / piDouble );
123 template <
typename T >
137 template <
typename T >
138 T positive( T value )
140 return value > T( 0 ) ? 1 : 0;
153 double smooth(
double value,
double min,
double max )
164 double scaledValue = ( value - min ) / max;
165 return min + max * ( 0.5 * ( 1.0 + cos( piDouble + ( scaledValue * piDouble ) ) ) );
254 double rtime = positive( time - startTime ) * ( time - startTime );
255 double rangle = smooth( speed * rtime, 0.0, degree );
256 makeRotate( degToRad( rangle ), axes[0], axes[1], axes[2] );
275 Zoomer(
double time,
double startTime,
double factor,
double speed ):
279 double zfactor = abs( factor );
282 zfactor = 1.0 / factor;
289 double rtime = time - startTime;
290 double sfactor = 1.0 + smooth( ( speed * rtime ), 0.0, zfactor );
294 makeScale( 1.0 / sfactor, 1.0 / sfactor, 1.0 / sfactor );
298 makeScale( sfactor, sfactor, sfactor );
323 double rtime = time - startTime;
324 double scaler = smooth( speed * rtime, 0.0, 1.0 );
325 makeTranslate( ( direction * scaler ).
operator osg::Vec3d() );
337 osg::Matrixd mBBTranslate = osg::Matrixd::translate( -159.0 / 2.0, -199.0 / 2.0, -159.0 / 2.0 );
338 osg::Matrixd mBBScale = osg::Matrixd::scale( 1.5, 1.5, 1.5 );
339 osg::Matrixd mBBRotate = osg::Matrixd::rotate( -piDouble / 2.0, 1.0, 0.0, 0.0 ) *
340 osg::Matrixd::rotate( piDouble, 0.0, 1.0, 0.0 );
343 Rotator rotateToBack =
Rotator( elapsed, 0.0, Transformation::axeY, 360.0, 22.5 );
348 Zoomer zoomToNei1 =
Zoomer( elapsed, translateABitUp.finish() - 2.0, 2.0, 0.15 );
349 Zoomer zoomToNaus =
Zoomer( elapsed, zoomToNei1.finish() + 1.0, 0.1, 3.0 );
350 Zoomer zoomToNei2 =
Zoomer( elapsed, zoomToNaus.finish(), 5.0, 1.5 );
352 m_matrix = mBBTranslate * mBBScale * mBBRotate * rotateToBack
virtual osg::Matrixd getMatrix() const
Gets the current animation matrix for the current time-step.
virtual void home(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Sets the manipulator back to its default.
virtual void setByInverseMatrix(const osg::Matrixd &matrix)
Sets the current inverse matrix of this animation manipulator.
Rotator(double time, double startTime, WVector3d axes, double degree, double speed)
Create a rotation matrix which rotates a certain number of degree with a given speed.
void handleFrame()
This method updates m_matrix per frame according to time elapsed.
WTimer::ConstSPtr m_timer
This timer keeps track of the current animation-time.
Translator(double time, double startTime, WVector3d direction, double speed)
Translates the scene using the given direction.
virtual ~WGEAnimationManipulator()
Destructor.
double m_homeOffsetTime
If home() is called, the homeOffsetTime stores the timers current value.
virtual void setTimer(WTimer::ConstSPtr timer)
Allows to switch the timer type.
Zoomer(double time, double startTime, double factor, double speed)
Zooms the scene with the given factor.
WGEAnimationManipulator(WTimer::ConstSPtr timer=WTimer::ConstSPtr(new WRealtimeTimer()))
Constructs a animation path manipulator using a realtime timer if not specified.
Provides a comfortable zoomer lens.
A fixed size matrix class.
virtual void init(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Initializes this manipulator.
osg::Matrixd m_matrix
The view matrix.
Provides a time-dependent translation.
virtual osg::Matrixd getInverseMatrix() const
Gets the current inverse animation matrix for the current time-step.
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Handles incoming events send by the event dispatcher of the view.
Provides a time dependent rotation around a specified axis.
boost::shared_ptr< const WTimer > ConstSPtr
Convenience typedef for a const shared_ptr.
virtual void setByMatrix(const osg::Matrixd &matrix)
Sets the current matrix of this animation manipulator.