From Cedric Pinson, Fix Skeleton to compute correctly bind matrix, fix compile issue on osganimationhardware after fixing Skeleton

This commit is contained in:
Cedric Pinson 2009-11-13 13:39:21 +00:00
parent cd2d69506b
commit 5842677662
2 changed files with 37 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/* -*-c++-*- /* -*-c++-*-
* Copyright (C) 2008 Cedric Pinson <mornifle@plopbyte.net> * Copyright (C) 2008 Cedric Pinson <cedric.pinson@plopbyte.net>
* *
* This library is open source and may be redistributed and/or modified under * This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
@ -12,12 +12,11 @@
* OpenSceneGraph Public License for more details. * OpenSceneGraph Public License for more details.
*/ */
#ifndef OSGANIMATION_SKELETON_H #ifndef OSGANIMATION_SKELETON
#define OSGANIMATION_SKELETON_H #define OSGANIMATION_SKELETON 1
#include <osg/MatrixTransform>
#include <osgAnimation/Bone>
#include <osgAnimation/Export> #include <osgAnimation/Export>
#include <osgAnimation/Bone>
namespace osgAnimation namespace osgAnimation
{ {
@ -31,18 +30,19 @@ namespace osgAnimation
{ {
public: public:
META_Object(osgAnimation, UpdateSkeleton); META_Object(osgAnimation, UpdateSkeleton);
UpdateSkeleton() : _needValidate(true) {} UpdateSkeleton();
UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop) { _needValidate = true;} UpdateSkeleton(const UpdateSkeleton&, const osg::CopyOp&);
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
bool needToValidate() const;
protected: protected:
bool _needValidate; bool _needValidate;
}; };
Skeleton(const Skeleton& b, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : Bone(b,copyop) {}
Skeleton(); Skeleton();
void setDefaultUpdateCallback(void); Skeleton(const Skeleton&, const osg::CopyOp&);
void computeBindMatrix() { _invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace); _needToRecomputeBindMatrix = false; }
void setDefaultUpdateCallback();
void computeBindMatrix();
}; };
} }

View File

@ -17,6 +17,20 @@
using namespace osgAnimation; using namespace osgAnimation;
Skeleton::Skeleton() {}
Skeleton::Skeleton(const Skeleton& b, const osg::CopyOp& copyop) : Bone(b,copyop) {}
Skeleton::UpdateSkeleton::UpdateSkeleton() : _needValidate(true) {}
Skeleton::UpdateSkeleton::UpdateSkeleton(const UpdateSkeleton& us, const osg::CopyOp& copyop= osg::CopyOp::SHALLOW_COPY) : osg::Object(us, copyop), osg::NodeCallback(us, copyop)
{
_needValidate = true;
}
bool Skeleton::UpdateSkeleton::needToValidate() const
{
return _needValidate;
}
class ValidateSkeletonVisitor : public osg::NodeVisitor class ValidateSkeletonVisitor : public osg::NodeVisitor
{ {
public: public:
@ -56,25 +70,28 @@ public:
void Skeleton::UpdateSkeleton::operator()(osg::Node* node, osg::NodeVisitor* nv) void Skeleton::UpdateSkeleton::operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
if (_needValidate && nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) if (nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR)
{ {
Skeleton* b = dynamic_cast<Skeleton*>(node); Skeleton* skeleton = dynamic_cast<Skeleton*>(node);
if (b) if (_needValidate && skeleton)
{ {
ValidateSkeletonVisitor visitor; ValidateSkeletonVisitor visitor;
node->accept(visitor); node->accept(visitor);
_needValidate = false;
} }
if (skeleton->needToComputeBindMatrix())
_needValidate = false; skeleton->computeBindMatrix();
} }
traverse(node,nv); traverse(node,nv);
} }
Skeleton::Skeleton()
{
}
void Skeleton::setDefaultUpdateCallback() void Skeleton::setDefaultUpdateCallback()
{ {
setUpdateCallback(new Skeleton::UpdateSkeleton ); setUpdateCallback(new Skeleton::UpdateSkeleton );
} }
void Skeleton::computeBindMatrix()
{
_invBindInSkeletonSpace = osg::Matrix::inverse(_bindInBoneSpace);
_needToRecomputeBindMatrix = false;
}