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;
122 float damage = 0; // eventually returned from function
123 bool breaking = false;
126 freetime += multiplier;
128 whichpatchx = coords->x / (terrain.size / subdivision * terrain.scale);
129 whichpatchz = coords->z / (terrain.size / subdivision * terrain.scale);
131 terrainlight = *coords;
132 Object::SphereCheckPossible(&terrainlight, 1);
135 for (i = 0; i < joints.size(); i++) {
136 joints[i].position = joints[i].position + joints[i].velocity * multiplier;
138 switch (joints[i].label) {
155 joints[i].position.y -= groundlevel;
156 joints[i].oldvelocity = joints[i].velocity;
159 float tempmult = multiplier;
160 //multiplier/=numrepeats;
162 for (int j = 0; j < numrepeats; j++) {
164 // right leg constraints?
165 if (!joint(rightknee).locked && !joint(righthip).locked) {
166 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
167 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(righthip), &jointPos(rightankle), &jointPos(rightknee), &r)) {
168 jointPos(rightknee) -= lowforward * .05;
170 jointVel(rightknee) -= lowforward * .05 / multiplier / 4;
172 jointVel(rightknee) -= lowforward * .05;
173 jointPos(rightankle) += lowforward * .025;
175 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
177 jointVel(rightankle) += lowforward * .25;
178 jointPos(righthip) += lowforward * .025;
180 jointVel(righthip) += lowforward * .025 / multiplier / 4;
182 jointVel(righthip) += lowforward * .025;
183 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
187 // left leg constraints?
188 if (!joint(leftknee).locked && !joint(lefthip).locked) {
189 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
190 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
191 jointPos(leftknee) -= lowforward * .05;
193 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
195 jointVel(leftknee) -= lowforward * .05;
196 jointPos(leftankle) += lowforward * .025;
198 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
200 jointVel(leftankle) += lowforward * .25;
201 jointPos(lefthip) += lowforward * .025;
203 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
205 jointVel(lefthip) += lowforward * .025;
206 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
210 for (i = 0; i < joints.size(); i++) {
211 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320)
212 joints[i].locked = 0;
213 if (spinny && findLengthfast(&joints[i].velocity) > 600)
214 joints[i].locked = 0;
215 if (joints[i].delay > 0) {
217 for (unsigned j = 0; j < joints.size(); j++) {
218 if (joints[j].locked)
222 joints[i].delay -= multiplier * 3;
226 for (i = 0; i < muscles.size(); i++) {
228 muscles[i].DoConstraint(spinny);
232 for (i = 0; i < joints.size(); i++) {
236 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) {
239 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
240 joints[i].locked = 1;
242 if (!Tutorial::active || id == 0) {
243 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
248 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
249 joints[i].locked = 1;
251 if (!Tutorial::active || id == 0) {
252 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
256 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
257 ReflectVector(&joints[i].velocity, &terrainnormal);
258 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
259 if (!joints[i].locked)
260 damage += findLengthfast(&bounceness) / 4000;
261 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness))
263 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
264 joints[i].velocity -= bounceness;
265 if (1 - friction * frictionness > 0)
266 joints[i].velocity *= 1 - friction * frictionness;
268 joints[i].velocity = 0;
270 if (!Tutorial::active || id == 0)
271 if (findLengthfast(&bounceness) > 8000 && breaking) {
272 // FIXME: this crashes because k is not initialized!
273 // to reproduce, type 'wolfie' in console and play a while
274 // I'll just comment it out for now
275 //Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
276 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
280 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
282 addEnvSound(*coords, 64);
285 if (findLengthfast(&bounceness) > 2500) {
286 Normalise(&bounceness);
287 bounceness = bounceness * 50;
290 joints[i].velocity += bounceness * elasticity;
292 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
294 joints[i].velocity = joints[i].oldvelocity;
298 if (joints[i].locked == 0)
299 if (findLengthfast(&joints[i].velocity) < 1)
300 joints[i].locked = 1;
302 if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
303 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
304 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7);
306 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
307 } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
308 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
309 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);
312 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
313 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
314 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);
315 } else if (findLengthfast(&bounceness) > 500)
316 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
319 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
323 for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) {
324 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
325 if (k < Object::objects.size()) {
326 if (Object::objects[k]->possible) {
327 friction = Object::objects[k]->friction;
328 XYZ start = joints[i].realoldposition;
329 XYZ end = joints[i].position * (*scale) + *coords;
330 whichhit = Object::objects[k]->model.LineCheckPossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
331 if (whichhit != -1) {
332 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
333 joints[i].locked = 1;
335 if (!Tutorial::active || id == 0) {
336 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
341 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
342 joints[i].locked = 1;
344 if (!Tutorial::active || id == 0) {
345 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
349 terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
350 if (terrainnormal.y > .8)
352 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
353 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
355 joints[i].velocity = joints[i].oldvelocity;
357 if (!Tutorial::active || id == 0)
358 if (findLengthfast(&bounceness) > 4000 && breaking) {
359 Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
360 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
364 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
366 addEnvSound(*coords, 64);
368 if (Object::objects[k]->type == treetrunktype) {
369 Object::objects[k]->rotx += joints[i].velocity.x * multiplier * .4;
370 Object::objects[k]->roty += joints[i].velocity.z * multiplier * .4;
371 Object::objects[k + 1]->rotx += joints[i].velocity.x * multiplier * .4;
372 Object::objects[k + 1]->roty += joints[i].velocity.z * multiplier * .4;
374 if (!joints[i].locked)
375 damage += findLengthfast(&bounceness) / 2500;
376 ReflectVector(&joints[i].velocity, &terrainnormal);
377 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
378 joints[i].velocity -= bounceness;
379 if (1 - friction * frictionness > 0)
380 joints[i].velocity *= 1 - friction * frictionness;
382 joints[i].velocity = 0;
383 if (findLengthfast(&bounceness) > 2500) {
384 Normalise(&bounceness);
385 bounceness = bounceness * 50;
387 joints[i].velocity += bounceness * elasticity;
390 if (!joints[i].locked)
391 if (findLengthfast(&joints[i].velocity) < 1) {
392 joints[i].locked = 1;
394 if (findLengthfast(&bounceness) > 500)
395 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
396 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
403 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
406 multiplier = tempmult;
409 for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) {
410 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
411 if (Object::objects[k]->possible) {
412 for (i = 0; i < 26; i++) {
413 //Make this less stupid
414 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
415 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
416 whichhit = Object::objects[k]->model.LineCheckSlidePossible(&start, &end, &Object::objects[k]->position, &Object::objects[k]->yaw);
417 if (whichhit != -1) {
418 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
419 for (unsigned j = 0; j < muscles.size(); j++) {
420 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]))
421 muscles[j].DoConstraint(spinny);
428 for (i = 0; i < joints.size(); i++) {
429 switch (joints[i].label) {
445 joints[i].position.y += groundlevel;
447 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)
449 if (joints[i].locked) {
458 for (i = 0; i < muscles.size(); i++) {
459 if (muscles[i].type == boneconnect)
460 muscles[i].DoConstraint(0);
468 * applies gravity to the skeleton
471 * Person/Person::DoStuff
473 void Skeleton::DoGravity(float *scale)
475 for (unsigned i = 0; i < joints.size(); i++) {
478 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
479 (lowforward.y > -.1) ||
482 ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
486 joints[i].velocity.y += gravity * multiplier / (*scale);
492 * set muscles[which].rotate1
496 * special case if animation == hanganim
498 void Skeleton::FindRotationMuscle(int which, int animation)
503 p1 = muscles[which].parent1->position;
504 p2 = muscles[which].parent2->position;
505 dist = findDistance(&p1, &p2);
506 if (p1.y - p2.y <= dist)
507 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
508 if (p1.y - p2.y > dist)
509 muscles[which].rotate2 = asin(1.f);
510 muscles[which].rotate2 *= 360.0 / 6.2831853;
514 dist = findDistance(&p1, &p2);
515 if (p1.z - p2.z <= dist)
516 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
517 if (p1.z - p2.z > dist)
518 muscles[which].rotate1 = acos(1.f);
519 muscles[which].rotate1 *= 360.0 / 6.2831853;
521 muscles[which].rotate1 = 360 - muscles[which].rotate1;
522 if (!isnormal(muscles[which].rotate1))
523 muscles[which].rotate1 = 0;
524 if (!isnormal(muscles[which].rotate2))
525 muscles[which].rotate2 = 0;
527 const int label1 = muscles[which].parent1->label;
528 const int label2 = muscles[which].parent2->label;
531 fwd = specialforward[0];
537 fwd = specialforward[1];
543 fwd = specialforward[2];
549 fwd = specialforward[3];
555 fwd = specialforward[4];
558 if (muscles[which].parent1->lower)
565 if (animation == hanganim) {
566 if (label1 == righthand || label2 == righthand) {
570 if (label1 == lefthand || label2 == lefthand) {
577 if (label1 == rightfoot || label2 == rightfoot) {
580 if (label1 == leftfoot || label2 == leftfoot) {
585 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
586 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
588 fwd /= findLength(&fwd);
589 if (fwd.z <= 1 && fwd.z >= -1)
590 muscles[which].rotate3 = acos(0 - fwd.z);
592 muscles[which].rotate3 = acos(-1.f);
593 muscles[which].rotate3 *= 360.0 / 6.2831853;
595 muscles[which].rotate3 = 360 - muscles[which].rotate3;
596 if (!isnormal(muscles[which].rotate3))
597 muscles[which].rotate3 = 0;
602 * takes filenames for three skeleton files and various models
604 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
605 const std::string& modelfilename, const std::string& model2filename,
606 const std::string& model3filename, const std::string& model4filename,
607 const std::string& model5filename, const std::string& model6filename,
608 const std::string& model7filename, const std::string& modellowfilename,
609 const std::string& modelclothesfilename, bool clothes)
614 int j, num_joints, num_muscles;
620 // load various models
621 // rotate, scale, do normals, do texcoords for each as needed
623 model[0].loadnotex(modelfilename);
624 model[1].loadnotex(model2filename);
625 model[2].loadnotex(model3filename);
626 model[3].loadnotex(model4filename);
627 model[4].loadnotex(model5filename);
628 model[5].loadnotex(model6filename);
629 model[6].loadnotex(model7filename);
631 for (int i = 0; i < num_models; i++) {
632 model[i].Rotate(180, 0, 0);
633 model[i].Scale(.04, .04, .04);
634 model[i].CalculateNormals(0);
637 drawmodel.load(modelfilename);
638 drawmodel.Rotate(180, 0, 0);
639 drawmodel.Scale(.04, .04, .04);
640 drawmodel.FlipTexCoords();
641 if ((Tutorial::active) && (id != 0)) {
642 drawmodel.UniformTexCoords();
643 drawmodel.ScaleTexCoords(0.1);
645 drawmodel.CalculateNormals(0);
647 modellow.loadnotex(modellowfilename);
648 modellow.Rotate(180, 0, 0);
649 modellow.Scale(.04, .04, .04);
650 modellow.CalculateNormals(0);
652 drawmodellow.load(modellowfilename);
653 drawmodellow.Rotate(180, 0, 0);
654 drawmodellow.Scale(.04, .04, .04);
655 drawmodellow.FlipTexCoords();
656 if (Tutorial::active && id != 0)
657 drawmodellow.UniformTexCoords();
658 if (Tutorial::active && id != 0)
659 drawmodellow.ScaleTexCoords(0.1);
660 drawmodellow.CalculateNormals(0);
663 modelclothes.loadnotex(modelclothesfilename);
664 modelclothes.Rotate(180, 0, 0);
665 modelclothes.Scale(.041, .04, .041);
666 modelclothes.CalculateNormals(0);
668 drawmodelclothes.load(modelclothesfilename);
669 drawmodelclothes.Rotate(180, 0, 0);
670 drawmodelclothes.Scale(.04, .04, .04);
671 drawmodelclothes.FlipTexCoords();
672 drawmodelclothes.CalculateNormals(0);
675 // FIXME: three similar blocks follow, one for each of:
676 // filename, lowfilename, clothesfilename
680 tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
683 funpackf(tfile, "Bi", &num_joints);
685 joints.resize(num_joints);
687 // read info for each joint
688 for (int i = 0; i < num_joints; i++) {
689 joints[i].load(tfile, joints);
693 funpackf(tfile, "Bi", &num_muscles);
696 muscles.resize(num_muscles);
698 // for each muscle...
699 for (int i = 0; i < num_muscles; i++) {
700 muscles[i].load(tfile, model[0].vertexNum, joints);
703 // read forwardjoints (?)
704 for (j = 0; j < 3; j++) {
705 funpackf(tfile, "Bi", &forwardjoints[j]);
707 // read lowforwardjoints (?)
708 for (j = 0; j < 3; j++) {
709 funpackf(tfile, "Bi", &lowforwardjoints[j]);
713 for (j = 0; j < num_muscles; j++) {
714 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
715 for (int k = 0; k < num_models; k++) {
716 if (muscles[j].vertices[i] < model[k].vertexNum) {
717 model[k].owner[muscles[j].vertices[i]] = j;
723 // calculate some stuff
725 for (int i = 0; i < num_muscles; i++) {
726 FindRotationMuscle(i, -1);
728 // this seems to use opengl purely for matrix calculations
729 for (int k = 0; k < num_models; k++) {
730 for (int i = 0; i < model[k].vertexNum; i++) {
731 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
732 glMatrixMode(GL_MODELVIEW);
735 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
736 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
737 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
738 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
739 glGetFloatv(GL_MODELVIEW_MATRIX, M);
740 model[k].vertex[i].x = M[12] * 1;
741 model[k].vertex[i].y = M[13] * 1;
742 model[k].vertex[i].z = M[14] * 1;
745 model[k].CalculateNormals(0);
751 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
753 // skip joints section
755 fseek(tfile, sizeof(num_joints), SEEK_CUR);
756 for (int i = 0; i < num_joints; i++) {
770 fseek(tfile, lSize, SEEK_CUR);
774 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
776 for (int i = 0; i < num_muscles; i++) {
778 lSize = sizeof(float)
784 fseek(tfile, lSize, SEEK_CUR);
786 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
789 lSize = 1; //sizeof(bool);
790 fseek ( tfile, lSize, SEEK_CUR);
792 fseek ( tfile, lSize, SEEK_CUR);
793 fseek ( tfile, lSize, SEEK_CUR);
796 for (j = 0; j < num_muscles; j++) {
797 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
798 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
799 modellow.owner[muscles[j].verticeslow[i]] = j;
804 // use opengl for its matrix math
805 for (int i = 0; i < modellow.vertexNum; i++) {
806 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
807 glMatrixMode(GL_MODELVIEW);
810 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
811 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
812 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
813 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
814 glGetFloatv(GL_MODELVIEW_MATRIX, M);
815 modellow.vertex[i].x = M[12];
816 modellow.vertex[i].y = M[13];
817 modellow.vertex[i].z = M[14];
821 modellow.CalculateNormals(0);
826 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
829 fseek(tfile, sizeof(num_joints), SEEK_CUR);
831 for (int i = 0; i < num_joints; i++) {
845 fseek(tfile, lSize, SEEK_CUR);
849 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
851 for (int i = 0; i < num_muscles; i++) {
853 lSize = sizeof(float)
859 fseek(tfile, lSize, SEEK_CUR);
861 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
864 lSize = 1; //sizeof(bool);
865 fseek ( tfile, lSize, SEEK_CUR);
867 fseek ( tfile, lSize, SEEK_CUR);
868 fseek ( tfile, lSize, SEEK_CUR);
873 for (j = 0; j < num_muscles; j++) {
874 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
875 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
876 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
881 // use opengl for its matrix math
882 for (int i = 0; i < modelclothes.vertexNum; i++) {
883 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
884 glMatrixMode(GL_MODELVIEW);
887 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
888 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
889 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
890 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
891 glGetFloatv(GL_MODELVIEW_MATRIX, M);
892 modelclothes.vertex[i].x = M[12];
893 modelclothes.vertex[i].y = M[13];
894 modelclothes.vertex[i].z = M[14];
898 modelclothes.CalculateNormals(0);
902 for (int i = 0; i < num_joints; i++) {
903 for (j = 0; j < num_joints; j++) {
904 if (joints[i].label == j)