Add copy ctor for JointState

create AngularConstraint for joints that need them (but not used yet)
This commit is contained in:
Andrew Meadows 2014-07-02 11:22:07 -07:00
parent c3f7d9d155
commit b018c1c4a5
3 changed files with 31 additions and 6 deletions

View file

@ -23,6 +23,15 @@ JointState::JointState() :
_constraint(NULL) { _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() { JointState::~JointState() {
delete _constraint; delete _constraint;
_constraint = NULL; _constraint = NULL;
@ -33,6 +42,22 @@ void JointState::setFBXJoint(const FBXJoint* joint) {
_rotationInParentFrame = joint->rotation; _rotationInParentFrame = joint->rotation;
// NOTE: JointState does not own the FBXJoint to which it points. // NOTE: JointState does not own the FBXJoint to which it points.
_fbxJoint = joint; _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) { void JointState::copyState(const JointState& state) {
@ -40,7 +65,7 @@ void JointState::copyState(const JointState& state) {
_transform = state._transform; _transform = state._transform;
_rotation = extractRotation(_transform); _rotation = extractRotation(_transform);
_animationPriority = state._animationPriority; _animationPriority = state._animationPriority;
// DO NOT copy _fbxJoint // DO NOT copy _fbxJoint or _constraint
} }
void JointState::computeTransform(const glm::mat4& parentTransform) { void JointState::computeTransform(const glm::mat4& parentTransform) {
@ -88,8 +113,7 @@ void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, floa
return; return;
} }
_animationPriority = priority; _animationPriority = priority;
if (!constrain || (_fbxJoint->rotationMin == glm::vec3(-PI, -PI, -PI) && if (!constrain || _constraint == NULL) {
_fbxJoint->rotationMax == glm::vec3(PI, PI, PI))) {
// no constraints // no constraints
_rotationInParentFrame = _rotationInParentFrame * glm::inverse(_rotation) * delta * _rotation; _rotationInParentFrame = _rotationInParentFrame * glm::inverse(_rotation) * delta * _rotation;
_rotation = delta * _rotation; _rotation = delta * _rotation;

View file

@ -23,11 +23,13 @@ class AngularConstraint;
class JointState { class JointState {
public: public:
JointState(); JointState();
JointState(const JointState& other);
~JointState(); ~JointState();
void setFBXJoint(const FBXJoint* joint); void setFBXJoint(const FBXJoint* joint);
const FBXJoint& getFBXJoint() const { return *_fbxJoint; } const FBXJoint& getFBXJoint() const { return *_fbxJoint; }
void updateConstraint();
void copyState(const JointState& state); void copyState(const JointState& state);
void computeTransform(const glm::mat4& parentTransform); void computeTransform(const glm::mat4& parentTransform);
@ -64,7 +66,7 @@ private:
glm::quat _rotation; // joint- to model-frame glm::quat _rotation; // joint- to model-frame
const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint
AngularConstraint* _constraint; AngularConstraint* _constraint; // JointState owns its AngularConstraint
}; };
#endif // hifi_JointState_h #endif // hifi_JointState_h

View file

@ -561,8 +561,6 @@ bool Model::updateGeometry() {
void Model::setJointStates(QVector<JointState> states) { void Model::setJointStates(QVector<JointState> states) {
_jointStates = states; _jointStates = states;
// compute an approximate bounding radius for broadphase collision queries
// against PhysicsSimulation boundaries
int numJoints = _jointStates.size(); int numJoints = _jointStates.size();
float radius = 0.0f; float radius = 0.0f;
for (int i = 0; i < numJoints; ++i) { for (int i = 0; i < numJoints; ++i) {
@ -570,6 +568,7 @@ void Model::setJointStates(QVector<JointState> states) {
if (distance > radius) { if (distance > radius) {
radius = distance; radius = distance;
} }
_jointStates[i].updateConstraint();
} }
_boundingRadius = radius; _boundingRadius = radius;
} }