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 /**> HEADER FILES <**/
23 #include "Animation/Skeleton.h"
24 #include "openal_wrapper.h"
25 #include "Animation/Animation.h"
26 #include "Utils/Folders.h"
28 extern float multiplier;
30 extern Terrain terrain;
31 extern Objects objects;
32 extern int environment;
33 extern float camerashake;
36 extern int tutoriallevel;
38 extern int whichjointstartarray[26];
39 extern int whichjointendarray[26];
41 extern bool visibleloading;
47 memset(forwardjoints, 0, sizeof(forwardjoints));
51 memset(lowforwardjoints, 0, sizeof(lowforwardjoints));
53 memset(jointlabels, 0, sizeof(jointlabels));
60 memset(skinText, 0, sizeof(skinText));
79 * sets forward, lowforward, specialforward[]
83 * Person/Person::DoAnimations
84 * Person/Person::DrawSkeleton
86 void Skeleton::FindForwards()
88 //Find forward vectors
89 CrossProduct(joints[forwardjoints[1]].position - joints[forwardjoints[0]].position, joints[forwardjoints[2]].position - joints[forwardjoints[0]].position, &forward);
92 CrossProduct(joints[lowforwardjoints[1]].position - joints[lowforwardjoints[0]].position, joints[lowforwardjoints[2]].position - joints[lowforwardjoints[0]].position, &lowforward);
93 Normalise(&lowforward);
96 specialforward[0] = forward;
98 specialforward[1] = jointPos(rightshoulder) + jointPos(rightwrist);
99 specialforward[1] = jointPos(rightelbow) - specialforward[1] / 2;
100 specialforward[1] += forward * .4;
101 Normalise(&specialforward[1]);
102 specialforward[2] = jointPos(leftshoulder) + jointPos(leftwrist);
103 specialforward[2] = jointPos(leftelbow) - specialforward[2] / 2;
104 specialforward[2] += forward * .4;
105 Normalise(&specialforward[2]);
107 specialforward[3] = jointPos(righthip) + jointPos(rightankle);
108 specialforward[3] = specialforward[3] / 2 - jointPos(rightknee);
109 specialforward[3] += lowforward * .4;
110 Normalise(&specialforward[3]);
111 specialforward[4] = jointPos(lefthip) + jointPos(leftankle);
112 specialforward[4] = specialforward[4] / 2 - jointPos(leftknee);
113 specialforward[4] += lowforward * .4;
114 Normalise(&specialforward[4]);
121 * Person/Person::RagDoll
122 * Person/Person::DoStuff
125 float Skeleton::DoConstraints(XYZ *coords, float *scale)
127 float friction = 1.5;
128 const float elasticity = .3;
130 const int numrepeats = 3;
131 float groundlevel = .15;
140 float damage = 0; // eventually returned from function
141 bool breaking = false;
144 freetime += multiplier;
146 whichpatchx = coords->x / (terrain.size / subdivision * terrain.scale);
147 whichpatchz = coords->z / (terrain.size / subdivision * terrain.scale);
149 terrainlight = *coords;
150 objects.SphereCheckPossible(&terrainlight, 1);
153 for (i = 0; i < joints.size(); i++) {
154 joints[i].position = joints[i].position + joints[i].velocity * multiplier;
156 switch (joints[i].label) {
173 joints[i].position.y -= groundlevel;
174 joints[i].oldvelocity = joints[i].velocity;
177 float tempmult = multiplier;
178 //multiplier/=numrepeats;
180 for (j = 0; j < numrepeats; j++) {
182 // right leg constraints?
183 if (!joint(rightknee).locked && !joint(righthip).locked) {
184 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
185 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(righthip), &jointPos(rightankle), &jointPos(rightknee), &r)) {
186 jointPos(rightknee) -= lowforward * .05;
188 jointVel(rightknee) -= lowforward * .05 / multiplier / 4;
190 jointVel(rightknee) -= lowforward * .05;
191 jointPos(rightankle) += lowforward * .025;
193 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
195 jointVel(rightankle) += lowforward * .25;
196 jointPos(righthip) += lowforward * .025;
198 jointVel(righthip) += lowforward * .025 / multiplier / 4;
200 jointVel(righthip) += lowforward * .025;
201 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
205 // left leg constraints?
206 if (!joint(leftknee).locked && !joint(lefthip).locked) {
207 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
208 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
209 jointPos(leftknee) -= lowforward * .05;
211 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
213 jointVel(leftknee) -= lowforward * .05;
214 jointPos(leftankle) += lowforward * .025;
216 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
218 jointVel(leftankle) += lowforward * .25;
219 jointPos(lefthip) += lowforward * .025;
221 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
223 jointVel(lefthip) += lowforward * .025;
224 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
228 for (i = 0; i < joints.size(); i++) {
229 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320)
230 joints[i].locked = 0;
231 if (spinny && findLengthfast(&joints[i].velocity) > 600)
232 joints[i].locked = 0;
233 if (joints[i].delay > 0) {
235 for (j = 0; j < joints.size(); j++) {
236 if (joints[j].locked)
240 joints[i].delay -= multiplier * 3;
244 for (i = 0; i < muscles.size(); i++) {
246 muscles[i].DoConstraint(spinny);
249 for (i = 0; i < joints.size(); i++) {
253 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) {
256 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
257 joints[i].locked = 1;
259 if (tutoriallevel != 1 || id == 0) {
260 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
265 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
266 joints[i].locked = 1;
268 if (tutoriallevel != 1 || id == 0) {
269 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
273 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
274 ReflectVector(&joints[i].velocity, &terrainnormal);
275 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
276 if (!joints[i].locked)
277 damage += findLengthfast(&bounceness) / 4000;
278 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness))
280 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
281 joints[i].velocity -= bounceness;
282 if (1 - friction * frictionness > 0)
283 joints[i].velocity *= 1 - friction * frictionness;
285 joints[i].velocity = 0;
287 if (tutoriallevel != 1 || id == 0)
288 if (findLengthfast(&bounceness) > 8000 && breaking) {
289 // FIXME: this crashes because k is not initialized!
290 // to reproduce, type 'wolfie' in console and play a while
291 // I'll just comment it out for now
292 //objects.model[k].MakeDecal(breakdecal, DoRotation(temp - objects.position[k], 0, -objects.yaw[k], 0), .4, .5, Random() % 360);
293 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
297 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
299 addEnvSound(*coords, 64);
302 if (findLengthfast(&bounceness) > 2500) {
303 Normalise(&bounceness);
304 bounceness = bounceness * 50;
307 joints[i].velocity += bounceness * elasticity;
309 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
311 joints[i].velocity = joints[i].oldvelocity;
315 if (joints[i].locked == 0)
316 if (findLengthfast(&joints[i].velocity) < 1)
317 joints[i].locked = 1;
319 if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
320 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
321 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7);
323 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
324 } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
325 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
326 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);
329 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
330 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
331 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);
332 } else if (findLengthfast(&bounceness) > 500)
333 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
336 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
340 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
341 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
342 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
343 if (k < objects.numobjects && k >= 0)
344 if (objects.possible[k]) {
345 friction = objects.friction[k];
346 XYZ start = joints[i].realoldposition;
347 XYZ end = joints[i].position * (*scale) + *coords;
348 whichhit = objects.model[k].LineCheckPossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]);
349 if (whichhit != -1) {
350 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
351 joints[i].locked = 1;
353 if (tutoriallevel != 1 || id == 0) {
354 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
359 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
360 joints[i].locked = 1;
362 if (tutoriallevel != 1 || id == 0) {
363 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
367 terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
368 if (terrainnormal.y > .8)
370 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
371 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
373 joints[i].velocity = joints[i].oldvelocity;
375 if (tutoriallevel != 1 || id == 0)
376 if (findLengthfast(&bounceness) > 4000 && breaking) {
377 objects.model[k].MakeDecal(breakdecal, DoRotation(temp - objects.position[k], 0, -objects.yaw[k], 0), .4, .5, Random() % 360);
378 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
382 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
384 addEnvSound(*coords, 64);
386 if (objects.type[k] == treetrunktype) {
387 objects.rotx[k] += joints[i].velocity.x * multiplier * .4;
388 objects.roty[k] += joints[i].velocity.z * multiplier * .4;
389 objects.rotx[k + 1] += joints[i].velocity.x * multiplier * .4;
390 objects.roty[k + 1] += joints[i].velocity.z * multiplier * .4;
392 if (!joints[i].locked)
393 damage += findLengthfast(&bounceness) / 2500;
394 ReflectVector(&joints[i].velocity, &terrainnormal);
395 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
396 joints[i].velocity -= bounceness;
397 if (1 - friction * frictionness > 0)
398 joints[i].velocity *= 1 - friction * frictionness;
400 joints[i].velocity = 0;
401 if (findLengthfast(&bounceness) > 2500) {
402 Normalise(&bounceness);
403 bounceness = bounceness * 50;
405 joints[i].velocity += bounceness * elasticity;
408 if (!joints[i].locked)
409 if (findLengthfast(&joints[i].velocity) < 1) {
410 joints[i].locked = 1;
412 if (findLengthfast(&bounceness) > 500)
413 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
414 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
420 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
423 multiplier = tempmult;
426 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
427 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
428 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
429 if (objects.possible[k]) {
430 for (i = 0; i < 26; i++) {
431 //Make this less stupid
432 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
433 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
434 whichhit = objects.model[k].LineCheckSlidePossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]);
435 if (whichhit != -1) {
436 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
437 for (j = 0; j < muscles.size(); j++) {
438 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]))
439 muscles[j].DoConstraint(spinny);
446 for (i = 0; i < joints.size(); i++) {
447 switch (joints[i].label) {
463 joints[i].position.y += groundlevel;
465 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)
467 if (joints[i].locked) {
476 for (i = 0; i < muscles.size(); i++) {
477 if (muscles[i].type == boneconnect)
478 muscles[i].DoConstraint(0);
486 * applies gravity to the skeleton
489 * Person/Person::DoStuff
491 void Skeleton::DoGravity(float *scale)
494 for (i = 0; i < joints.size(); i++) {
497 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
498 (lowforward.y > -.1) ||
501 ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
505 joints[i].velocity.y += gravity * multiplier / (*scale);
510 * set muscles[which].rotate1
514 * special case if animation == hanganim
516 void Skeleton::FindRotationMuscle(int which, int animation)
521 p1 = muscles[which].parent1->position;
522 p2 = muscles[which].parent2->position;
523 dist = findDistance(&p1, &p2);
524 if (p1.y - p2.y <= dist)
525 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
526 if (p1.y - p2.y > dist)
527 muscles[which].rotate2 = asin(1.f);
528 muscles[which].rotate2 *= 360.0 / 6.2831853;
532 dist = findDistance(&p1, &p2);
533 if (p1.z - p2.z <= dist)
534 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
535 if (p1.z - p2.z > dist)
536 muscles[which].rotate1 = acos(1.f);
537 muscles[which].rotate1 *= 360.0 / 6.2831853;
539 muscles[which].rotate1 = 360 - muscles[which].rotate1;
540 if (!isnormal(muscles[which].rotate1))
541 muscles[which].rotate1 = 0;
542 if (!isnormal(muscles[which].rotate2))
543 muscles[which].rotate2 = 0;
545 const int label1 = muscles[which].parent1->label;
546 const int label2 = muscles[which].parent2->label;
549 fwd = specialforward[0];
555 fwd = specialforward[1];
561 fwd = specialforward[2];
567 fwd = specialforward[3];
573 fwd = specialforward[4];
576 if (muscles[which].parent1->lower)
583 if (animation == hanganim) {
584 if (label1 == righthand || label2 == righthand) {
588 if (label1 == lefthand || label2 == lefthand) {
595 if (label1 == rightfoot || label2 == rightfoot) {
598 if (label1 == leftfoot || label2 == leftfoot) {
603 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
604 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
606 fwd /= findLength(&fwd);
607 if (fwd.z <= 1 && fwd.z >= -1)
608 muscles[which].rotate3 = acos(0 - fwd.z);
610 muscles[which].rotate3 = acos(-1.f);
611 muscles[which].rotate3 *= 360.0 / 6.2831853;
613 muscles[which].rotate3 = 360 - muscles[which].rotate3;
614 if (!isnormal(muscles[which].rotate3))
615 muscles[which].rotate3 = 0;
620 * takes filenames for three skeleton files and various models
622 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
623 const std::string& modelfilename, const std::string& model2filename,
624 const std::string& model3filename, const std::string& model4filename,
625 const std::string& model5filename, const std::string& model6filename,
626 const std::string& model7filename, const std::string& modellowfilename,
627 const std::string& modelclothesfilename, bool clothes)
632 int i, j, num_joints, num_muscles;
638 // load various models
639 // rotate, scale, do normals, do texcoords for each as needed
641 model[0].loadnotex(modelfilename);
642 model[1].loadnotex(model2filename);
643 model[2].loadnotex(model3filename);
644 model[3].loadnotex(model4filename);
645 model[4].loadnotex(model5filename);
646 model[5].loadnotex(model6filename);
647 model[6].loadnotex(model7filename);
649 for (i = 0; i < num_models; i++) {
650 model[i].Rotate(180, 0, 0);
651 model[i].Scale(.04, .04, .04);
652 model[i].CalculateNormals(0);
655 drawmodel.load(modelfilename, 0);
656 drawmodel.Rotate(180, 0, 0);
657 drawmodel.Scale(.04, .04, .04);
658 drawmodel.FlipTexCoords();
659 if ((tutoriallevel == 1) && (id != 0)) {
660 drawmodel.UniformTexCoords();
661 drawmodel.ScaleTexCoords(0.1);
663 drawmodel.CalculateNormals(0);
665 modellow.loadnotex(modellowfilename);
666 modellow.Rotate(180, 0, 0);
667 modellow.Scale(.04, .04, .04);
668 modellow.CalculateNormals(0);
670 drawmodellow.load(modellowfilename, 0);
671 drawmodellow.Rotate(180, 0, 0);
672 drawmodellow.Scale(.04, .04, .04);
673 drawmodellow.FlipTexCoords();
674 if (tutoriallevel == 1 && id != 0)
675 drawmodellow.UniformTexCoords();
676 if (tutoriallevel == 1 && id != 0)
677 drawmodellow.ScaleTexCoords(0.1);
678 drawmodellow.CalculateNormals(0);
681 modelclothes.loadnotex(modelclothesfilename);
682 modelclothes.Rotate(180, 0, 0);
683 modelclothes.Scale(.041, .04, .041);
684 modelclothes.CalculateNormals(0);
686 drawmodelclothes.load(modelclothesfilename, 0);
687 drawmodelclothes.Rotate(180, 0, 0);
688 drawmodelclothes.Scale(.04, .04, .04);
689 drawmodelclothes.FlipTexCoords();
690 drawmodelclothes.CalculateNormals(0);
693 // FIXME: three similar blocks follow, one for each of:
694 // filename, lowfilename, clothesfilename
698 tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
701 funpackf(tfile, "Bi", &num_joints);
703 joints.resize(num_joints);
705 // read info for each joint
706 for (i = 0; i < num_joints; i++) {
707 joints[i].load(tfile, joints);
711 funpackf(tfile, "Bi", &num_muscles);
714 muscles.resize(num_muscles);
716 // for each muscle...
717 for (i = 0; i < num_muscles; i++) {
718 muscles[i].load(tfile, model[0].vertexNum, joints);
721 // read forwardjoints (?)
722 for (j = 0; j < 3; j++) {
723 funpackf(tfile, "Bi", &forwardjoints[j]);
725 // read lowforwardjoints (?)
726 for (j = 0; j < 3; j++) {
727 funpackf(tfile, "Bi", &lowforwardjoints[j]);
731 for (j = 0; j < num_muscles; j++) {
732 for (i = 0; i < muscles[j].vertices.size(); i++) {
733 for (int k = 0; k < num_models; k++) {
734 if (muscles[j].vertices[i] < model[k].vertexNum)
735 model[k].owner[muscles[j].vertices[i]] = j;
740 // calculate some stuff
742 for (i = 0; i < num_muscles; i++) {
743 FindRotationMuscle(i, -1);
745 // this seems to use opengl purely for matrix calculations
746 for (int k = 0; k < num_models; k++) {
747 for (i = 0; i < model[k].vertexNum; i++) {
748 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
749 glMatrixMode(GL_MODELVIEW);
752 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
753 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
754 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
755 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
756 glGetFloatv(GL_MODELVIEW_MATRIX, M);
757 model[k].vertex[i].x = M[12] * 1;
758 model[k].vertex[i].y = M[13] * 1;
759 model[k].vertex[i].z = M[14] * 1;
762 model[k].CalculateNormals(0);
768 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
770 // skip joints section
772 fseek(tfile, sizeof(num_joints), SEEK_CUR);
773 for (i = 0; i < num_joints; i++) {
787 fseek(tfile, lSize, SEEK_CUR);
791 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
793 for (i = 0; i < num_muscles; i++) {
795 lSize = sizeof(float)
801 fseek(tfile, lSize, SEEK_CUR);
803 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
806 lSize = 1; //sizeof(bool);
807 fseek ( tfile, lSize, SEEK_CUR);
809 fseek ( tfile, lSize, SEEK_CUR);
810 fseek ( tfile, lSize, SEEK_CUR);
813 for (j = 0; j < num_muscles; j++) {
814 for (i = 0; i < muscles[j].verticeslow.size(); i++) {
815 if (muscles[j].verticeslow[i] < modellow.vertexNum)
816 modellow.owner[muscles[j].verticeslow[i]] = j;
820 // use opengl for its matrix math
821 for (i = 0; i < modellow.vertexNum; i++) {
822 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
823 glMatrixMode(GL_MODELVIEW);
826 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
827 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
828 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
829 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
830 glGetFloatv(GL_MODELVIEW_MATRIX, M);
831 modellow.vertex[i].x = M[12];
832 modellow.vertex[i].y = M[13];
833 modellow.vertex[i].z = M[14];
837 modellow.CalculateNormals(0);
842 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
845 fseek(tfile, sizeof(num_joints), SEEK_CUR);
847 for (i = 0; i < num_joints; i++) {
861 fseek(tfile, lSize, SEEK_CUR);
865 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
867 for (i = 0; i < num_muscles; i++) {
869 lSize = sizeof(float)
875 fseek(tfile, lSize, SEEK_CUR);
877 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
880 lSize = 1; //sizeof(bool);
881 fseek ( tfile, lSize, SEEK_CUR);
883 fseek ( tfile, lSize, SEEK_CUR);
884 fseek ( tfile, lSize, SEEK_CUR);
889 for (j = 0; j < num_muscles; j++) {
890 for (i = 0; i < muscles[j].verticesclothes.size(); i++) {
891 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum)
892 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
896 // use opengl for its matrix math
897 for (i = 0; i < modelclothes.vertexNum; i++) {
898 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
899 glMatrixMode(GL_MODELVIEW);
902 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
903 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
904 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
905 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
906 glGetFloatv(GL_MODELVIEW_MATRIX, M);
907 modelclothes.vertex[i].x = M[12];
908 modelclothes.vertex[i].y = M[13];
909 modelclothes.vertex[i].z = M[14];
913 modelclothes.CalculateNormals(0);
917 for (i = 0; i < num_joints; i++) {
918 for (j = 0; j < num_joints; j++) {
919 if (joints[i].label == j)