| [11009] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include <osgAnimation/UpdateMatrixTransform> |
|---|
| 16 | #include <osg/NodeVisitor> |
|---|
| 17 | #include <osg/MatrixTransform> |
|---|
| 18 | |
|---|
| 19 | using namespace osgAnimation; |
|---|
| 20 | |
|---|
| 21 | UpdateMatrixTransform::UpdateMatrixTransform( const UpdateMatrixTransform& apc,const osg::CopyOp& copyop) : osg::Object(apc,copyop), AnimationUpdateCallback<osg::NodeCallback>(apc, copyop) |
|---|
| 22 | { |
|---|
| 23 | _transforms = StackedTransform(apc.getStackedTransforms(), copyop); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | UpdateMatrixTransform::UpdateMatrixTransform(const std::string& name) : AnimationUpdateCallback<osg::NodeCallback>(name) |
|---|
| 27 | { |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | void UpdateMatrixTransform::operator()(osg::Node* node, osg::NodeVisitor* nv) |
|---|
| 32 | { |
|---|
| 33 | if (nv && nv->getVisitorType() == osg::NodeVisitor::UPDATE_VISITOR) |
|---|
| 34 | { |
|---|
| 35 | osg::MatrixTransform* matrixTransform = dynamic_cast<osg::MatrixTransform*>(node); |
|---|
| 36 | if (matrixTransform) |
|---|
| 37 | { |
|---|
| 38 | |
|---|
| 39 | _transforms.update(); |
|---|
| 40 | const osg::Matrix& matrix = _transforms.getMatrix(); |
|---|
| 41 | matrixTransform->setMatrix(matrix); |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | traverse(node,nv); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | bool UpdateMatrixTransform::link(osgAnimation::Channel* channel) |
|---|
| 49 | { |
|---|
| 50 | const std::string& channelName = channel->getName(); |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | for (StackedTransform::iterator it = _transforms.begin(); it != _transforms.end(); ++it) |
|---|
| 54 | { |
|---|
| [11034] | 55 | StackedTransformElement* element = it->get(); |
|---|
| [11009] | 56 | if (element && !element->getName().empty() && channelName == element->getName()) |
|---|
| 57 | { |
|---|
| 58 | Target* target = element->getOrCreateTarget(); |
|---|
| 59 | if (target && channel->setTarget(target)) |
|---|
| 60 | return true; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | osg::notify(osg::INFO) << "UpdateMatrixTransform::link Channel " << channel->getName() << " does not contain a symbolic name that can be linked to a StackedTransformElement." << std::endl; |
|---|
| 65 | |
|---|
| 66 | return false; |
|---|
| 67 | } |
|---|