Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 5 files). Show all
Unified · Split
| @@ -17,7 +17,9 @@ · 16 unmodified lines | ||
| 17 | 17 | #include "Menu.h" |
| 18 | 18 | #include "SkeletonModel.h" |
| 19 | 19 | |
| 20 | −SkeletonModel::SkeletonModel(Avatar* owningAvatar) : | |
| 20 | +SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) : | |
| 21 | + Model(parent), | |
| 22 | + Ragdoll(), | |
| 21 | 23 | _owningAvatar(owningAvatar) { |
| 22 | 24 | } |
| 23 | 25 | |
| @@ -36,10 +38,8 @@ void SkeletonModel::setJointStates(QVector<JointState> states) { · 12 unmodified lines | ||
| 36 | 38 | parentIndices.push_back(state.getFBXJoint().parentIndex); |
| 37 | 39 | points.push_back(state.getPosition()); |
| 38 | 40 | } |
| 39 | − // ... and feed the results to _ragDoll | |
| 40 | − // It is OK that_jointShapes is probably empty at this stage: _ragDoll keeps a | |
| 41 | − // pointer to it and things will start working as soon as the list is populated. | |
| 42 | − _ragDoll.init(&_jointShapes, parentIndices, points); | |
| 41 | + // ... and feed the results to Ragdoll | |
| 42 | + initShapesAndPoints(&_jointShapes, parentIndices, points); | |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| @@ -105,14 +105,13 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 59 unmodified lines | ||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | void SkeletonModel::simulateRagdoll(float deltaTime) { |
| 108 | − // move ragdoll points toward joints | |
| 109 | − QVector<glm::vec3>& points = _ragDoll.getPoints(); | |
| 108 | + // move ragdoll _points toward joints | |
| 110 | 109 | const int numStates = _jointStates.size(); |
| 111 | − assert(numStates == points.size()); | |
| 110 | + assert(numStates == _points.size()); | |
| 112 | 111 | float fraction = 0.1f; // fraction = 0.1f left intentionally low for demo purposes |
| 113 | 112 | float oneMinusFraction = 1.0f - fraction; |
| 114 | 113 | for (int i = 0; i < numStates; ++i) { |
| 115 | − points[i] = oneMinusFraction * points[i] + fraction * _jointStates[i].getPosition(); | |
| 114 | + _points[i] = oneMinusFraction * _points[i] + fraction * _jointStates[i].getPosition(); | |
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | // enforce the constraints |
| @@ -121,7 +120,7 @@ void SkeletonModel::simulateRagdoll(float deltaTime) { · 2 unmodified lines | ||
| 121 | 120 | int iterations = 0; |
| 122 | 121 | float delta = 0.0f; |
| 123 | 122 | do { |
| 124 | − delta = _ragDoll.enforceConstraints(); | |
| 123 | + delta = enforceConstraints(); | |
| 125 | 124 | ++iterations; |
| 126 | 125 | } while (delta > MIN_CONSTRAINT_ERROR && iterations < MAX_ITERATIONS); |
| 127 | 126 | } |
| @@ -273,7 +272,7 @@ void SkeletonModel::updateJointState(int index) { · 145 unmodified lines | ||
| 273 | 272 | void SkeletonModel::updateShapePositions() { |
| 274 | 273 | if (isActive() && _owningAvatar->isMyAvatar() && |
| 275 | 274 | Menu::getInstance()->isOptionChecked(MenuOption::CollideAsRagdoll)) { |
| 276 | − _ragDoll.updateShapes(_rotation, _translation); | |
| 275 | + updateShapes(_rotation, _translation); | |
| 277 | 276 | } else { |
| 278 | 277 | Model::updateShapePositions(); |
| 279 | 278 | } |
| @@ -505,15 +504,14 @@ void SkeletonModel::renderRagdoll() { · 225 unmodified lines | ||
| 505 | 504 | glPushMatrix(); |
| 506 | 505 | |
| 507 | 506 | Application::getInstance()->loadTranslatedViewMatrix(_translation); |
| 508 | − QVector<glm::vec3> points = _ragDoll.getPoints(); | |
| 509 | − int numPoints = points.size(); | |
| 507 | + int numPoints = _points.size(); | |
| 510 | 508 | float alpha = 0.3f; |
| 511 | 509 | float radius1 = 0.008f; |
| 512 | 510 | float radius2 = 0.01f; |
| 513 | 511 | for (int i = 0; i < numPoints; ++i) { |
| 514 | 512 | glPushMatrix(); |
| 515 | 513 | // draw each point as a yellow hexagon with black border |
| 516 | − glm::vec3 position = _rotation * points[i]; | |
| 514 | + glm::vec3 position = _rotation * _points[i]; | |
| 517 | 515 | glTranslatef(position.x, position.y, position.z); |
| 518 | 516 | glColor4f(0.0f, 0.0f, 0.0f, alpha); |
| 519 | 517 | glutSolidSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); |