25 #ifndef WGELINEARTRANSLATIONCALLBACK_H
26 #define WGELINEARTRANSLATIONCALLBACK_H
30 #include <osg/MatrixTransform>
33 #include <osg/Uniform>
35 #include "../../common/WProperties.h"
45 template<
typename T >
90 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
125 template<
typename T >
131 m_texMat( texMatrix ),
137 template<
typename T >
143 m_uniform( uniform ),
149 template<
typename T >
160 template<
typename T >
166 template<
typename T >
170 float newPos = m_pos->get();
171 if( newPos != m_oldPos )
174 osg::MatrixTransform* m =
dynamic_cast< osg::MatrixTransform*
>( node );
177 std::shared_ptr< WPropertyConstraintMax< typename T::element_type::DataType > > mx = m_pos->getMax();
178 std::shared_ptr< WPropertyConstraintMin< typename T::element_type::DataType > > mn = m_pos->getMin();
182 float max = mx->getMax();
183 float min = mn->getMin();
184 float size = max - min;
185 float axeLen = m_axe.length();
187 osg::Vec3 translation = m_axe * m_scaler *
static_cast< float >( m_oldPos - min );
192 m_texMat->setMatrix( osg::Matrix::translate( translation / size / axeLen ) );
196 m_uniform->set( osg::Matrix::translate( translation ) );
199 m->setMatrix( osg::Matrix::translate( translation ) );
204 traverse( node, nv );
This class is an OSG Callback which allows simple linear translation of a matrix transform node along...
WGELinearTranslationCallback(osg::Vec3 axe, T property, osg::ref_ptr< osg::TexMat > texMatrix, double scaler=1.0)
Constructor.
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.
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.