Added left hand/hand rotation setters in preparation for Leap integration.

This commit is contained in:
Andrzej Kapolka 2013-10-28 14:38:09 -07:00
parent b56d47929b
commit 4f34d89c4a
4 changed files with 42 additions and 0 deletions

View file

@ -696,6 +696,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QString jointRootName = processID(joints.value("jointRoot", "jointRoot").toString());
QString jointLeanName = processID(joints.value("jointLean", "jointLean").toString());
QString jointHeadName = processID(joints.value("jointHead", "jointHead").toString());
QString jointLeftHandName = processID(joints.value("jointLeftHand", "jointLeftHand").toString());
QString jointRightHandName = processID(joints.value("jointRightHand", "jointRightHand").toString());
QString jointEyeLeftID;
QString jointEyeRightID;
@ -703,6 +704,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
QString jointRootID;
QString jointLeanID;
QString jointHeadID;
QString jointLeftHandID;
QString jointRightHandID;
QVariantHash blendshapeMappings = mapping.value("bs").toHash();
@ -778,6 +780,9 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
} else if (name == jointHeadName) {
jointHeadID = getID(object.properties);
} else if (name == jointLeftHandName) {
jointLeftHandID = getID(object.properties);
} else if (name == jointRightHandName) {
jointRightHandID = getID(object.properties);
}
@ -1028,6 +1033,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
geometry.rootJointIndex = modelIDs.indexOf(jointRootID);
geometry.leanJointIndex = modelIDs.indexOf(jointLeanID);
geometry.headJointIndex = modelIDs.indexOf(jointHeadID);
geometry.leftHandJointIndex = modelIDs.indexOf(jointLeftHandID);
geometry.rightHandJointIndex = modelIDs.indexOf(jointRightHandID);
// extract the translation component of the neck transform

View file

@ -130,6 +130,7 @@ public:
int rootJointIndex;
int leanJointIndex;
int headJointIndex;
int leftHandJointIndex;
int rightHandJointIndex;
glm::vec3 neckPivot;

View file

@ -413,10 +413,22 @@ bool Model::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePos
getJointPosition(geometry.rightEyeJointIndex, secondEyePosition);
}
bool Model::setLeftHandPosition(const glm::vec3& position) {
return isActive() && setJointPosition(_geometry->getFBXGeometry().leftHandJointIndex, position);
}
bool Model::setLeftHandRotation(const glm::quat& rotation) {
return isActive() && setJointRotation(_geometry->getFBXGeometry().leftHandJointIndex, rotation);
}
bool Model::setRightHandPosition(const glm::vec3& position) {
return isActive() && setJointPosition(_geometry->getFBXGeometry().rightHandJointIndex, position);
}
bool Model::setRightHandRotation(const glm::quat& rotation) {
return isActive() && setJointRotation(_geometry->getFBXGeometry().rightHandJointIndex, rotation);
}
void Model::setURL(const QUrl& url) {
// don't recreate the geometry if it's the same URL
if (_url == url) {
@ -535,6 +547,16 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position) {
return true;
}
bool Model::setJointRotation(int jointIndex, const glm::quat& rotation) {
if (jointIndex == -1 || _jointStates.isEmpty()) {
return false;
}
JointState& state = _jointStates[jointIndex];
state.rotation = state.rotation * glm::inverse(state.combinedRotation) * rotation *
glm::inverse(_geometry->getFBXGeometry().joints.at(jointIndex).inverseBindRotation);
return true;
}
void Model::deleteGeometry() {
foreach (Model* attachment, _attachments) {
delete attachment;

View file

@ -70,10 +70,22 @@ public:
/// \return whether or not both eye meshes were found
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
/// Sets the position of the left hand using inverse kinematics.
/// \return whether or not the left hand joint was found
bool setLeftHandPosition(const glm::vec3& position);
/// Sets the rotation of the left hand.
/// \return whether or not the left hand joint was found
bool setLeftHandRotation(const glm::quat& rotation);
/// Sets the position of the right hand using inverse kinematics.
/// \return whether or not the right hand joint was found
bool setRightHandPosition(const glm::vec3& position);
/// Sets the rotation of the right hand.
/// \return whether or not the right hand joint was found
bool setRightHandRotation(const glm::quat& rotation);
/// Returns the average color of all meshes in the geometry.
glm::vec4 computeAverageColor() const;
@ -106,6 +118,7 @@ protected:
bool getJointRotation(int jointIndex, glm::quat& rotation) const;
bool setJointPosition(int jointIndex, const glm::vec3& position);
bool setJointRotation(int jointIndex, const glm::quat& rotation);
private: