Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 1 file). Show all
Unified · Split
| @@ -236,17 +236,51 @@ void SkeletonModel::applyPalmData(int jointIndex, const PalmData& palm) { · 235 unmodified lines | |||
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const { | 238 | bool SkeletonModel::getLeftGrabPosition(glm::vec3& position) const { |
| 239 | int index = _rig->indexOfJoint("LeftHandMiddle1"); | 239 | int knuckleIndex = _rig->indexOfJoint("LeftHandMiddle1"); |
| 240 | if (index >= 0) { | 240 | int handIndex = _rig->indexOfJoint("LeftHand"); |
| 241 | return getJointPositionInWorldFrame(index, position); | 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; | ||
| 242 | } | 259 | } |
| 243 | return false; | 260 | return false; |
| 244 | } | 261 | } |
| 245 | 262 | ||
| 246 | bool SkeletonModel::getRightGrabPosition(glm::vec3& position) const { | 263 | bool SkeletonModel::getRightGrabPosition(glm::vec3& position) const { |
| 247 | int index = _rig->indexOfJoint("RightHandMiddle1"); | 264 | int knuckleIndex = _rig->indexOfJoint("RightHandMiddle1"); |
| 248 | if (index >= 0) { | 265 | int handIndex = _rig->indexOfJoint("RightHand"); |
| 249 | return getJointPositionInWorldFrame(index, position); | 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; | ||
| 250 | } | 284 | } |
| 251 | return false; | 285 | return false; |
| 252 | } | 286 | } |