Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 8 files). Show all
Unified · Split
| @@ -21,6 +21,11 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar) : · 20 unmodified lines | |||
| 21 | _owningAvatar(owningAvatar) { | 21 | _owningAvatar(owningAvatar) { |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | void SkeletonModel::setJointStates(QVector<JointState> states) { | ||
| 25 | Model::setJointStates(states); | ||
| 26 | _ragDoll.init(_jointStates); | ||
| 27 | } | ||
| 28 | |||
| 24 | const float PALM_PRIORITY = 3.0f; | 29 | const float PALM_PRIORITY = 3.0f; |
| 25 | 30 | ||
| 26 | void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { | 31 | void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { |
| @@ -78,6 +83,21 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 51 unmodified lines | |||
| 78 | applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]); | 83 | applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]); |
| 79 | applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]); | 84 | applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]); |
| 80 | } | 85 | } |
| 86 | |||
| 87 | simulateRagDoll(deltaTime); | ||
| 88 | } | ||
| 89 | |||
| 90 | void SkeletonModel::simulateRagDoll(float deltaTime) { | ||
| 91 | _ragDoll.slaveToSkeleton(_jointStates, 0.5f); | ||
| 92 | |||
| 93 | float MIN_CONSTRAINT_ERROR = 0.005f; // 5mm | ||
| 94 | int MAX_ITERATIONS = 4; | ||
| 95 | int iterations = 0; | ||
| 96 | float delta = 0.0f; | ||
| 97 | do { | ||
| 98 | delta = _ragDoll.enforceConstraints(); | ||
| 99 | ++iterations; | ||
| 100 | } while (delta > MIN_CONSTRAINT_ERROR && iterations < MAX_ITERATIONS); | ||
| 81 | } | 101 | } |
| 82 | 102 | ||
| 83 | void SkeletonModel::getHandShapes(int jointIndex, QVector<const Shape*>& shapes) const { | 103 | void SkeletonModel::getHandShapes(int jointIndex, QVector<const Shape*>& shapes) const { |
| @@ -121,6 +141,7 @@ void SkeletonModel::getBodyShapes(QVector<const Shape*>& shapes) const { · 37 unmodified lines | |||
| 121 | void SkeletonModel::renderIKConstraints() { | 141 | void SkeletonModel::renderIKConstraints() { |
| 122 | renderJointConstraints(getRightHandJointIndex()); | 142 | renderJointConstraints(getRightHandJointIndex()); |
| 123 | renderJointConstraints(getLeftHandJointIndex()); | 143 | renderJointConstraints(getLeftHandJointIndex()); |
| 144 | renderRagDoll(); | ||
| 124 | } | 145 | } |
| 125 | 146 | ||
| 126 | class IndexValue { | 147 | class IndexValue { |
| @@ -452,3 +473,30 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco · 325 unmodified lines | |||
| 452 | return false; | 473 | return false; |
| 453 | } | 474 | } |
| 454 | 475 | ||
| 476 | void SkeletonModel::renderRagDoll() { | ||
| 477 | const int BALL_SUBDIVISIONS = 6; | ||
| 478 | glDisable(GL_DEPTH_TEST); | ||
| 479 | glDisable(GL_LIGHTING); | ||
| 480 | glPushMatrix(); | ||
| 481 | |||
| 482 | Application::getInstance()->loadTranslatedViewMatrix(_translation); | ||
| 483 | QVector<glm::vec3> points = _ragDoll.getPoints(); | ||
| 484 | int numPoints = points.size(); | ||
| 485 | float alpha = 0.3f; | ||
| 486 | float radius1 = 0.008f; | ||
| 487 | float radius2 = 0.01f; | ||
| 488 | for (int i = 0; i < numPoints; ++i) { | ||
| 489 | glPushMatrix(); | ||
| 490 | // draw each point as a yellow hexagon with black border | ||
| 491 | glm::vec3 position = _rotation * points[i]; | ||
| 492 | glTranslatef(position.x, position.y, position.z); | ||
| 493 | glColor4f(0.0f, 0.0f, 0.0f, alpha); | ||
| 494 | glutSolidSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); | ||
| 495 | glColor4f(1.0f, 1.0f, 0.0f, alpha); | ||
| 496 | glutSolidSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); | ||
| 497 | glPopMatrix(); | ||
| 498 | } | ||
| 499 | glPopMatrix(); | ||
| 500 | glEnable(GL_DEPTH_TEST); | ||
| 501 | glEnable(GL_LIGHTING); | ||
| 502 | } | ||