More work on copy constructors

c++11
scrawl 10 years ago
parent f8422c3ed4
commit 00ab474188

@ -111,6 +111,8 @@ namespace NifOsg
class NodeTargetValue : public ControllerValue class NodeTargetValue : public ControllerValue
{ {
protected: protected:
// TODO: get rid of target pointers, which are incompatible with a copy constructor we will need later
// instead, controllers can be a Node added as child of their target
osg::Node *mNode; osg::Node *mNode;
public: public:

@ -168,11 +168,12 @@ namespace
class InvertBoneMatrix : public osg::NodeCallback class InvertBoneMatrix : public osg::NodeCallback
{ {
public: public:
InvertBoneMatrix(osg::Node* skelRootNode) InvertBoneMatrix() {}
: mSkelRoot(skelRootNode)
{ InvertBoneMatrix(const InvertBoneMatrix& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY)
} : osg::Object(copy, copyop), osg::NodeCallback(copy, copyop) {}
// TODO: add copy constructor
META_Object(NifOsg, InvertBoneMatrix)
void operator()(osg::Node* node, osg::NodeVisitor* nv) void operator()(osg::Node* node, osg::NodeVisitor* nv)
{ {
@ -183,21 +184,20 @@ namespace
osg::MatrixTransform* trans = dynamic_cast<osg::MatrixTransform*>(node); osg::MatrixTransform* trans = dynamic_cast<osg::MatrixTransform*>(node);
osg::NodePath::iterator found = std::find(path.begin(), path.end(), mSkelRoot); for (osg::NodePath::iterator it = path.begin(); it != path.end(); ++it)
if (found != path.end())
{ {
path.erase(path.begin(),found+1); if (dynamic_cast<osgAnimation::Skeleton*>(*it))
{
osg::Matrix worldMat = osg::computeLocalToWorld( path ); path.erase(path.begin(), it+1);
trans->setMatrix(osg::Matrix::inverse(worldMat)); // the bone's transform in skeleton space
osg::Matrix boneMat = osg::computeLocalToWorld( path );
trans->setMatrix(osg::Matrix::inverse(boneMat));
break;
}
} }
} }
traverse(node,nv); traverse(node,nv);
} }
private:
// TODO: keeping this pointer will break when copying the scene graph; maybe retrieve it while visiting if it's NULL?
osg::Node* mSkelRoot;
}; };
osg::ref_ptr<osg::Geometry> handleMorphGeometry(const Nif::NiGeomMorpherController* morpher) osg::ref_ptr<osg::Geometry> handleMorphGeometry(const Nif::NiGeomMorpherController* morpher)
@ -793,7 +793,7 @@ namespace NifOsg
rig->setInfluenceMap(map); rig->setInfluenceMap(map);
osg::ref_ptr<osg::MatrixTransform> trans(new osg::MatrixTransform); osg::ref_ptr<osg::MatrixTransform> trans(new osg::MatrixTransform);
trans->setUpdateCallback(new InvertBoneMatrix(mSkeleton)); trans->setUpdateCallback(new InvertBoneMatrix());
osg::ref_ptr<osg::Geode> geode (new osg::Geode); osg::ref_ptr<osg::Geode> geode (new osg::Geode);
geode->addDrawable(rig); geode->addDrawable(rig);

Loading…
Cancel
Save