25 #ifndef WGELINEARTRANSLATIONCALLBACK_H
26 #define WGELINEARTRANSLATIONCALLBACK_H
30 #include <osg/Uniform>
31 #include <osg/MatrixTransform>
33 #include "../../common/WProperties.h"
43 template<
typename T >
88 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
123 template<
typename T >
129 m_texMat( texMatrix ),
135 template<
typename T >
141 m_uniform( uniform ),
147 template<
typename T >
158 template<
typename T >
164 template<
typename T >
168 float newPos = m_pos->get();
169 if( newPos != m_oldPos )
172 osg::MatrixTransform* m =
static_cast< osg::MatrixTransform*
>( node );
175 float max = m_pos->getMax()->getMax();
176 float min = m_pos->getMin()->getMin();
177 float size = max - min;
178 float axeLen = m_axe.length();
180 osg::Vec3 translation = m_axe * m_scaler *
static_cast< float >( m_oldPos - min );
185 m_texMat->setMatrix( osg::Matrix::translate( translation / size / axeLen ) );
189 m_uniform->set( osg::Matrix::translate( translation ) );
192 m->setMatrix( osg::Matrix::translate( translation ) );
196 traverse( node, nv );
199 #endif // WGELINEARTRANSLATIONCALLBACK_H
WGELinearTranslationCallback(osg::Vec3 axe, T property, osg::ref_ptr< osg::TexMat > texMatrix, double scaler=1.0)
Constructor.
osg::ref_ptr< osg::Uniform > m_uniform
The uniform to set the matrix to.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
This operator gets called by OSG every update cycle.
osg::Vec3 m_axe
The axis to transform along.
virtual ~WGELinearTranslationCallback()
Destructor.
double m_scaler
Scale the property prior to creating the matrix.
double m_oldPos
Cache the old position for proper update.
osg::ref_ptr< osg::TexMat > m_texMat
Texture matrix that contains normalized translation.
This class is an OSG Callback which allows simple linear translation of a matrix transform node along...