Added a AnimationPathCallback which can update both a MatrixTransform and a
PositionAttitudeTransform, removed the equivialnt callbacks once found in these transform classes. Changed the NodeCallback class so its derived from osg::Object instead of osg::Referenced to allow it to be saved out in the .osg format. Added support for Update and Cull callbacks into the .osg file format. Added support for AnimationPathCallback into the .osg file format.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Quat>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -131,6 +132,61 @@ class SG_EXPORT AnimationPath : public virtual osg::Object
|
||||
|
||||
};
|
||||
|
||||
|
||||
class SG_EXPORT AnimationPathCallback : public NodeCallback, public NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
AnimationPathCallback():
|
||||
_timeOffset(0.0),
|
||||
_timeMultiplier(1.0),
|
||||
_firstTime(0.0),
|
||||
_animationTime(0.0) {}
|
||||
|
||||
|
||||
AnimationPathCallback(const AnimationPathCallback& apc,const CopyOp& copyop):
|
||||
NodeCallback(apc,copyop),
|
||||
_animationPath(apc._animationPath),
|
||||
_timeOffset(apc._timeOffset),
|
||||
_timeMultiplier(apc._timeMultiplier),
|
||||
_firstTime(apc._firstTime),
|
||||
_animationTime(apc._animationTime) {}
|
||||
|
||||
|
||||
META_Object(osg,AnimationPathCallback)
|
||||
|
||||
AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0f,double timeMultiplier=1.0f):
|
||||
_animationPath(ap),
|
||||
_timeOffset(timeOffset),
|
||||
_timeMultiplier(timeMultiplier),
|
||||
_firstTime(0.0),
|
||||
_animationTime(0.0) {}
|
||||
|
||||
|
||||
|
||||
void setAnimationPath(AnimationPath* path) { _animationPath = path; }
|
||||
|
||||
AnimationPath* getAnimationPath() { return _animationPath.get(); }
|
||||
|
||||
const AnimationPath* getAnimationPath() const { return _animationPath.get(); }
|
||||
|
||||
|
||||
/** implements the callback*/
|
||||
virtual void operator()(Node* node, NodeVisitor* nv);
|
||||
|
||||
virtual void apply(MatrixTransform& mt);
|
||||
|
||||
virtual void apply(PositionAttitudeTransform& pat);
|
||||
|
||||
public:
|
||||
|
||||
ref_ptr<AnimationPath> _animationPath;
|
||||
double _timeOffset;
|
||||
double _timeMultiplier;
|
||||
double _firstTime;
|
||||
mutable double _animationTime;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,8 +28,6 @@ class SG_EXPORT MatrixTransform : public Transform
|
||||
|
||||
META_Node(osg, MatrixTransform);
|
||||
|
||||
virtual void traverse(NodeVisitor& nv);
|
||||
|
||||
/** Set the transform's matrix.*/
|
||||
void setMatrix(const Matrix& mat) { (*_matrix) = mat; _inverseDirty=true; dirtyBound(); }
|
||||
|
||||
@@ -53,68 +51,10 @@ class SG_EXPORT MatrixTransform : public Transform
|
||||
return *_inverse;
|
||||
}
|
||||
|
||||
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
matrix.preMult(*_matrix);
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = *_matrix;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor*) const;
|
||||
|
||||
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const
|
||||
{
|
||||
const Matrix& inverse = getInverseMatrix();
|
||||
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor*) const;
|
||||
|
||||
if (_referenceFrame==RELATIVE_TO_PARENTS)
|
||||
{
|
||||
matrix.postMult(inverse);
|
||||
}
|
||||
else // absolute
|
||||
{
|
||||
matrix = inverse;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Set an optional animation path. */
|
||||
void setAnimationPath(AnimationPath* ap) { _animationPath = ap; }
|
||||
|
||||
/** Get a read only version of the AnimationPath object*/
|
||||
AnimationPath* getAnimationPath() { return _animationPath.get(); }
|
||||
|
||||
/** Get a read only version of the AnimationPath object*/
|
||||
const AnimationPath* getAnimationPath() const { return _animationPath.get(); }
|
||||
|
||||
|
||||
|
||||
/** Callback which can be attached to a MatrixTransform as an app
|
||||
* callback to allow it to follow the path defined by a AnimationPath.
|
||||
* note, now deprecated by attaching an AnimationPath directly to MatrixTransform.*/
|
||||
class SG_EXPORT AnimationPathCallback : public NodeCallback
|
||||
{
|
||||
public:
|
||||
|
||||
AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0f,double timeMultiplier=1.0f):
|
||||
_animationPath(ap),
|
||||
_timeOffset(timeOffset),
|
||||
_timeMultiplier(timeMultiplier),
|
||||
_firstTime(0.0) {}
|
||||
|
||||
/** implements the callback*/
|
||||
virtual void operator()(Node* node, NodeVisitor* nv);
|
||||
|
||||
ref_ptr<AnimationPath> _animationPath;
|
||||
double _timeOffset;
|
||||
double _timeMultiplier;
|
||||
double _firstTime;
|
||||
};
|
||||
|
||||
protected :
|
||||
|
||||
@@ -123,8 +63,6 @@ class SG_EXPORT MatrixTransform : public Transform
|
||||
ref_ptr<Matrix> _matrix;
|
||||
mutable ref_ptr<Matrix> _inverse;
|
||||
mutable bool _inverseDirty;
|
||||
|
||||
osg::ref_ptr<AnimationPath> _animationPath;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#ifndef OSG_NODECALLBACK
|
||||
#define OSG_NODECALLBACK 1
|
||||
|
||||
#include <osg/Referenced>
|
||||
#include <osg/Object>
|
||||
#include <osg/ref_ptr>
|
||||
|
||||
namespace osg {
|
||||
@@ -13,13 +13,18 @@ namespace osg {
|
||||
class Node;
|
||||
class NodeVisitor;
|
||||
|
||||
class SG_EXPORT NodeCallback : public virtual Referenced {
|
||||
class SG_EXPORT NodeCallback : public virtual Object {
|
||||
|
||||
public :
|
||||
|
||||
|
||||
NodeCallback(){}
|
||||
virtual ~NodeCallback() {}
|
||||
|
||||
NodeCallback(const NodeCallback&,const CopyOp&):
|
||||
_nestedCallback(_nestedCallback) {}
|
||||
|
||||
|
||||
META_Object(osg,NodeCallback)
|
||||
|
||||
|
||||
/** Callback method call by the NodeVisitor when visiting a node.*/
|
||||
@@ -71,6 +76,10 @@ class SG_EXPORT NodeCallback : public virtual Referenced {
|
||||
public:
|
||||
|
||||
ref_ptr<NodeCallback> _nestedCallback;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~NodeCallback() {}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -42,7 +42,7 @@ class Sequence;
|
||||
myVisitor.apply(*root). The later method will bypass the double
|
||||
dispatch and the appropriate NodeVisitor::apply(..) method will
|
||||
not be called. */
|
||||
class SG_EXPORT NodeVisitor : public Referenced
|
||||
class SG_EXPORT NodeVisitor : public virtual Referenced
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -51,8 +51,7 @@ class SG_EXPORT NodeVisitor : public Referenced
|
||||
TRAVERSE_NONE,
|
||||
TRAVERSE_PARENTS,
|
||||
TRAVERSE_ALL_CHILDREN,
|
||||
TRAVERSE_ACTIVE_CHILDREN,
|
||||
TRAVERSE_VISITOR
|
||||
TRAVERSE_ACTIVE_CHILDREN
|
||||
};
|
||||
|
||||
enum VisitorType
|
||||
@@ -137,26 +136,18 @@ class SG_EXPORT NodeVisitor : public Referenced
|
||||
NodeVisitor has been attached via setTraverseVisitor()
|
||||
and the new mode is not TRAVERSE_VISITOR then the attached
|
||||
visitor is detached. Default mode is TRAVERSE_NONE.*/
|
||||
void setTraversalMode(TraversalMode mode);
|
||||
inline void setTraversalMode(TraversalMode mode) { _traversalMode = mode; }
|
||||
|
||||
/** Get the traversal mode.*/
|
||||
inline TraversalMode getTraversalMode() const { return _traversalMode; }
|
||||
|
||||
/** Set a visitor to handle traversal.
|
||||
Overrides the traverse mode setting it to TRAVERSAL_VISITOR.*/
|
||||
void setTraversalVisitor(NodeVisitor* nv);
|
||||
|
||||
/** Get the traversal visitor, returns NULL if none is attached.*/
|
||||
inline NodeVisitor* getTraversalVisitor() { return _traversalVisitor.get(); }
|
||||
|
||||
/** Method for handling traversal of a nodes.
|
||||
If you intend to use the visitor for actively traversing
|
||||
the scene graph then make sure the accept() methods call
|
||||
this method unless they handle traversal directly.*/
|
||||
inline void traverse(Node& node)
|
||||
{
|
||||
if (_traversalVisitor.valid()) node.accept(*_traversalVisitor);
|
||||
else if (_traversalMode==TRAVERSE_PARENTS) node.ascend(*this);
|
||||
if (_traversalMode==TRAVERSE_PARENTS) node.ascend(*this);
|
||||
else if (_traversalMode!=TRAVERSE_NONE) node.traverse(*this);
|
||||
}
|
||||
|
||||
@@ -234,8 +225,6 @@ class SG_EXPORT NodeVisitor : public Referenced
|
||||
int _traversalNumber;
|
||||
|
||||
ref_ptr<FrameStamp> _frameStamp;
|
||||
|
||||
ref_ptr<NodeVisitor> _traversalVisitor;
|
||||
|
||||
TraversalMode _traversalMode;
|
||||
Node::NodeMask _traversalMask;
|
||||
|
||||
@@ -30,19 +30,19 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
|
||||
META_Node(osg, PositionAttitudeTransform);
|
||||
|
||||
|
||||
void setPosition(const Vec3& pos) { _position = pos; dirtyBound(); }
|
||||
inline void setPosition(const Vec3& pos) { _position = pos; dirtyBound(); }
|
||||
|
||||
const Vec3& getPosition() const { return _position; }
|
||||
inline const Vec3& getPosition() const { return _position; }
|
||||
|
||||
|
||||
void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); }
|
||||
inline void setAttitude(const Quat& quat) { _attitude = quat; dirtyBound(); }
|
||||
|
||||
const Quat& getAttitude() const { return _attitude; }
|
||||
inline const Quat& getAttitude() const { return _attitude; }
|
||||
|
||||
|
||||
void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; dirtyBound(); }
|
||||
inline void setPivotPoint(const Vec3& pivot) { _pivotPoint = pivot; dirtyBound(); }
|
||||
|
||||
const Vec3& getPivotPoint() const { return _pivotPoint; }
|
||||
inline const Vec3& getPivotPoint() const { return _pivotPoint; }
|
||||
|
||||
|
||||
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
|
||||
@@ -50,28 +50,6 @@ class SG_EXPORT PositionAttitudeTransform : public Transform
|
||||
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
|
||||
|
||||
|
||||
/** Callback which can be attached to a PositionAttitudeTransform
|
||||
* as an app callback to allow it to follow the path defined by a
|
||||
* AnimationPath.*/
|
||||
class SG_EXPORT AnimationPathCallback : public virtual NodeCallback
|
||||
{
|
||||
public:
|
||||
|
||||
AnimationPathCallback(AnimationPath* ap,double timeOffset=0.0f,double timeMultiplier=1.0f):
|
||||
_animationPath(ap),
|
||||
_timeOffset(timeOffset),
|
||||
_timeMultiplier(timeMultiplier),
|
||||
_firstTime(0.0) {}
|
||||
|
||||
/** implements the callback*/
|
||||
virtual void operator()(Node* node, NodeVisitor* nv);
|
||||
|
||||
ref_ptr<AnimationPath> _animationPath;
|
||||
double _timeOffset;
|
||||
double _timeMultiplier;
|
||||
double _firstTime;
|
||||
};
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
|
||||
Reference in New Issue
Block a user