History

move grab position to front of palm

Seth Alves committed 10 years ago

Commit 1e69c121 parent 2501be11 file · +40 −6Browse files

Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 1 file). Show all

Unified · Split

interface/src/avatar/SkeletonModel.cpp+40−6
@@ -236,17 +236,51 @@ void SkeletonModel::applyPalmData(int jointIndex, const PalmData& palm) { · 235 unmodified lines
236236 }
237237
238238 bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const {
239− int index = _rig->indexOfJoint("LeftHandMiddle1");
240− if (index >= 0) {
241− return getJointPositionInWorldFrame(index, position);
239+ int knuckleIndex = _rig->indexOfJoint("LeftHandMiddle1");
240+ int handIndex = _rig->indexOfJoint("LeftHand");
241+ if (knuckleIndex >= 0 && handIndex >= 0) {
242+ glm::quat handRotation;
243+ glm::vec3 knucklePosition;
244+ glm::vec3 handPosition;
245+ if (!getJointPositionInWorldFrame(knuckleIndex, knucklePosition)) {
246+ return false;
247+ }
248+ if (!getJointPositionInWorldFrame(handIndex, handPosition)) {
249+ return false;
250+ }
251+ if (!getJointRotationInWorldFrame(handIndex, handRotation)) {
252+ return false;
253+ }
254+ float halfPalmLength = glm::distance(knucklePosition, handPosition) * 0.5f;
255+ // z azis is standardized to be out of the palm. move from the knuckle-joint away from the palm
256+ // by 1/2 the palm length.
257+ position = knucklePosition + handRotation * (glm::vec3(0.0f, 0.0f, 1.0f) * halfPalmLength);
258+ return true;
242259 }
243260 return false;
244261 }
245262
246263 bool SkeletonModel::getRightGrabPosition(glm::vec3& position) const {
247− int index = _rig->indexOfJoint("RightHandMiddle1");
248− if (index >= 0) {
249− return getJointPositionInWorldFrame(index, position);
264+ int knuckleIndex = _rig->indexOfJoint("RightHandMiddle1");
265+ int handIndex = _rig->indexOfJoint("RightHand");
266+ if (knuckleIndex >= 0 && handIndex >= 0) {
267+ glm::quat handRotation;
268+ glm::vec3 knucklePosition;
269+ glm::vec3 handPosition;
270+ if (!getJointPositionInWorldFrame(knuckleIndex, knucklePosition)) {
271+ return false;
272+ }
273+ if (!getJointPositionInWorldFrame(handIndex, handPosition)) {
274+ return false;
275+ }
276+ if (!getJointRotationInWorldFrame(handIndex, handRotation)) {
277+ return false;
278+ }
279+ float halfPalmLength = glm::distance(knucklePosition, handPosition) * 0.5f;
280+ // z azis is standardized to be out of the palm. move from the knuckle-joint away from the palm
281+ // by 1/2 the palm length.
282+ position = knucklePosition + handRotation * (glm::vec3(0.0f, 0.0f, 1.0f) * halfPalmLength);
283+ return true;
250284 }
251285 return false;
252286 }