History

adding RagDoll scaffold

Andrew Meadows committed 12 years ago

Commit 1b2cd2e1 parent 78073888 files · +441 −134Browse files

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

Unified · Split

interface/src/avatar/SkeletonModel.cpp+48−0
@@ -21,6 +21,11 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar) : · 20 unmodified lines
2121 _owningAvatar(owningAvatar) {
2222 }
2323
24+void SkeletonModel::setJointStates(QVector<JointState> states) {
25+ Model::setJointStates(states);
26+ _ragDoll.init(_jointStates);
27+}
28+
2429 const float PALM_PRIORITY = 3.0f;
2530
2631 void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
@@ -78,6 +83,21 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { · 51 unmodified lines
7883 applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]);
7984 applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]);
8085 }
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);
81101 }
82102
83103 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
121141 void SkeletonModel::renderIKConstraints() {
122142 renderJointConstraints(getRightHandJointIndex());
123143 renderJointConstraints(getLeftHandJointIndex());
144+ renderRagDoll();
124145 }
125146
126147 class IndexValue {
@@ -452,3 +473,30 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco · 325 unmodified lines
452473 return false;
453474 }
454475
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+}

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