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