| 59 | | class OSGANIMATION_EXPORT UpdateBone : public AnimationUpdateCallback <osg::NodeCallback> |
| 60 | | { |
| 61 | | protected: |
| 62 | | osg::ref_ptr<osgAnimation::Vec3Target> _position; |
| 63 | | osg::ref_ptr<osgAnimation::QuatTarget> _quaternion; |
| 64 | | osg::ref_ptr<osgAnimation::Vec3Target> _scale; |
| 65 | | |
| 66 | | public: |
| 67 | | META_Object(osgAnimation, UpdateBone); |
| 68 | | UpdateBone(const UpdateBone& apc,const osg::CopyOp& copyop); |
| 69 | | |
| 70 | | UpdateBone(const std::string& name = "") : AnimationUpdateCallback <osg::NodeCallback>(name) |
| 71 | | { |
| 72 | | setName(name); |
| 73 | | _quaternion = new osgAnimation::QuatTarget; |
| 74 | | _position = new osgAnimation::Vec3Target; |
| 75 | | _scale = new osgAnimation::Vec3Target; |
| 76 | | } |
| 77 | | |
| 78 | | void update(osgAnimation::Bone& bone) |
| 79 | | { |
| 80 | | bone.setTranslation(_position->getValue()); |
| 81 | | bone.setRotation(_quaternion->getValue()); |
| 82 | | bone.setScale(_scale->getValue()); |
| 83 | | bone.dirtyBound(); |
| 84 | | } |
| 85 | | |
| 86 | | osgAnimation::QuatTarget* getQuaternion() {return _quaternion.get();} |
| 87 | | osgAnimation::Vec3Target* getPosition() {return _position.get();} |
| 88 | | osgAnimation::Vec3Target* getScale() {return _scale.get();} |
| 89 | | |
| 90 | | bool needLink() const |
| 91 | | { |
| 92 | | // the idea is to return true if nothing is linked |
| 93 | | return !((_position->getCount() + _quaternion->getCount() + _scale->getCount()) > 3); |
| 94 | | } |
| 95 | | |
| 96 | | /** Link channel*/ |
| 97 | | bool link(osgAnimation::Channel* channel); |
| 98 | | |
| 99 | | /** Callback method called by the NodeVisitor when visiting a node.*/ |
| 100 | | virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); |
| 101 | | }; |
| 102 | | |
| 103 | | virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; |
| 104 | | virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; |
| 105 | | |
| 109 | | void setTranslation(const osg::Vec3& trans) { _position = trans;} |
| 110 | | void setRotation(const osg::Quat& quat) { _rotation = quat;} |
| 111 | | void setScale(const osg::Vec3& scale) { _scale = scale;} |
| 112 | | |
| 113 | | const osg::Vec3& getTranslation() const { return _position;} |
| 114 | | const osg::Quat& getRotation() const { return _rotation;} |
| 115 | | const osg::Vec3& getScale() const { return _scale;} |
| 116 | | |
| 117 | | osg::Matrix getMatrixInBoneSpace() const { return (osg::Matrix(getRotation())) * osg::Matrix::translate(getTranslation()) * _bindInBoneSpace;} |
| 118 | | const osg::Matrix& getBindMatrixInBoneSpace() const { return _bindInBoneSpace; } |
| | 44 | const osg::Matrix& getMatrixInBoneSpace() const { return getMatrix();} |
| 122 | | void setBindMatrixInBoneSpace(const osg::Matrix& matrix) |
| 123 | | { |
| 124 | | _bindInBoneSpace = matrix; |
| 125 | | _needToRecomputeBindMatrix = true; |
| 126 | | } |
| 127 | | |
| 128 | | inline bool needToComputeBindMatrix() { return _needToRecomputeBindMatrix;} |
| 129 | | virtual void computeBindMatrix(); |
| 130 | | |
| 131 | | void setNeedToComputeBindMatrix(bool state) { _needToRecomputeBindMatrix = state; } |
| 132 | | |
| 133 | | /** Add Node to Group. |
| 134 | | * If node is not NULL and is not contained in Group then increment its |
| 135 | | * reference count, add it to the child list and dirty the bounding |
| 136 | | * sphere to force it to recompute on next getBound() and return true for success. |
| 137 | | * Otherwise return false. Scene nodes can't be added as child nodes. |
| 138 | | */ |
| 139 | | virtual bool addChild( Node *child ); |
| 140 | | BoneMap getBoneMap(); |
| 141 | | |
| | 48 | void setInvBindMatrixInSkeletonSpace(const osg::Matrix& matrix) { _invBindInSkeletonSpace = matrix; } |
| 162 | | |
| 163 | | inline bool Bone::computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const |
| 164 | | { |
| 165 | | if (_referenceFrame==RELATIVE_RF) |
| 166 | | matrix.preMult(getMatrixInBoneSpace()); |
| 167 | | else |
| 168 | | matrix = getMatrixInBoneSpace(); |
| 169 | | return true; |
| 170 | | } |
| 171 | | |
| 172 | | |
| 173 | | inline bool Bone::computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const |
| 174 | | { |
| 175 | | if (_referenceFrame==RELATIVE_RF) |
| 176 | | matrix.postMult(osg::Matrix::inverse(getMatrixInBoneSpace())); |
| 177 | | else |
| 178 | | matrix = osg::Matrix::inverse(getMatrixInBoneSpace()); |
| 179 | | return true; |
| 180 | | } |
| 181 | | |
| | 59 | typedef std::map<std::string, osg::ref_ptr<Bone> > BoneMap; |