From 2aaa628a6727096c6f1f9a406bd98504caeaca74 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 24 Jul 2014 08:42:34 -0700 Subject: [PATCH] send visible joint state when colliding as ragdoll --- interface/src/avatar/MyAvatar.cpp | 13 ++++++++++--- interface/src/renderer/JointState.cpp | 8 ++++++++ interface/src/renderer/JointState.h | 3 +++ interface/src/renderer/Model.cpp | 18 ++++++++++++------ interface/src/renderer/Model.h | 4 ++++ 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 556f9dfc68..37558adbc7 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -165,9 +165,16 @@ void MyAvatar::simulate(float deltaTime) { PerformanceTimer perfTimer("joints"); // copy out the skeleton joints from the model _jointData.resize(_skeletonModel.getJointStateCount()); - for (int i = 0; i < _jointData.size(); i++) { - JointData& data = _jointData[i]; - data.valid = _skeletonModel.getJointState(i, data.rotation); + if (Menu::getInstance()->isOptionChecked(MenuOption::CollideAsRagdoll)) { + for (int i = 0; i < _jointData.size(); i++) { + JointData& data = _jointData[i]; + data.valid = _skeletonModel.getVisibleJointState(i, data.rotation); + } + } else { + for (int i = 0; i < _jointData.size(); i++) { + JointData& data = _jointData[i]; + data.valid = _skeletonModel.getJointState(i, data.rotation); + } } } diff --git a/interface/src/renderer/JointState.cpp b/interface/src/renderer/JointState.cpp index 26fa29c4a9..2a4372401e 100644 --- a/interface/src/renderer/JointState.cpp +++ b/interface/src/renderer/JointState.cpp @@ -218,6 +218,14 @@ void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRot _visibleRotation = parentRotation * _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation; } +const bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) const { + glm::quat defaultRotation = _fbxJoint->rotation; + return glm::abs(rotation.x - defaultRotation.x) < tolerance && + glm::abs(rotation.y - defaultRotation.y) < tolerance && + glm::abs(rotation.z - defaultRotation.z) < tolerance && + glm::abs(rotation.w - defaultRotation.w) < tolerance; +} + const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const { assert(_fbxJoint != NULL); return _fbxJoint->translation; diff --git a/interface/src/renderer/JointState.h b/interface/src/renderer/JointState.h index a3b792abc4..94811fe13c 100644 --- a/interface/src/renderer/JointState.h +++ b/interface/src/renderer/JointState.h @@ -82,6 +82,9 @@ public: void setRotationInConstrainedFrame(const glm::quat& targetRotation); void setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation); const glm::quat& getRotationInConstrainedFrame() const { return _rotationInConstrainedFrame; } + const glm::quat& getVisibleRotationInConstrainedFrame() const { return _visibleRotationInConstrainedFrame; } + + const bool rotationIsDefault(const glm::quat& rotation, float tolerance = EPSILON) const; const glm::vec3& getDefaultTranslationInConstrainedFrame() const; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 8fac5d3d03..8c19c11ed3 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -676,12 +676,18 @@ bool Model::getJointState(int index, glm::quat& rotation) const { if (index == -1 || index >= _jointStates.size()) { return false; } - rotation = _jointStates.at(index).getRotationInConstrainedFrame(); - const glm::quat& defaultRotation = _geometry->getFBXGeometry().joints.at(index).rotation; - return glm::abs(rotation.x - defaultRotation.x) >= EPSILON || - glm::abs(rotation.y - defaultRotation.y) >= EPSILON || - glm::abs(rotation.z - defaultRotation.z) >= EPSILON || - glm::abs(rotation.w - defaultRotation.w) >= EPSILON; + const JointState& state = _jointStates.at(index); + rotation = state.getRotationInConstrainedFrame(); + return !state.rotationIsDefault(rotation); +} + +bool Model::getVisibleJointState(int index, glm::quat& rotation) const { + if (index == -1 || index >= _jointStates.size()) { + return false; + } + const JointState& state = _jointStates.at(index); + rotation = state.getVisibleRotationInConstrainedFrame(); + return !state.rotationIsDefault(rotation); } void Model::setJointState(int index, bool valid, const glm::quat& rotation, float priority) { diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index a4eae8fd9a..cbed941791 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -113,6 +113,10 @@ public: /// Fetches the joint state at the specified index. /// \return whether or not the joint state is "valid" (that is, non-default) bool getJointState(int index, glm::quat& rotation) const; + + /// Fetches the visible joint state at the specified index. + /// \return whether or not the joint state is "valid" (that is, non-default) + bool getVisibleJointState(int index, glm::quat& rotation) const; /// Sets the joint state at the specified index. void setJointState(int index, bool valid, const glm::quat& rotation = glm::quat(), float priority = 1.0f);