diff --git a/interface/src/renderer/JointState.cpp b/interface/src/renderer/JointState.cpp index 3b3c135eb5..f7b4dbc96f 100644 --- a/interface/src/renderer/JointState.cpp +++ b/interface/src/renderer/JointState.cpp @@ -23,6 +23,15 @@ JointState::JointState() : _constraint(NULL) { } +JointState::JointState(const JointState& other) : _constraint(NULL) { + _rotationInParentFrame = other._rotationInParentFrame; + _transform = other._transform; + _rotation = other._rotation; + _animationPriority = other._animationPriority; + _fbxJoint = other._fbxJoint; + // DO NOT copy _constraint +} + JointState::~JointState() { delete _constraint; _constraint = NULL; @@ -33,6 +42,22 @@ void JointState::setFBXJoint(const FBXJoint* joint) { _rotationInParentFrame = joint->rotation; // NOTE: JointState does not own the FBXJoint to which it points. _fbxJoint = joint; + if (_constraint) { + delete _constraint; + _constraint = NULL; + } +} + +void JointState::updateConstraint() { + if (_constraint) { + delete _constraint; + _constraint = NULL; + } + if (glm::distance2(glm::vec3(-PI), _fbxJoint->rotationMin) > EPSILON || + glm::distance2(glm::vec3(PI), _fbxJoint->rotationMax) > EPSILON ) { + // this joint has rotation constraints + _constraint = AngularConstraint::newAngularConstraint(_fbxJoint->rotationMin, _fbxJoint->rotationMax); + } } void JointState::copyState(const JointState& state) { @@ -40,7 +65,7 @@ void JointState::copyState(const JointState& state) { _transform = state._transform; _rotation = extractRotation(_transform); _animationPriority = state._animationPriority; - // DO NOT copy _fbxJoint + // DO NOT copy _fbxJoint or _constraint } void JointState::computeTransform(const glm::mat4& parentTransform) { @@ -88,8 +113,7 @@ void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, floa return; } _animationPriority = priority; - if (!constrain || (_fbxJoint->rotationMin == glm::vec3(-PI, -PI, -PI) && - _fbxJoint->rotationMax == glm::vec3(PI, PI, PI))) { + if (!constrain || _constraint == NULL) { // no constraints _rotationInParentFrame = _rotationInParentFrame * glm::inverse(_rotation) * delta * _rotation; _rotation = delta * _rotation; diff --git a/interface/src/renderer/JointState.h b/interface/src/renderer/JointState.h index 4eadc51f7c..e5f02fdf16 100644 --- a/interface/src/renderer/JointState.h +++ b/interface/src/renderer/JointState.h @@ -23,11 +23,13 @@ class AngularConstraint; class JointState { public: JointState(); + JointState(const JointState& other); ~JointState(); void setFBXJoint(const FBXJoint* joint); const FBXJoint& getFBXJoint() const { return *_fbxJoint; } + void updateConstraint(); void copyState(const JointState& state); void computeTransform(const glm::mat4& parentTransform); @@ -64,7 +66,7 @@ private: glm::quat _rotation; // joint- to model-frame const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint - AngularConstraint* _constraint; + AngularConstraint* _constraint; // JointState owns its AngularConstraint }; #endif // hifi_JointState_h diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index 3b5cda4fd2..a86d392981 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -561,8 +561,6 @@ bool Model::updateGeometry() { void Model::setJointStates(QVector states) { _jointStates = states; - // compute an approximate bounding radius for broadphase collision queries - // against PhysicsSimulation boundaries int numJoints = _jointStates.size(); float radius = 0.0f; for (int i = 0; i < numJoints; ++i) { @@ -570,6 +568,7 @@ void Model::setJointStates(QVector states) { if (distance > radius) { radius = distance; } + _jointStates[i].updateConstraint(); } _boundingRadius = radius; }