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
21 _owningAvatar(owningAvatar) {21 _owningAvatar(owningAvatar) {
22}22}
23 23
24void SkeletonModel::setJointStates(QVector<JointState> states) {
25 Model::setJointStates(states);
26 _ragDoll.init(_jointStates);
27}
28
24const float PALM_PRIORITY = 3.0f;29const float PALM_PRIORITY = 3.0f;
25 30
26void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {31void 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
90void 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
83void SkeletonModel::getHandShapes(int jointIndex, QVector<const Shape*>& shapes) const {103void SkeletonModel::getHandShapes(int jointIndex, QVector<const Shape*>& shapes) const {
@@ -121,6 +141,7 @@ void SkeletonModel::getBodyShapes(QVector<const Shape*>& shapes) const { · 37 unmodified lines
121void SkeletonModel::renderIKConstraints() {141void SkeletonModel::renderIKConstraints() {
122 renderJointConstraints(getRightHandJointIndex());142 renderJointConstraints(getRightHandJointIndex());
123 renderJointConstraints(getLeftHandJointIndex());143 renderJointConstraints(getLeftHandJointIndex());
144 renderRagDoll();
124}145}
125 146
126class IndexValue {147class 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
476void 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