2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
5 This file is part of Lugaru.
7 Lugaru is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Lugaru is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
21 #include "Animation/Skeleton.hpp"
23 #include "Animation/Animation.hpp"
24 #include "Audio/openal_wrapper.hpp"
26 #include "Utils/Folders.hpp"
27 #include "Tutorial.hpp"
29 extern float multiplier;
31 extern Terrain terrain;
32 extern int environment;
33 extern float camerashake;
37 extern int whichjointstartarray[26];
38 extern int whichjointendarray[26];
40 Skeleton::Skeleton() :
55 memset(forwardjoints, 0, sizeof(forwardjoints));
56 memset(lowforwardjoints, 0, sizeof(lowforwardjoints));
57 memset(jointlabels, 0, sizeof(jointlabels));
58 memset(skinText, 0, sizeof(skinText));
62 * sets forward, lowforward, specialforward[]
66 * Person/Person::DoAnimations
67 * Person/Person::DrawSkeleton
69 void Skeleton::FindForwards()
71 //Find forward vectors
72 CrossProduct(joints[forwardjoints[1]].position - joints[forwardjoints[0]].position, joints[forwardjoints[2]].position - joints[forwardjoints[0]].position, &forward);
75 CrossProduct(joints[lowforwardjoints[1]].position - joints[lowforwardjoints[0]].position, joints[lowforwardjoints[2]].position - joints[lowforwardjoints[0]].position, &lowforward);
76 Normalise(&lowforward);
79 specialforward[0] = forward;
81 specialforward[1] = jointPos(rightshoulder) + jointPos(rightwrist);
82 specialforward[1] = jointPos(rightelbow) - specialforward[1] / 2;
83 specialforward[1] += forward * .4;
84 Normalise(&specialforward[1]);
85 specialforward[2] = jointPos(leftshoulder) + jointPos(leftwrist);
86 specialforward[2] = jointPos(leftelbow) - specialforward[2] / 2;
87 specialforward[2] += forward * .4;
88 Normalise(&specialforward[2]);
90 specialforward[3] = jointPos(righthip) + jointPos(rightankle);
91 specialforward[3] = specialforward[3] / 2 - jointPos(rightknee);
92 specialforward[3] += lowforward * .4;
93 Normalise(&specialforward[3]);
94 specialforward[4] = jointPos(lefthip) + jointPos(leftankle);
95 specialforward[4] = specialforward[4] / 2 - jointPos(leftknee);
96 specialforward[4] += lowforward * .4;
97 Normalise(&specialforward[4]);
104 * Person/Person::RagDoll
105 * Person/Person::DoStuff
108 float Skeleton::DoConstraints(XYZ *coords, float *scale)
110 const float elasticity = .3;
112 const int numrepeats = 3;
113 float groundlevel = .15;
123 float damage = 0; // eventually returned from function
124 bool breaking = false;
127 freetime += multiplier;
129 whichpatchx = coords->x / (terrain.size / subdivision * terrain.scale);
130 whichpatchz = coords->z / (terrain.size / subdivision * terrain.scale);
132 terrainlight = *coords;
133 Object::SphereCheckPossible(&terrainlight, 1);
136 for (i = 0; i < joints.size(); i++) {
137 joints[i].position = joints[i].position + joints[i].velocity * multiplier;
139 switch (joints[i].label) {
156 joints[i].position.y -= groundlevel;
157 joints[i].oldvelocity = joints[i].velocity;
160 float tempmult = multiplier;
161 //multiplier/=numrepeats;
163 for (int j = 0; j < numrepeats; j++) {
165 // right leg constraints?
166 if (!joint(rightknee).locked && !joint(righthip).locked) {
167 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
168 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(righthip), &jointPos(rightankle), &jointPos(rightknee), &r)) {
169 jointPos(rightknee) -= lowforward * .05;
171 jointVel(rightknee) -= lowforward * .05 / multiplier / 4;
173 jointVel(rightknee) -= lowforward * .05;
174 jointPos(rightankle) += lowforward * .025;
176 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
178 jointVel(rightankle) += lowforward * .25;
179 jointPos(righthip) += lowforward * .025;
181 jointVel(righthip) += lowforward * .025 / multiplier / 4;
183 jointVel(righthip) += lowforward * .025;
184 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
188 // left leg constraints?
189 if (!joint(leftknee).locked && !joint(lefthip).locked) {
190 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
191 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
192 jointPos(leftknee) -= lowforward * .05;
194 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
196 jointVel(leftknee) -= lowforward * .05;
197 jointPos(leftankle) += lowforward * .025;
199 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
201 jointVel(leftankle) += lowforward * .25;
202 jointPos(lefthip) += lowforward * .025;
204 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
206 jointVel(lefthip) += lowforward * .025;
207 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
211 for (i = 0; i < joints.size(); i++) {
212 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320)
213 joints[i].locked = 0;
214 if (spinny && findLengthfast(&joints[i].velocity) > 600)
215 joints[i].locked = 0;
216 if (joints[i].delay > 0) {
218 for (unsigned j = 0; j < joints.size(); j++) {
219 if (joints[j].locked)
223 joints[i].delay -= multiplier * 3;
227 for (i = 0; i < muscles.size(); i++) {
229 muscles[i].DoConstraint(spinny);
233 for (i = 0; i < joints.size(); i++) {
237 if (joints[i].position.y * (*scale) + coords->y < terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel) {
240 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
241 joints[i].locked = 1;
243 if (!Tutorial::active || id == 0) {
244 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
249 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
250 joints[i].locked = 1;
252 if (!Tutorial::active || id == 0) {
253 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
257 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
258 ReflectVector(&joints[i].velocity, &terrainnormal);
259 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
260 if (!joints[i].locked)
261 damage += findLengthfast(&bounceness) / 4000;
262 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness))
264 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
265 joints[i].velocity -= bounceness;
266 if (1 - friction * frictionness > 0)
267 joints[i].velocity *= 1 - friction * frictionness;
269 joints[i].velocity = 0;
271 if (!Tutorial::active || id == 0)
272 if (findLengthfast(&bounceness) > 8000 && breaking) {
273 // FIXME: this crashes because k is not initialized!
274 // to reproduce, type 'wolfie' in console and play a while
275 // I'll just comment it out for now
276 //Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
277 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
281 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
283 addEnvSound(*coords, 64);
286 if (findLengthfast(&bounceness) > 2500) {
287 Normalise(&bounceness);
288 bounceness = bounceness * 50;
291 joints[i].velocity += bounceness * elasticity;
293 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
295 joints[i].velocity = joints[i].oldvelocity;
299 if (joints[i].locked == 0)
300 if (findLengthfast(&joints[i].velocity) < 1)
301 joints[i].locked = 1;
303 if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
304 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
305 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7);
307 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
308 } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
309 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
310 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7);
313 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
314 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
315 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x * 90 / 255, terrainlight.y * 70 / 255, terrainlight.z * 8 / 255, .5, .5);
316 } else if (findLengthfast(&bounceness) > 500)
317 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
320 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
324 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
325 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
326 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
327 if (k < Object::objects.size()) {
328 if (Object::objects[k]->possible) {
329 friction = Object::objects[k]->friction;
330 XYZ start = joints[i].realoldposition;
331 XYZ end = joints[i].position * (*scale) + *coords;
332 whichhit = Object::objects[k]->model.LineCheckPossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
333 if (whichhit != -1) {
334 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
335 joints[i].locked = 1;
337 if (!Tutorial::active || id == 0) {
338 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
343 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
344 joints[i].locked = 1;
346 if (!Tutorial::active || id == 0) {
347 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
351 terrainnormal = DoRotation(Object::objects[k]->model.facenormals[whichhit], 0, Object::objects[k]->yaw, 0) * -1;
352 if (terrainnormal.y > .8)
354 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
355 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
357 joints[i].velocity = joints[i].oldvelocity;
359 if (!Tutorial::active || id == 0)
360 if (findLengthfast(&bounceness) > 4000 && breaking) {
361 Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
362 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
366 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
368 addEnvSound(*coords, 64);
370 if (Object::objects[k]->type == treetrunktype) {
371 Object::objects[k]->rotx += joints[i].velocity.x * multiplier * .4;
372 Object::objects[k]->roty += joints[i].velocity.z * multiplier * .4;
373 Object::objects[k + 1]->rotx += joints[i].velocity.x * multiplier * .4;
374 Object::objects[k + 1]->roty += joints[i].velocity.z * multiplier * .4;
376 if (!joints[i].locked)
377 damage += findLengthfast(&bounceness) / 2500;
378 ReflectVector(&joints[i].velocity, &terrainnormal);
379 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
380 joints[i].velocity -= bounceness;
381 if (1 - friction * frictionness > 0)
382 joints[i].velocity *= 1 - friction * frictionness;
384 joints[i].velocity = 0;
385 if (findLengthfast(&bounceness) > 2500) {
386 Normalise(&bounceness);
387 bounceness = bounceness * 50;
389 joints[i].velocity += bounceness * elasticity;
392 if (!joints[i].locked)
393 if (findLengthfast(&joints[i].velocity) < 1) {
394 joints[i].locked = 1;
396 if (findLengthfast(&bounceness) > 500)
397 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
398 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
405 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
408 multiplier = tempmult;
411 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
412 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
413 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
414 if (Object::objects[k]->possible) {
415 for (i = 0; i < 26; i++) {
416 //Make this less stupid
417 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
418 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
419 whichhit = Object::objects[k]->model.LineCheckSlidePossible(&start, &end, &Object::objects[k]->position, &Object::objects[k]->yaw);
420 if (whichhit != -1) {
421 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
422 for (unsigned j = 0; j < muscles.size(); j++) {
423 if ((muscles[j].parent1->label == whichjointstartarray[i] && muscles[j].parent2->label == whichjointendarray[i]) || (muscles[j].parent2->label == whichjointstartarray[i] && muscles[j].parent1->label == whichjointendarray[i]))
424 muscles[j].DoConstraint(spinny);
431 for (i = 0; i < joints.size(); i++) {
432 switch (joints[i].label) {
448 joints[i].position.y += groundlevel;
450 if (joints[i].label == lefthip || joints[i].label == leftknee || joints[i].label == leftankle || joints[i].label == righthip || joints[i].label == rightknee || joints[i].label == rightankle)
452 if (joints[i].locked) {
461 for (i = 0; i < muscles.size(); i++) {
462 if (muscles[i].type == boneconnect)
463 muscles[i].DoConstraint(0);
471 * applies gravity to the skeleton
474 * Person/Person::DoStuff
476 void Skeleton::DoGravity(float *scale)
478 for (unsigned i = 0; i < joints.size(); i++) {
481 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
482 (lowforward.y > -.1) ||
485 ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
489 joints[i].velocity.y += gravity * multiplier / (*scale);
495 * set muscles[which].rotate1
499 * special case if animation == hanganim
501 void Skeleton::FindRotationMuscle(int which, int animation)
506 p1 = muscles[which].parent1->position;
507 p2 = muscles[which].parent2->position;
508 dist = findDistance(&p1, &p2);
509 if (p1.y - p2.y <= dist)
510 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
511 if (p1.y - p2.y > dist)
512 muscles[which].rotate2 = asin(1.f);
513 muscles[which].rotate2 *= 360.0 / 6.2831853;
517 dist = findDistance(&p1, &p2);
518 if (p1.z - p2.z <= dist)
519 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
520 if (p1.z - p2.z > dist)
521 muscles[which].rotate1 = acos(1.f);
522 muscles[which].rotate1 *= 360.0 / 6.2831853;
524 muscles[which].rotate1 = 360 - muscles[which].rotate1;
525 if (!isnormal(muscles[which].rotate1))
526 muscles[which].rotate1 = 0;
527 if (!isnormal(muscles[which].rotate2))
528 muscles[which].rotate2 = 0;
530 const int label1 = muscles[which].parent1->label;
531 const int label2 = muscles[which].parent2->label;
534 fwd = specialforward[0];
540 fwd = specialforward[1];
546 fwd = specialforward[2];
552 fwd = specialforward[3];
558 fwd = specialforward[4];
561 if (muscles[which].parent1->lower)
568 if (animation == hanganim) {
569 if (label1 == righthand || label2 == righthand) {
573 if (label1 == lefthand || label2 == lefthand) {
580 if (label1 == rightfoot || label2 == rightfoot) {
583 if (label1 == leftfoot || label2 == leftfoot) {
588 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
589 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
591 fwd /= findLength(&fwd);
592 if (fwd.z <= 1 && fwd.z >= -1)
593 muscles[which].rotate3 = acos(0 - fwd.z);
595 muscles[which].rotate3 = acos(-1.f);
596 muscles[which].rotate3 *= 360.0 / 6.2831853;
598 muscles[which].rotate3 = 360 - muscles[which].rotate3;
599 if (!isnormal(muscles[which].rotate3))
600 muscles[which].rotate3 = 0;
605 * takes filenames for three skeleton files and various models
607 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
608 const std::string& modelfilename, const std::string& model2filename,
609 const std::string& model3filename, const std::string& model4filename,
610 const std::string& model5filename, const std::string& model6filename,
611 const std::string& model7filename, const std::string& modellowfilename,
612 const std::string& modelclothesfilename, bool clothes)
617 int j, num_joints, num_muscles;
623 // load various models
624 // rotate, scale, do normals, do texcoords for each as needed
626 model[0].loadnotex(modelfilename);
627 model[1].loadnotex(model2filename);
628 model[2].loadnotex(model3filename);
629 model[3].loadnotex(model4filename);
630 model[4].loadnotex(model5filename);
631 model[5].loadnotex(model6filename);
632 model[6].loadnotex(model7filename);
634 for (int i = 0; i < num_models; i++) {
635 model[i].Rotate(180, 0, 0);
636 model[i].Scale(.04, .04, .04);
637 model[i].CalculateNormals(0);
640 drawmodel.load(modelfilename);
641 drawmodel.Rotate(180, 0, 0);
642 drawmodel.Scale(.04, .04, .04);
643 drawmodel.FlipTexCoords();
644 if ((Tutorial::active) && (id != 0)) {
645 drawmodel.UniformTexCoords();
646 drawmodel.ScaleTexCoords(0.1);
648 drawmodel.CalculateNormals(0);
650 modellow.loadnotex(modellowfilename);
651 modellow.Rotate(180, 0, 0);
652 modellow.Scale(.04, .04, .04);
653 modellow.CalculateNormals(0);
655 drawmodellow.load(modellowfilename);
656 drawmodellow.Rotate(180, 0, 0);
657 drawmodellow.Scale(.04, .04, .04);
658 drawmodellow.FlipTexCoords();
659 if (Tutorial::active && id != 0)
660 drawmodellow.UniformTexCoords();
661 if (Tutorial::active && id != 0)
662 drawmodellow.ScaleTexCoords(0.1);
663 drawmodellow.CalculateNormals(0);
666 modelclothes.loadnotex(modelclothesfilename);
667 modelclothes.Rotate(180, 0, 0);
668 modelclothes.Scale(.041, .04, .041);
669 modelclothes.CalculateNormals(0);
671 drawmodelclothes.load(modelclothesfilename);
672 drawmodelclothes.Rotate(180, 0, 0);
673 drawmodelclothes.Scale(.04, .04, .04);
674 drawmodelclothes.FlipTexCoords();
675 drawmodelclothes.CalculateNormals(0);
678 // FIXME: three similar blocks follow, one for each of:
679 // filename, lowfilename, clothesfilename
683 tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
686 funpackf(tfile, "Bi", &num_joints);
688 joints.resize(num_joints);
690 // read info for each joint
691 for (int i = 0; i < num_joints; i++) {
692 joints[i].load(tfile, joints);
696 funpackf(tfile, "Bi", &num_muscles);
699 muscles.resize(num_muscles);
701 // for each muscle...
702 for (int i = 0; i < num_muscles; i++) {
703 muscles[i].load(tfile, model[0].vertexNum, joints);
706 // read forwardjoints (?)
707 for (j = 0; j < 3; j++) {
708 funpackf(tfile, "Bi", &forwardjoints[j]);
710 // read lowforwardjoints (?)
711 for (j = 0; j < 3; j++) {
712 funpackf(tfile, "Bi", &lowforwardjoints[j]);
716 for (j = 0; j < num_muscles; j++) {
717 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
718 for (int k = 0; k < num_models; k++) {
719 if (muscles[j].vertices[i] < model[k].vertexNum) {
720 model[k].owner[muscles[j].vertices[i]] = j;
726 // calculate some stuff
728 for (int i = 0; i < num_muscles; i++) {
729 FindRotationMuscle(i, -1);
731 // this seems to use opengl purely for matrix calculations
732 for (int k = 0; k < num_models; k++) {
733 for (int i = 0; i < model[k].vertexNum; i++) {
734 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
735 glMatrixMode(GL_MODELVIEW);
738 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
739 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
740 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
741 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
742 glGetFloatv(GL_MODELVIEW_MATRIX, M);
743 model[k].vertex[i].x = M[12] * 1;
744 model[k].vertex[i].y = M[13] * 1;
745 model[k].vertex[i].z = M[14] * 1;
748 model[k].CalculateNormals(0);
754 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
756 // skip joints section
758 fseek(tfile, sizeof(num_joints), SEEK_CUR);
759 for (int i = 0; i < num_joints; i++) {
773 fseek(tfile, lSize, SEEK_CUR);
777 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
779 for (int i = 0; i < num_muscles; i++) {
781 lSize = sizeof(float)
787 fseek(tfile, lSize, SEEK_CUR);
789 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
792 lSize = 1; //sizeof(bool);
793 fseek ( tfile, lSize, SEEK_CUR);
795 fseek ( tfile, lSize, SEEK_CUR);
796 fseek ( tfile, lSize, SEEK_CUR);
799 for (j = 0; j < num_muscles; j++) {
800 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
801 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
802 modellow.owner[muscles[j].verticeslow[i]] = j;
807 // use opengl for its matrix math
808 for (int i = 0; i < modellow.vertexNum; i++) {
809 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
810 glMatrixMode(GL_MODELVIEW);
813 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
814 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
815 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
816 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
817 glGetFloatv(GL_MODELVIEW_MATRIX, M);
818 modellow.vertex[i].x = M[12];
819 modellow.vertex[i].y = M[13];
820 modellow.vertex[i].z = M[14];
824 modellow.CalculateNormals(0);
829 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
832 fseek(tfile, sizeof(num_joints), SEEK_CUR);
834 for (int i = 0; i < num_joints; i++) {
848 fseek(tfile, lSize, SEEK_CUR);
852 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
854 for (int i = 0; i < num_muscles; i++) {
856 lSize = sizeof(float)
862 fseek(tfile, lSize, SEEK_CUR);
864 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
867 lSize = 1; //sizeof(bool);
868 fseek ( tfile, lSize, SEEK_CUR);
870 fseek ( tfile, lSize, SEEK_CUR);
871 fseek ( tfile, lSize, SEEK_CUR);
876 for (j = 0; j < num_muscles; j++) {
877 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
878 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
879 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
884 // use opengl for its matrix math
885 for (int i = 0; i < modelclothes.vertexNum; i++) {
886 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
887 glMatrixMode(GL_MODELVIEW);
890 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
891 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
892 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
893 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
894 glGetFloatv(GL_MODELVIEW_MATRIX, M);
895 modelclothes.vertex[i].x = M[12];
896 modelclothes.vertex[i].y = M[13];
897 modelclothes.vertex[i].z = M[14];
901 modelclothes.CalculateNormals(0);
905 for (int i = 0; i < num_joints; i++) {
906 for (j = 0; j < num_joints; j++) {
907 if (joints[i].label == j)