From 72c74984540a6f6bc593be7136871e9d6de06d28 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 23 Jul 2014 16:56:40 -0700 Subject: [PATCH] add JointState::getDistanceToParent() --- interface/src/renderer/JointState.cpp | 4 ++++ interface/src/renderer/JointState.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/interface/src/renderer/JointState.cpp b/interface/src/renderer/JointState.cpp index 865036df8e..26fa29c4a9 100644 --- a/interface/src/renderer/JointState.cpp +++ b/interface/src/renderer/JointState.cpp @@ -20,6 +20,7 @@ JointState::JointState() : _animationPriority(0.0f), _positionInParentFrame(0.0f), + _distanceToParent(0.0f), _fbxJoint(NULL), _constraint(NULL) { } @@ -29,6 +30,7 @@ JointState::JointState(const JointState& other) : _constraint(NULL) { _rotation = other._rotation; _rotationInConstrainedFrame = other._rotationInConstrainedFrame; _positionInParentFrame = other._positionInParentFrame; + _distanceToParent = other._distanceToParent; _animationPriority = other._animationPriority; _fbxJoint = other._fbxJoint; // DO NOT copy _constraint @@ -72,6 +74,7 @@ void JointState::copyState(const JointState& state) { _rotation = extractRotation(_transform); _rotationInConstrainedFrame = state._rotationInConstrainedFrame; _positionInParentFrame = state._positionInParentFrame; + _distanceToParent = state._distanceToParent; _visibleTransform = state._visibleTransform; _visibleRotation = extractRotation(_visibleTransform); @@ -82,6 +85,7 @@ void JointState::copyState(const JointState& state) { void JointState::initTransform(const glm::mat4& parentTransform) { computeTransform(parentTransform); _positionInParentFrame = glm::inverse(extractRotation(parentTransform)) * (extractTranslation(_transform) - extractTranslation(parentTransform)); + _distanceToParent = glm::length(_positionInParentFrame); } void JointState::computeTransform(const glm::mat4& parentTransform) { diff --git a/interface/src/renderer/JointState.h b/interface/src/renderer/JointState.h index 86ee5d01b7..a3b792abc4 100644 --- a/interface/src/renderer/JointState.h +++ b/interface/src/renderer/JointState.h @@ -51,6 +51,7 @@ public: glm::quat getRotationInParentFrame() const; glm::quat getVisibleRotationInParentFrame() const; const glm::vec3& getPositionInParentFrame() const { return _positionInParentFrame; } + float getDistanceToParent() const { return _distanceToParent; } int getParentIndex() const { return _fbxJoint->parentIndex; } @@ -104,6 +105,7 @@ private: glm::quat _rotation; // joint- to model-frame glm::quat _rotationInConstrainedFrame; // rotation in frame where angular constraints would be applied glm::vec3 _positionInParentFrame; // only changes when the Model is scaled + float _distanceToParent; glm::mat4 _visibleTransform; glm::quat _visibleRotation;