From 7ac90850d3b8adc613fb07acaad7b6aaee0844d4 Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Thu, 24 Jun 2021 09:41:16 +0200 Subject: [PATCH] Fix axis object in translate animation This will allow an object to be moved using a line (with 2d points). Use the factor to switch direction (direction will depend on the order of definition of the end points of the vertex and) together with a (usually normalised property to define how much of the translation to apply). translate mm_radios-display /sim/model/f-14/radio-position-norm -1 mm_radios-display-alt-position-axis --- simgear/scene/model/animation.cxx | 14 +++++++++----- simgear/scene/model/animation.hxx | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/simgear/scene/model/animation.cxx b/simgear/scene/model/animation.cxx index a9ecaece..76f691ad 100644 --- a/simgear/scene/model/animation.cxx +++ b/simgear/scene/model/animation.cxx @@ -714,7 +714,7 @@ protected: * This function will take action when axis has an object-name tag and the corresponding object * can be found within the hierarchy. */ -bool SGAnimation::setCenterAndAxisFromObject(osg::Node *rootNode, SGVec3d& center, SGVec3d &axis, simgear::SGTransientModelData &modelData) const +bool SGAnimation::setCenterAndAxisFromObject(osg::Node *rootNode, SGVec3d& center, SGVec3d &axis, SGVec3d &offset, simgear::SGTransientModelData &modelData) const { std::string axis_object_name = std::string(); bool can_warn = true; @@ -792,6 +792,7 @@ bool SGAnimation::setCenterAndAxisFromObject(osg::Node *rootNode, SGVec3d& cente } if (axisSegment) { + offset = axisSegment->getStart() - axisSegment->getEnd(); center = 0.5*(axisSegment->getStart() + axisSegment->getEnd()); axis = axisSegment->getEnd() - axisSegment->getStart(); return true; @@ -805,7 +806,8 @@ void SGAnimation::readRotationCenterAndAxis(osg::Node *_rootNode, SGVec3d& cente SGVec3d& axis, simgear::SGTransientModelData &modelData) const { center = SGVec3d::zeros(); - if (setCenterAndAxisFromObject(_rootNode, center, axis, modelData)) + SGVec3d offsets; + if (setCenterAndAxisFromObject(_rootNode, center, axis, offsets, modelData)) { if (8 * SGLimitsd::min() < norm(axis)) axis = normalize(axis); @@ -969,9 +971,11 @@ SGTranslateAnimation::SGTranslateAnimation(simgear::SGTransientModelData &modelD else _initialValue = 0; - SGVec3d _center; - if (modelData.getNode() && !setCenterAndAxisFromObject(modelData.getNode(), _center, _axis, modelData)) - _axis = readTranslateAxis(modelData.getConfigNode()); + SGVec3d _center, _offsets; + if (modelData.getNode() && !setCenterAndAxisFromObject(modelData.getNode(), _center, _axis, _offsets, modelData)) + _axis = readTranslateAxis(modelData.getConfigNode()); + else + _axis = _offsets; } osg::Group* diff --git a/simgear/scene/model/animation.hxx b/simgear/scene/model/animation.hxx index 5826b9ba..017a7247 100644 --- a/simgear/scene/model/animation.hxx +++ b/simgear/scene/model/animation.hxx @@ -82,7 +82,7 @@ protected: const SGVec3d& def = SGVec3d::zeros() ) const; void readRotationCenterAndAxis(osg::Node *rootNode, SGVec3d& center, SGVec3d& axis, simgear::SGTransientModelData &modelData) const; - bool setCenterAndAxisFromObject(osg::Node *rootNode, SGVec3d& center, SGVec3d &axis, simgear::SGTransientModelData &modelData) const; + bool setCenterAndAxisFromObject(osg::Node *rootNode, SGVec3d& center, SGVec3d &axis, SGVec3d& offset, simgear::SGTransientModelData &modelData) const; SGExpressiond* readOffsetValue(const char* tag_name) const;