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 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
327 if (k < Object::objects.size() && k >= 0)
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;
404 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
407 multiplier = tempmult;
410 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
411 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
412 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
413 if (Object::objects[k]->possible) {
414 for (i = 0; i < 26; i++) {
415 //Make this less stupid
416 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
417 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
418 whichhit = Object::objects[k]->model.LineCheckSlidePossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
419 if (whichhit != -1) {
420 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
421 for (unsigned j = 0; j < muscles.size(); j++) {
422 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]))
423 muscles[j].DoConstraint(spinny);
430 for (i = 0; i < joints.size(); i++) {
431 switch (joints[i].label) {
447 joints[i].position.y += groundlevel;
449 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)
451 if (joints[i].locked) {
460 for (i = 0; i < muscles.size(); i++) {
461 if (muscles[i].type == boneconnect)
462 muscles[i].DoConstraint(0);
470 * applies gravity to the skeleton
473 * Person/Person::DoStuff
475 void Skeleton::DoGravity(float *scale)
477 for (unsigned i = 0; i < joints.size(); i++) {
480 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
481 (lowforward.y > -.1) ||
484 ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
488 joints[i].velocity.y += gravity * multiplier / (*scale);
494 * set muscles[which].rotate1
498 * special case if animation == hanganim
500 void Skeleton::FindRotationMuscle(int which, int animation)
505 p1 = muscles[which].parent1->position;
506 p2 = muscles[which].parent2->position;
507 dist = findDistance(&p1, &p2);
508 if (p1.y - p2.y <= dist)
509 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
510 if (p1.y - p2.y > dist)
511 muscles[which].rotate2 = asin(1.f);
512 muscles[which].rotate2 *= 360.0 / 6.2831853;
516 dist = findDistance(&p1, &p2);
517 if (p1.z - p2.z <= dist)
518 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
519 if (p1.z - p2.z > dist)
520 muscles[which].rotate1 = acos(1.f);
521 muscles[which].rotate1 *= 360.0 / 6.2831853;
523 muscles[which].rotate1 = 360 - muscles[which].rotate1;
524 if (!isnormal(muscles[which].rotate1))
525 muscles[which].rotate1 = 0;
526 if (!isnormal(muscles[which].rotate2))
527 muscles[which].rotate2 = 0;
529 const int label1 = muscles[which].parent1->label;
530 const int label2 = muscles[which].parent2->label;
533 fwd = specialforward[0];
539 fwd = specialforward[1];
545 fwd = specialforward[2];
551 fwd = specialforward[3];
557 fwd = specialforward[4];
560 if (muscles[which].parent1->lower)
567 if (animation == hanganim) {
568 if (label1 == righthand || label2 == righthand) {
572 if (label1 == lefthand || label2 == lefthand) {
579 if (label1 == rightfoot || label2 == rightfoot) {
582 if (label1 == leftfoot || label2 == leftfoot) {
587 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
588 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
590 fwd /= findLength(&fwd);
591 if (fwd.z <= 1 && fwd.z >= -1)
592 muscles[which].rotate3 = acos(0 - fwd.z);
594 muscles[which].rotate3 = acos(-1.f);
595 muscles[which].rotate3 *= 360.0 / 6.2831853;
597 muscles[which].rotate3 = 360 - muscles[which].rotate3;
598 if (!isnormal(muscles[which].rotate3))
599 muscles[which].rotate3 = 0;
604 * takes filenames for three skeleton files and various models
606 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
607 const std::string& modelfilename, const std::string& model2filename,
608 const std::string& model3filename, const std::string& model4filename,
609 const std::string& model5filename, const std::string& model6filename,
610 const std::string& model7filename, const std::string& modellowfilename,
611 const std::string& modelclothesfilename, bool clothes)
616 int j, num_joints, num_muscles;
622 // load various models
623 // rotate, scale, do normals, do texcoords for each as needed
625 model[0].loadnotex(modelfilename);
626 model[1].loadnotex(model2filename);
627 model[2].loadnotex(model3filename);
628 model[3].loadnotex(model4filename);
629 model[4].loadnotex(model5filename);
630 model[5].loadnotex(model6filename);
631 model[6].loadnotex(model7filename);
633 for (int i = 0; i < num_models; i++) {
634 model[i].Rotate(180, 0, 0);
635 model[i].Scale(.04, .04, .04);
636 model[i].CalculateNormals(0);
639 drawmodel.load(modelfilename, 0);
640 drawmodel.Rotate(180, 0, 0);
641 drawmodel.Scale(.04, .04, .04);
642 drawmodel.FlipTexCoords();
643 if ((Tutorial::active) && (id != 0)) {
644 drawmodel.UniformTexCoords();
645 drawmodel.ScaleTexCoords(0.1);
647 drawmodel.CalculateNormals(0);
649 modellow.loadnotex(modellowfilename);
650 modellow.Rotate(180, 0, 0);
651 modellow.Scale(.04, .04, .04);
652 modellow.CalculateNormals(0);
654 drawmodellow.load(modellowfilename, 0);
655 drawmodellow.Rotate(180, 0, 0);
656 drawmodellow.Scale(.04, .04, .04);
657 drawmodellow.FlipTexCoords();
658 if (Tutorial::active && id != 0)
659 drawmodellow.UniformTexCoords();
660 if (Tutorial::active && id != 0)
661 drawmodellow.ScaleTexCoords(0.1);
662 drawmodellow.CalculateNormals(0);
665 modelclothes.loadnotex(modelclothesfilename);
666 modelclothes.Rotate(180, 0, 0);
667 modelclothes.Scale(.041, .04, .041);
668 modelclothes.CalculateNormals(0);
670 drawmodelclothes.load(modelclothesfilename, 0);
671 drawmodelclothes.Rotate(180, 0, 0);
672 drawmodelclothes.Scale(.04, .04, .04);
673 drawmodelclothes.FlipTexCoords();
674 drawmodelclothes.CalculateNormals(0);
677 // FIXME: three similar blocks follow, one for each of:
678 // filename, lowfilename, clothesfilename
682 tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
685 funpackf(tfile, "Bi", &num_joints);
687 joints.resize(num_joints);
689 // read info for each joint
690 for (int i = 0; i < num_joints; i++) {
691 joints[i].load(tfile, joints);
695 funpackf(tfile, "Bi", &num_muscles);
698 muscles.resize(num_muscles);
700 // for each muscle...
701 for (int i = 0; i < num_muscles; i++) {
702 muscles[i].load(tfile, model[0].vertexNum, joints);
705 // read forwardjoints (?)
706 for (j = 0; j < 3; j++) {
707 funpackf(tfile, "Bi", &forwardjoints[j]);
709 // read lowforwardjoints (?)
710 for (j = 0; j < 3; j++) {
711 funpackf(tfile, "Bi", &lowforwardjoints[j]);
715 for (j = 0; j < num_muscles; j++) {
716 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
717 for (int k = 0; k < num_models; k++) {
718 if (muscles[j].vertices[i] < model[k].vertexNum) {
719 model[k].owner[muscles[j].vertices[i]] = j;
725 // calculate some stuff
727 for (int i = 0; i < num_muscles; i++) {
728 FindRotationMuscle(i, -1);
730 // this seems to use opengl purely for matrix calculations
731 for (int k = 0; k < num_models; k++) {
732 for (int i = 0; i < model[k].vertexNum; i++) {
733 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
734 glMatrixMode(GL_MODELVIEW);
737 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
738 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
739 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
740 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
741 glGetFloatv(GL_MODELVIEW_MATRIX, M);
742 model[k].vertex[i].x = M[12] * 1;
743 model[k].vertex[i].y = M[13] * 1;
744 model[k].vertex[i].z = M[14] * 1;
747 model[k].CalculateNormals(0);
753 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
755 // skip joints section
757 fseek(tfile, sizeof(num_joints), SEEK_CUR);
758 for (int i = 0; i < num_joints; i++) {
772 fseek(tfile, lSize, SEEK_CUR);
776 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
778 for (int i = 0; i < num_muscles; i++) {
780 lSize = sizeof(float)
786 fseek(tfile, lSize, SEEK_CUR);
788 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
791 lSize = 1; //sizeof(bool);
792 fseek ( tfile, lSize, SEEK_CUR);
794 fseek ( tfile, lSize, SEEK_CUR);
795 fseek ( tfile, lSize, SEEK_CUR);
798 for (j = 0; j < num_muscles; j++) {
799 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
800 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
801 modellow.owner[muscles[j].verticeslow[i]] = j;
806 // use opengl for its matrix math
807 for (int i = 0; i < modellow.vertexNum; i++) {
808 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
809 glMatrixMode(GL_MODELVIEW);
812 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
813 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
814 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
815 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
816 glGetFloatv(GL_MODELVIEW_MATRIX, M);
817 modellow.vertex[i].x = M[12];
818 modellow.vertex[i].y = M[13];
819 modellow.vertex[i].z = M[14];
823 modellow.CalculateNormals(0);
828 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
831 fseek(tfile, sizeof(num_joints), SEEK_CUR);
833 for (int i = 0; i < num_joints; i++) {
847 fseek(tfile, lSize, SEEK_CUR);
851 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
853 for (int i = 0; i < num_muscles; i++) {
855 lSize = sizeof(float)
861 fseek(tfile, lSize, SEEK_CUR);
863 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
866 lSize = 1; //sizeof(bool);
867 fseek ( tfile, lSize, SEEK_CUR);
869 fseek ( tfile, lSize, SEEK_CUR);
870 fseek ( tfile, lSize, SEEK_CUR);
875 for (j = 0; j < num_muscles; j++) {
876 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
877 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
878 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
883 // use opengl for its matrix math
884 for (int i = 0; i < modelclothes.vertexNum; i++) {
885 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
886 glMatrixMode(GL_MODELVIEW);
889 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
890 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
891 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
892 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
893 glGetFloatv(GL_MODELVIEW_MATRIX, M);
894 modelclothes.vertex[i].x = M[12];
895 modelclothes.vertex[i].y = M[13];
896 modelclothes.vertex[i].z = M[14];
900 modelclothes.CalculateNormals(0);
904 for (int i = 0; i < num_joints; i++) {
905 for (j = 0; j < num_joints; j++) {
906 if (joints[i].label == j)