move grab position to front of palm

This commit is contained in:
Seth Alves 2016-02-01 18:47:26 -08:00
parent 2501be16cb
commit 1e69c12e87

View file

@ -236,17 +236,51 @@ void SkeletonModel::applyPalmData(int jointIndex, const PalmData& palm) {
}
bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const {
int index = _rig->indexOfJoint("LeftHandMiddle1");
if (index >= 0) {
return getJointPositionInWorldFrame(index, position);
int knuckleIndex = _rig->indexOfJoint("LeftHandMiddle1");
int handIndex = _rig->indexOfJoint("LeftHand");
if (knuckleIndex >= 0 && handIndex >= 0) {
glm::quat handRotation;
glm::vec3 knucklePosition;
glm::vec3 handPosition;
if (!getJointPositionInWorldFrame(knuckleIndex, knucklePosition)) {
return false;
}
if (!getJointPositionInWorldFrame(handIndex, handPosition)) {
return false;
}
if (!getJointRotationInWorldFrame(handIndex, handRotation)) {
return false;
}
float halfPalmLength = glm::distance(knucklePosition, handPosition) * 0.5f;
// z azis is standardized to be out of the palm. move from the knuckle-joint away from the palm
// by 1/2 the palm length.
position = knucklePosition + handRotation * (glm::vec3(0.0f, 0.0f, 1.0f) * halfPalmLength);
return true;
}
return false;
}
bool SkeletonModel::getRightGrabPosition(glm::vec3& position) const {
int index = _rig->indexOfJoint("RightHandMiddle1");
if (index >= 0) {
return getJointPositionInWorldFrame(index, position);
int knuckleIndex = _rig->indexOfJoint("RightHandMiddle1");
int handIndex = _rig->indexOfJoint("RightHand");
if (knuckleIndex >= 0 && handIndex >= 0) {
glm::quat handRotation;
glm::vec3 knucklePosition;
glm::vec3 handPosition;
if (!getJointPositionInWorldFrame(knuckleIndex, knucklePosition)) {
return false;
}
if (!getJointPositionInWorldFrame(handIndex, handPosition)) {
return false;
}
if (!getJointRotationInWorldFrame(handIndex, handRotation)) {
return false;
}
float halfPalmLength = glm::distance(knucklePosition, handPosition) * 0.5f;
// z azis is standardized to be out of the palm. move from the knuckle-joint away from the palm
// by 1/2 the palm length.
position = knucklePosition + handRotation * (glm::vec3(0.0f, 0.0f, 1.0f) * halfPalmLength);
return true;
}
return false;
}