From Brede Johansen, added support for incrementing animation of DOFTransform
w.r.t. time rather than frame number.
This commit is contained in:
@@ -29,25 +29,7 @@ class OSGSIM_EXPORT DOFTransform : public osg::Transform
|
|||||||
DOFTransform();
|
DOFTransform();
|
||||||
|
|
||||||
/**copy constructor*/
|
/**copy constructor*/
|
||||||
DOFTransform(const DOFTransform& dof, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
DOFTransform(const DOFTransform& dof, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
|
||||||
osg::Transform(dof, copyop),
|
|
||||||
_minHPR(dof._minHPR),
|
|
||||||
_maxHPR(dof._maxHPR),
|
|
||||||
_currentHPR(dof._currentHPR),
|
|
||||||
_incrementHPR(dof._incrementHPR),
|
|
||||||
_minTranslate(dof._minTranslate),
|
|
||||||
_maxTranslate(dof._maxTranslate),
|
|
||||||
_currentTranslate(dof._currentTranslate),
|
|
||||||
_incrementTranslate(dof._incrementTranslate),
|
|
||||||
_minScale(dof._minScale),
|
|
||||||
_maxScale(dof._maxScale),
|
|
||||||
_currentScale(dof._currentScale),
|
|
||||||
_incrementScale(dof._incrementScale),
|
|
||||||
_Put(dof._Put),
|
|
||||||
_inversePut(dof._inversePut),
|
|
||||||
_limitationFlags(dof._limitationFlags),
|
|
||||||
_animationOn(dof._animationOn),
|
|
||||||
_increasingFlags(dof._increasingFlags) {}
|
|
||||||
|
|
||||||
META_Node(osgSim, DOFTransform);
|
META_Node(osgSim, DOFTransform);
|
||||||
|
|
||||||
@@ -111,7 +93,7 @@ class OSGSIM_EXPORT DOFTransform : public osg::Transform
|
|||||||
inline void setAnimationOn(bool do_animate) {_animationOn = do_animate;}
|
inline void setAnimationOn(bool do_animate) {_animationOn = do_animate;}
|
||||||
inline bool getAnimationOn() const {return _animationOn;}
|
inline bool getAnimationOn() const {return _animationOn;}
|
||||||
|
|
||||||
void animate();
|
void animate(float deltaTime);
|
||||||
|
|
||||||
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
|
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
|
||||||
|
|
||||||
@@ -121,6 +103,9 @@ class OSGSIM_EXPORT DOFTransform : public osg::Transform
|
|||||||
|
|
||||||
virtual ~DOFTransform() {}
|
virtual ~DOFTransform() {}
|
||||||
|
|
||||||
|
int _previousTraversalNumber;
|
||||||
|
double _previousTime;
|
||||||
|
|
||||||
osg::Vec3 _minHPR;
|
osg::Vec3 _minHPR;
|
||||||
osg::Vec3 _maxHPR;
|
osg::Vec3 _maxHPR;
|
||||||
osg::Vec3 _currentHPR;
|
osg::Vec3 _currentHPR;
|
||||||
|
|||||||
@@ -15,7 +15,20 @@
|
|||||||
using namespace osgSim;
|
using namespace osgSim;
|
||||||
using namespace osg;
|
using namespace osg;
|
||||||
|
|
||||||
|
static const unsigned int TRANSLATION_X_LIMIT_BIT = 0x80000000u >> 0;
|
||||||
|
static const unsigned int TRANSLATION_Y_LIMIT_BIT = 0x80000000u >> 1;
|
||||||
|
static const unsigned int TRANSLATION_Z_LIMIT_BIT = 0x80000000u >> 2;
|
||||||
|
static const unsigned int ROTATION_PITCH_LIMIT_BIT = 0x80000000u >> 3;
|
||||||
|
static const unsigned int ROTATION_ROLL_LIMIT_BIT = 0x80000000u >> 4;
|
||||||
|
static const unsigned int ROTATION_YAW_LIMIT_BIT = 0x80000000u >> 5;
|
||||||
|
static const unsigned int SCALE_X_LIMIT_BIT = 0x80000000u >> 6;
|
||||||
|
static const unsigned int SCALE_Y_LIMIT_BIT = 0x80000000u >> 7;
|
||||||
|
static const unsigned int SCALE_Z_LIMIT_BIT = 0x80000000u >> 8;
|
||||||
|
|
||||||
|
|
||||||
DOFTransform::DOFTransform():
|
DOFTransform::DOFTransform():
|
||||||
|
_previousTraversalNumber(-1),
|
||||||
|
_previousTime(0.0),
|
||||||
_limitationFlags(0),
|
_limitationFlags(0),
|
||||||
_animationOn(true),
|
_animationOn(true),
|
||||||
_increasingFlags(0xffff)
|
_increasingFlags(0xffff)
|
||||||
@@ -23,12 +36,49 @@ DOFTransform::DOFTransform():
|
|||||||
setNumChildrenRequiringUpdateTraversal(1);
|
setNumChildrenRequiringUpdateTraversal(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DOFTransform::DOFTransform(const DOFTransform& dof, const osg::CopyOp& copyop):
|
||||||
|
osg::Transform(dof, copyop),
|
||||||
|
_previousTraversalNumber(dof._previousTraversalNumber),
|
||||||
|
_previousTime(dof._previousTime),
|
||||||
|
_minHPR(dof._minHPR),
|
||||||
|
_maxHPR(dof._maxHPR),
|
||||||
|
_currentHPR(dof._currentHPR),
|
||||||
|
_incrementHPR(dof._incrementHPR),
|
||||||
|
_minTranslate(dof._minTranslate),
|
||||||
|
_maxTranslate(dof._maxTranslate),
|
||||||
|
_currentTranslate(dof._currentTranslate),
|
||||||
|
_incrementTranslate(dof._incrementTranslate),
|
||||||
|
_minScale(dof._minScale),
|
||||||
|
_maxScale(dof._maxScale),
|
||||||
|
_currentScale(dof._currentScale),
|
||||||
|
_incrementScale(dof._incrementScale),
|
||||||
|
_Put(dof._Put),
|
||||||
|
_inversePut(dof._inversePut),
|
||||||
|
_limitationFlags(dof._limitationFlags),
|
||||||
|
_animationOn(dof._animationOn),
|
||||||
|
_increasingFlags(dof._increasingFlags)
|
||||||
|
{
|
||||||
|
setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()+1);
|
||||||
|
}
|
||||||
|
|
||||||
void DOFTransform::traverse(osg::NodeVisitor& nv)
|
void DOFTransform::traverse(osg::NodeVisitor& nv)
|
||||||
{
|
{
|
||||||
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
|
||||||
{
|
{
|
||||||
animate();
|
// ensure that we do not operate on this node more than
|
||||||
|
// once during this traversal. This is an issue since node
|
||||||
|
// can be shared between multiple parents.
|
||||||
|
if ((nv.getTraversalNumber()!=_previousTraversalNumber) && nv.getFrameStamp())
|
||||||
|
{
|
||||||
|
double newTime = nv.getFrameStamp()->getReferenceTime();
|
||||||
|
|
||||||
|
animate((float)(newTime-_previousTime));
|
||||||
|
|
||||||
|
_previousTraversalNumber = nv.getTraversalNumber();
|
||||||
|
_previousTime = newTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform::traverse(nv);
|
Transform::traverse(nv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,10 +154,11 @@ bool DOFTransform::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisito
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DOFTransform::updateCurrentHPR(const osg::Vec3& hpr)
|
void DOFTransform::updateCurrentHPR(const osg::Vec3& hpr)
|
||||||
{
|
{
|
||||||
//if there is no constrain on animation
|
//if there is constrain on animation
|
||||||
if(!(_limitationFlags & ((unsigned long)1<<26)))
|
if (_limitationFlags & ROTATION_ROLL_LIMIT_BIT)
|
||||||
{
|
{
|
||||||
//if we have min == max, it is efective constrain, so don't change
|
//if we have min == max, it is efective constrain, so don't change
|
||||||
if(_minHPR[2] != _maxHPR[2])
|
if(_minHPR[2] != _maxHPR[2])
|
||||||
@@ -129,9 +180,12 @@ void DOFTransform::updateCurrentHPR(const osg::Vec3& hpr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentHPR[2] = hpr[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_limitationFlags & ROTATION_PITCH_LIMIT_BIT)
|
||||||
if(!(_limitationFlags & ((unsigned long)1<<27)))
|
|
||||||
{
|
{
|
||||||
if(_minHPR[1] != _maxHPR[1])
|
if(_minHPR[1] != _maxHPR[1])
|
||||||
{
|
{
|
||||||
@@ -150,9 +204,12 @@ void DOFTransform::updateCurrentHPR(const osg::Vec3& hpr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentHPR[1] = hpr[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_limitationFlags & ROTATION_YAW_LIMIT_BIT)
|
||||||
if(!(_limitationFlags & ((unsigned long)1<<28)))
|
|
||||||
{
|
{
|
||||||
if(_minHPR[0] != _maxHPR[0])
|
if(_minHPR[0] != _maxHPR[0])
|
||||||
{
|
{
|
||||||
@@ -172,12 +229,18 @@ void DOFTransform::updateCurrentHPR(const osg::Vec3& hpr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentHPR[0] = hpr[0];
|
||||||
|
}
|
||||||
|
|
||||||
dirtyBound();
|
dirtyBound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DOFTransform::updateCurrentTranslate(const osg::Vec3& translate)
|
void DOFTransform::updateCurrentTranslate(const osg::Vec3& translate)
|
||||||
{
|
{
|
||||||
if(!(_limitationFlags & (unsigned long)1<<29))
|
if (_limitationFlags & TRANSLATION_Z_LIMIT_BIT)
|
||||||
{
|
{
|
||||||
if(_minTranslate[2] != _maxTranslate[2])
|
if(_minTranslate[2] != _maxTranslate[2])
|
||||||
{
|
{
|
||||||
@@ -196,8 +259,12 @@ void DOFTransform::updateCurrentTranslate(const osg::Vec3& translate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentTranslate[2] = translate[2];
|
||||||
|
}
|
||||||
|
|
||||||
if(!(_limitationFlags & (unsigned long)1<<30))
|
if (_limitationFlags & TRANSLATION_Y_LIMIT_BIT)
|
||||||
{
|
{
|
||||||
if(_minTranslate[1] != _maxTranslate[1])
|
if(_minTranslate[1] != _maxTranslate[1])
|
||||||
{
|
{
|
||||||
@@ -216,8 +283,12 @@ void DOFTransform::updateCurrentTranslate(const osg::Vec3& translate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentTranslate[1] = translate[1];
|
||||||
|
}
|
||||||
|
|
||||||
if(!(_limitationFlags & (unsigned long)1<<31))
|
if (_limitationFlags & TRANSLATION_X_LIMIT_BIT)
|
||||||
{
|
{
|
||||||
if(_minTranslate[0] != _maxTranslate[0])
|
if(_minTranslate[0] != _maxTranslate[0])
|
||||||
{
|
{
|
||||||
@@ -236,13 +307,18 @@ void DOFTransform::updateCurrentTranslate(const osg::Vec3& translate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentTranslate[0] = translate[0];
|
||||||
|
}
|
||||||
|
|
||||||
dirtyBound();
|
dirtyBound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DOFTransform::updateCurrentScale(const osg::Vec3& scale)
|
void DOFTransform::updateCurrentScale(const osg::Vec3& scale)
|
||||||
{
|
{
|
||||||
|
if (_limitationFlags & SCALE_Z_LIMIT_BIT)
|
||||||
if(!(_limitationFlags & ((unsigned long)1<<23)))
|
|
||||||
{
|
{
|
||||||
if(_minScale[2] != _maxScale[2])
|
if(_minScale[2] != _maxScale[2])
|
||||||
{
|
{
|
||||||
@@ -261,8 +337,12 @@ void DOFTransform::updateCurrentScale(const osg::Vec3& scale)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentScale[2] = scale[2];
|
||||||
|
}
|
||||||
|
|
||||||
if(!(_limitationFlags & ((unsigned long)1<<24)))
|
if (_limitationFlags & SCALE_Y_LIMIT_BIT)
|
||||||
{
|
{
|
||||||
if(_minScale[1] != _maxScale[1])
|
if(_minScale[1] != _maxScale[1])
|
||||||
{
|
{
|
||||||
@@ -281,8 +361,12 @@ void DOFTransform::updateCurrentScale(const osg::Vec3& scale)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentScale[1] = scale[1];
|
||||||
|
}
|
||||||
|
|
||||||
if(!(_limitationFlags & ((unsigned long)1<<25)))
|
if (_limitationFlags & SCALE_X_LIMIT_BIT)
|
||||||
{
|
{
|
||||||
if(_minScale[0] != _maxScale[0])
|
if(_minScale[0] != _maxScale[0])
|
||||||
{
|
{
|
||||||
@@ -300,11 +384,16 @@ void DOFTransform::updateCurrentScale(const osg::Vec3& scale)
|
|||||||
_increasingFlags &= ~this_flag;
|
_increasingFlags &= ~this_flag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentScale[0] = scale[0];
|
||||||
|
}
|
||||||
|
|
||||||
dirtyBound();
|
dirtyBound();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DOFTransform::animate()
|
void DOFTransform::animate(float deltaTime)
|
||||||
{
|
{
|
||||||
if(!_animationOn) return;
|
if(!_animationOn) return;
|
||||||
//this will increment or decrement all allowed values
|
//this will increment or decrement all allowed values
|
||||||
@@ -312,57 +401,57 @@ void DOFTransform::animate()
|
|||||||
osg::Vec3 new_value = _currentTranslate;
|
osg::Vec3 new_value = _currentTranslate;
|
||||||
|
|
||||||
if(_increasingFlags & 1)
|
if(_increasingFlags & 1)
|
||||||
new_value[0] += _incrementTranslate[0];
|
new_value[0] += _incrementTranslate[0]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[0] -= _incrementTranslate[0];
|
new_value[0] -= _incrementTranslate[0]*deltaTime;
|
||||||
|
|
||||||
if(_increasingFlags & 1<<1)
|
if(_increasingFlags & 1<<1)
|
||||||
new_value[1] += _incrementTranslate[1];
|
new_value[1] += _incrementTranslate[1]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[1] -= _incrementTranslate[1];
|
new_value[1] -= _incrementTranslate[1]*deltaTime;
|
||||||
|
|
||||||
if(_increasingFlags & 1<<2)
|
if(_increasingFlags & 1<<2)
|
||||||
new_value[2] += _incrementTranslate[2];
|
new_value[2] += _incrementTranslate[2]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[2] -= _incrementTranslate[2];
|
new_value[2] -= _incrementTranslate[2]*deltaTime;
|
||||||
|
|
||||||
updateCurrentTranslate(new_value);
|
updateCurrentTranslate(new_value);
|
||||||
|
|
||||||
new_value = _currentHPR;
|
new_value = _currentHPR;
|
||||||
|
|
||||||
if(_increasingFlags & ((unsigned short)1<<3))
|
if(_increasingFlags & ((unsigned short)1<<3))
|
||||||
new_value[1] += _incrementHPR[1];
|
new_value[1] += _incrementHPR[1]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[1] -= _incrementHPR[1];
|
new_value[1] -= _incrementHPR[1]*deltaTime;
|
||||||
|
|
||||||
if(_increasingFlags & ((unsigned short)1<<4))
|
if(_increasingFlags & ((unsigned short)1<<4))
|
||||||
new_value[2] += _incrementHPR[2];
|
new_value[2] += _incrementHPR[2]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[2] -= _incrementHPR[2];
|
new_value[2] -= _incrementHPR[2]*deltaTime;
|
||||||
|
|
||||||
if(_increasingFlags & ((unsigned short)1<<5))
|
if(_increasingFlags & ((unsigned short)1<<5))
|
||||||
new_value[0] += _incrementHPR[0];
|
new_value[0] += _incrementHPR[0]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[0] -= _incrementHPR[0];
|
new_value[0] -= _incrementHPR[0]*deltaTime;
|
||||||
|
|
||||||
updateCurrentHPR(new_value);
|
updateCurrentHPR(new_value);
|
||||||
|
|
||||||
new_value = _currentScale;
|
new_value = _currentScale;
|
||||||
|
|
||||||
if(_increasingFlags & 1<<6)
|
if(_increasingFlags & 1<<6)
|
||||||
new_value[0] += _incrementScale[0];
|
new_value[0] += _incrementScale[0]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[0] -= _incrementScale[0];
|
new_value[0] -= _incrementScale[0]*deltaTime;
|
||||||
|
|
||||||
if(_increasingFlags & 1<<7)
|
if(_increasingFlags & 1<<7)
|
||||||
new_value[1] += _incrementScale[1];
|
new_value[1] += _incrementScale[1]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[1] -= _incrementScale[1];
|
new_value[1] -= _incrementScale[1]*deltaTime;
|
||||||
|
|
||||||
if(_increasingFlags & 1<<8)
|
if(_increasingFlags & 1<<8)
|
||||||
new_value[2] += _incrementScale[2];
|
new_value[2] += _incrementScale[2]*deltaTime;
|
||||||
else
|
else
|
||||||
new_value[2] -= _incrementScale[2];
|
new_value[2] -= _incrementScale[2]*deltaTime;
|
||||||
|
|
||||||
updateCurrentScale(new_value);
|
updateCurrentScale(new_value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user