History

Ragdoll not an Entity. SkeletonModel is a Ragdoll

Andrew Meadows committed 12 years ago

Commit 158c7de1 parent 5bd37ac5 files · +20 −32Browse files

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

Unified · Split

interface/src/avatar/SkeletonModel.cpp+12−14
@@ -17,7 +17,9 @@ · 16 unmodified lines
1717 #include "Menu.h"
1818 #include "SkeletonModel.h"
1919
20−SkeletonModel::SkeletonModel(Avatar* owningAvatar) :
20+SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) :
21+ Model(parent),
22+ Ragdoll(),
2123 _owningAvatar(owningAvatar) {
2224 }
2325
@@ -36,10 +38,8 @@ void SkeletonModel::setJointStates(QVector<JointState> states) { · 12 unmodified lines
3638 parentIndices.push_back(state.getFBXJoint().parentIndex);
3739 points.push_back(state.getPosition());
3840 }
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);
4343 }
4444 }
4545
@@ -105,14 +105,13 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 59 unmodified lines
105105 }
106106
107107 void SkeletonModel::simulateRagdoll(float deltaTime) {
108− // move ragdoll points toward joints
109− QVector<glm::vec3>& points = _ragDoll.getPoints();
108+ // move ragdoll _points toward joints
110109 const int numStates = _jointStates.size();
111− assert(numStates == points.size());
110+ assert(numStates == _points.size());
112111 float fraction = 0.1f; // fraction = 0.1f left intentionally low for demo purposes
113112 float oneMinusFraction = 1.0f - fraction;
114113 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();
116115 }
117116
118117 // enforce the constraints
@@ -121,7 +120,7 @@ void SkeletonModel::simulateRagdoll(float deltaTime) { · 2 unmodified lines
121120 int iterations = 0;
122121 float delta = 0.0f;
123122 do {
124− delta = _ragDoll.enforceConstraints();
123+ delta = enforceConstraints();
125124 ++iterations;
126125 } while (delta > MIN_CONSTRAINT_ERROR && iterations < MAX_ITERATIONS);
127126 }
@@ -273,7 +272,7 @@ void SkeletonModel::updateJointState(int index) { · 145 unmodified lines
273272 void SkeletonModel::updateShapePositions() {
274273 if (isActive() && _owningAvatar->isMyAvatar() &&
275274 Menu::getInstance()->isOptionChecked(MenuOption::CollideAsRagdoll)) {
276− _ragDoll.updateShapes(_rotation, _translation);
275+ updateShapes(_rotation, _translation);
277276 } else {
278277 Model::updateShapePositions();
279278 }
@@ -505,15 +504,14 @@ void SkeletonModel::renderRagdoll() { · 225 unmodified lines
505504 glPushMatrix();
506505
507506 Application::getInstance()->loadTranslatedViewMatrix(_translation);
508− QVector<glm::vec3> points = _ragDoll.getPoints();
509− int numPoints = points.size();
507+ int numPoints = _points.size();
510508 float alpha = 0.3f;
511509 float radius1 = 0.008f;
512510 float radius2 = 0.01f;
513511 for (int i = 0; i < numPoints; ++i) {
514512 glPushMatrix();
515513 // draw each point as a yellow hexagon with black border
516− glm::vec3 position = _rotation * points[i];
514+ glm::vec3 position = _rotation * _points[i];
517515 glTranslatef(position.x, position.y, position.z);
518516 glColor4f(0.0f, 0.0f, 0.0f, alpha);
519517 glutSolidSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t