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 extern bool visibleloading;
42 Skeleton::Skeleton() :
57 memset(forwardjoints, 0, sizeof(forwardjoints));
58 memset(lowforwardjoints, 0, sizeof(lowforwardjoints));
59 memset(jointlabels, 0, sizeof(jointlabels));
60 memset(skinText, 0, sizeof(skinText));
64 * sets forward, lowforward, specialforward[]
68 * Person/Person::DoAnimations
69 * Person/Person::DrawSkeleton
71 void Skeleton::FindForwards()
73 //Find forward vectors
74 CrossProduct(joints[forwardjoints[1]].position - joints[forwardjoints[0]].position, joints[forwardjoints[2]].position - joints[forwardjoints[0]].position, &forward);
77 CrossProduct(joints[lowforwardjoints[1]].position - joints[lowforwardjoints[0]].position, joints[lowforwardjoints[2]].position - joints[lowforwardjoints[0]].position, &lowforward);
78 Normalise(&lowforward);
81 specialforward[0] = forward;
83 specialforward[1] = jointPos(rightshoulder) + jointPos(rightwrist);
84 specialforward[1] = jointPos(rightelbow) - specialforward[1] / 2;
85 specialforward[1] += forward * .4;
86 Normalise(&specialforward[1]);
87 specialforward[2] = jointPos(leftshoulder) + jointPos(leftwrist);
88 specialforward[2] = jointPos(leftelbow) - specialforward[2] / 2;
89 specialforward[2] += forward * .4;
90 Normalise(&specialforward[2]);
92 specialforward[3] = jointPos(righthip) + jointPos(rightankle);
93 specialforward[3] = specialforward[3] / 2 - jointPos(rightknee);
94 specialforward[3] += lowforward * .4;
95 Normalise(&specialforward[3]);
96 specialforward[4] = jointPos(lefthip) + jointPos(leftankle);
97 specialforward[4] = specialforward[4] / 2 - jointPos(leftknee);
98 specialforward[4] += lowforward * .4;
99 Normalise(&specialforward[4]);
106 * Person/Person::RagDoll
107 * Person/Person::DoStuff
110 float Skeleton::DoConstraints(XYZ *coords, float *scale)
112 float friction = 1.5;
113 const float elasticity = .3;
115 const int numrepeats = 3;
116 float groundlevel = .15;
126 float damage = 0; // eventually returned from function
127 bool breaking = false;
130 freetime += multiplier;
132 whichpatchx = coords->x / (terrain.size / subdivision * terrain.scale);
133 whichpatchz = coords->z / (terrain.size / subdivision * terrain.scale);
135 terrainlight = *coords;
136 Object::SphereCheckPossible(&terrainlight, 1);
139 for (i = 0; i < joints.size(); i++) {
140 joints[i].position = joints[i].position + joints[i].velocity * multiplier;
142 switch (joints[i].label) {
159 joints[i].position.y -= groundlevel;
160 joints[i].oldvelocity = joints[i].velocity;
163 float tempmult = multiplier;
164 //multiplier/=numrepeats;
166 for (int j = 0; j < numrepeats; j++) {
168 // right leg constraints?
169 if (!joint(rightknee).locked && !joint(righthip).locked) {
170 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
171 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(righthip), &jointPos(rightankle), &jointPos(rightknee), &r)) {
172 jointPos(rightknee) -= lowforward * .05;
174 jointVel(rightknee) -= lowforward * .05 / multiplier / 4;
176 jointVel(rightknee) -= lowforward * .05;
177 jointPos(rightankle) += lowforward * .025;
179 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
181 jointVel(rightankle) += lowforward * .25;
182 jointPos(righthip) += lowforward * .025;
184 jointVel(righthip) += lowforward * .025 / multiplier / 4;
186 jointVel(righthip) += lowforward * .025;
187 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
191 // left leg constraints?
192 if (!joint(leftknee).locked && !joint(lefthip).locked) {
193 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
194 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
195 jointPos(leftknee) -= lowforward * .05;
197 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
199 jointVel(leftknee) -= lowforward * .05;
200 jointPos(leftankle) += lowforward * .025;
202 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
204 jointVel(leftankle) += lowforward * .25;
205 jointPos(lefthip) += lowforward * .025;
207 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
209 jointVel(lefthip) += lowforward * .025;
210 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
214 for (i = 0; i < joints.size(); i++) {
215 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320)
216 joints[i].locked = 0;
217 if (spinny && findLengthfast(&joints[i].velocity) > 600)
218 joints[i].locked = 0;
219 if (joints[i].delay > 0) {
221 for (unsigned j = 0; j < joints.size(); j++) {
222 if (joints[j].locked)
226 joints[i].delay -= multiplier * 3;
230 for (i = 0; i < muscles.size(); i++) {
232 muscles[i].DoConstraint(spinny);
235 for (i = 0; i < joints.size(); i++) {
239 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) {
242 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
243 joints[i].locked = 1;
245 if (!Tutorial::active || id == 0) {
246 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
251 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
252 joints[i].locked = 1;
254 if (!Tutorial::active || id == 0) {
255 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
259 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
260 ReflectVector(&joints[i].velocity, &terrainnormal);
261 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
262 if (!joints[i].locked)
263 damage += findLengthfast(&bounceness) / 4000;
264 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness))
266 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
267 joints[i].velocity -= bounceness;
268 if (1 - friction * frictionness > 0)
269 joints[i].velocity *= 1 - friction * frictionness;
271 joints[i].velocity = 0;
273 if (!Tutorial::active || id == 0)
274 if (findLengthfast(&bounceness) > 8000 && breaking) {
275 // FIXME: this crashes because k is not initialized!
276 // to reproduce, type 'wolfie' in console and play a while
277 // I'll just comment it out for now
278 //Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
279 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
283 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
285 addEnvSound(*coords, 64);
288 if (findLengthfast(&bounceness) > 2500) {
289 Normalise(&bounceness);
290 bounceness = bounceness * 50;
293 joints[i].velocity += bounceness * elasticity;
295 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
297 joints[i].velocity = joints[i].oldvelocity;
301 if (joints[i].locked == 0)
302 if (findLengthfast(&joints[i].velocity) < 1)
303 joints[i].locked = 1;
305 if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
306 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
307 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7);
309 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
310 } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
311 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
312 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);
315 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
316 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
317 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);
318 } else if (findLengthfast(&bounceness) > 500)
319 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
322 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
326 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
327 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
328 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
329 if (k < Object::objects.size() && k >= 0)
330 if (Object::objects[k]->possible) {
331 friction = Object::objects[k]->friction;
332 XYZ start = joints[i].realoldposition;
333 XYZ end = joints[i].position * (*scale) + *coords;
334 whichhit = Object::objects[k]->model.LineCheckPossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
335 if (whichhit != -1) {
336 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
337 joints[i].locked = 1;
339 if (!Tutorial::active || id == 0) {
340 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
345 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
346 joints[i].locked = 1;
348 if (!Tutorial::active || id == 0) {
349 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
353 terrainnormal = DoRotation(Object::objects[k]->model.facenormals[whichhit], 0, Object::objects[k]->yaw, 0) * -1;
354 if (terrainnormal.y > .8)
356 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
357 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
359 joints[i].velocity = joints[i].oldvelocity;
361 if (!Tutorial::active || id == 0)
362 if (findLengthfast(&bounceness) > 4000 && breaking) {
363 Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
364 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
368 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
370 addEnvSound(*coords, 64);
372 if (Object::objects[k]->type == treetrunktype) {
373 Object::objects[k]->rotx += joints[i].velocity.x * multiplier * .4;
374 Object::objects[k]->roty += joints[i].velocity.z * multiplier * .4;
375 Object::objects[k + 1]->rotx += joints[i].velocity.x * multiplier * .4;
376 Object::objects[k + 1]->roty += joints[i].velocity.z * multiplier * .4;
378 if (!joints[i].locked)
379 damage += findLengthfast(&bounceness) / 2500;
380 ReflectVector(&joints[i].velocity, &terrainnormal);
381 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
382 joints[i].velocity -= bounceness;
383 if (1 - friction * frictionness > 0)
384 joints[i].velocity *= 1 - friction * frictionness;
386 joints[i].velocity = 0;
387 if (findLengthfast(&bounceness) > 2500) {
388 Normalise(&bounceness);
389 bounceness = bounceness * 50;
391 joints[i].velocity += bounceness * elasticity;
394 if (!joints[i].locked)
395 if (findLengthfast(&joints[i].velocity) < 1) {
396 joints[i].locked = 1;
398 if (findLengthfast(&bounceness) > 500)
399 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
400 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
406 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
409 multiplier = tempmult;
412 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
413 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
414 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
415 if (Object::objects[k]->possible) {
416 for (i = 0; i < 26; i++) {
417 //Make this less stupid
418 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
419 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
420 whichhit = Object::objects[k]->model.LineCheckSlidePossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
421 if (whichhit != -1) {
422 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
423 for (unsigned j = 0; j < muscles.size(); j++) {
424 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]))
425 muscles[j].DoConstraint(spinny);
432 for (i = 0; i < joints.size(); i++) {
433 switch (joints[i].label) {
449 joints[i].position.y += groundlevel;
451 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)
453 if (joints[i].locked) {
462 for (i = 0; i < muscles.size(); i++) {
463 if (muscles[i].type == boneconnect)
464 muscles[i].DoConstraint(0);
472 * applies gravity to the skeleton
475 * Person/Person::DoStuff
477 void Skeleton::DoGravity(float *scale)
479 for (unsigned i = 0; i < joints.size(); i++) {
482 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
483 (lowforward.y > -.1) ||
486 ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
490 joints[i].velocity.y += gravity * multiplier / (*scale);
496 * set muscles[which].rotate1
500 * special case if animation == hanganim
502 void Skeleton::FindRotationMuscle(int which, int animation)
507 p1 = muscles[which].parent1->position;
508 p2 = muscles[which].parent2->position;
509 dist = findDistance(&p1, &p2);
510 if (p1.y - p2.y <= dist)
511 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
512 if (p1.y - p2.y > dist)
513 muscles[which].rotate2 = asin(1.f);
514 muscles[which].rotate2 *= 360.0 / 6.2831853;
518 dist = findDistance(&p1, &p2);
519 if (p1.z - p2.z <= dist)
520 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
521 if (p1.z - p2.z > dist)
522 muscles[which].rotate1 = acos(1.f);
523 muscles[which].rotate1 *= 360.0 / 6.2831853;
525 muscles[which].rotate1 = 360 - muscles[which].rotate1;
526 if (!isnormal(muscles[which].rotate1))
527 muscles[which].rotate1 = 0;
528 if (!isnormal(muscles[which].rotate2))
529 muscles[which].rotate2 = 0;
531 const int label1 = muscles[which].parent1->label;
532 const int label2 = muscles[which].parent2->label;
535 fwd = specialforward[0];
541 fwd = specialforward[1];
547 fwd = specialforward[2];
553 fwd = specialforward[3];
559 fwd = specialforward[4];
562 if (muscles[which].parent1->lower)
569 if (animation == hanganim) {
570 if (label1 == righthand || label2 == righthand) {
574 if (label1 == lefthand || label2 == lefthand) {
581 if (label1 == rightfoot || label2 == rightfoot) {
584 if (label1 == leftfoot || label2 == leftfoot) {
589 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
590 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
592 fwd /= findLength(&fwd);
593 if (fwd.z <= 1 && fwd.z >= -1)
594 muscles[which].rotate3 = acos(0 - fwd.z);
596 muscles[which].rotate3 = acos(-1.f);
597 muscles[which].rotate3 *= 360.0 / 6.2831853;
599 muscles[which].rotate3 = 360 - muscles[which].rotate3;
600 if (!isnormal(muscles[which].rotate3))
601 muscles[which].rotate3 = 0;
606 * takes filenames for three skeleton files and various models
608 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
609 const std::string& modelfilename, const std::string& model2filename,
610 const std::string& model3filename, const std::string& model4filename,
611 const std::string& model5filename, const std::string& model6filename,
612 const std::string& model7filename, const std::string& modellowfilename,
613 const std::string& modelclothesfilename, bool clothes)
618 int j, num_joints, num_muscles;
624 // load various models
625 // rotate, scale, do normals, do texcoords for each as needed
627 model[0].loadnotex(modelfilename);
628 model[1].loadnotex(model2filename);
629 model[2].loadnotex(model3filename);
630 model[3].loadnotex(model4filename);
631 model[4].loadnotex(model5filename);
632 model[5].loadnotex(model6filename);
633 model[6].loadnotex(model7filename);
635 for (int i = 0; i < num_models; i++) {
636 model[i].Rotate(180, 0, 0);
637 model[i].Scale(.04, .04, .04);
638 model[i].CalculateNormals(0);
641 drawmodel.load(modelfilename, 0);
642 drawmodel.Rotate(180, 0, 0);
643 drawmodel.Scale(.04, .04, .04);
644 drawmodel.FlipTexCoords();
645 if ((Tutorial::active) && (id != 0)) {
646 drawmodel.UniformTexCoords();
647 drawmodel.ScaleTexCoords(0.1);
649 drawmodel.CalculateNormals(0);
651 modellow.loadnotex(modellowfilename);
652 modellow.Rotate(180, 0, 0);
653 modellow.Scale(.04, .04, .04);
654 modellow.CalculateNormals(0);
656 drawmodellow.load(modellowfilename, 0);
657 drawmodellow.Rotate(180, 0, 0);
658 drawmodellow.Scale(.04, .04, .04);
659 drawmodellow.FlipTexCoords();
660 if (Tutorial::active && id != 0)
661 drawmodellow.UniformTexCoords();
662 if (Tutorial::active && id != 0)
663 drawmodellow.ScaleTexCoords(0.1);
664 drawmodellow.CalculateNormals(0);
667 modelclothes.loadnotex(modelclothesfilename);
668 modelclothes.Rotate(180, 0, 0);
669 modelclothes.Scale(.041, .04, .041);
670 modelclothes.CalculateNormals(0);
672 drawmodelclothes.load(modelclothesfilename, 0);
673 drawmodelclothes.Rotate(180, 0, 0);
674 drawmodelclothes.Scale(.04, .04, .04);
675 drawmodelclothes.FlipTexCoords();
676 drawmodelclothes.CalculateNormals(0);
679 // FIXME: three similar blocks follow, one for each of:
680 // filename, lowfilename, clothesfilename
684 tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
687 funpackf(tfile, "Bi", &num_joints);
689 joints.resize(num_joints);
691 // read info for each joint
692 for (int i = 0; i < num_joints; i++) {
693 joints[i].load(tfile, joints);
697 funpackf(tfile, "Bi", &num_muscles);
700 muscles.resize(num_muscles);
702 // for each muscle...
703 for (int i = 0; i < num_muscles; i++) {
704 muscles[i].load(tfile, model[0].vertexNum, joints);
707 // read forwardjoints (?)
708 for (j = 0; j < 3; j++) {
709 funpackf(tfile, "Bi", &forwardjoints[j]);
711 // read lowforwardjoints (?)
712 for (j = 0; j < 3; j++) {
713 funpackf(tfile, "Bi", &lowforwardjoints[j]);
717 for (j = 0; j < num_muscles; j++) {
718 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
719 for (int k = 0; k < num_models; k++) {
720 if (muscles[j].vertices[i] < model[k].vertexNum) {
721 model[k].owner[muscles[j].vertices[i]] = j;
727 // calculate some stuff
729 for (int i = 0; i < num_muscles; i++) {
730 FindRotationMuscle(i, -1);
732 // this seems to use opengl purely for matrix calculations
733 for (int k = 0; k < num_models; k++) {
734 for (int i = 0; i < model[k].vertexNum; i++) {
735 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
736 glMatrixMode(GL_MODELVIEW);
739 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
740 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
741 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
742 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
743 glGetFloatv(GL_MODELVIEW_MATRIX, M);
744 model[k].vertex[i].x = M[12] * 1;
745 model[k].vertex[i].y = M[13] * 1;
746 model[k].vertex[i].z = M[14] * 1;
749 model[k].CalculateNormals(0);
755 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
757 // skip joints section
759 fseek(tfile, sizeof(num_joints), SEEK_CUR);
760 for (int i = 0; i < num_joints; i++) {
774 fseek(tfile, lSize, SEEK_CUR);
778 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
780 for (int i = 0; i < num_muscles; i++) {
782 lSize = sizeof(float)
788 fseek(tfile, lSize, SEEK_CUR);
790 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
793 lSize = 1; //sizeof(bool);
794 fseek ( tfile, lSize, SEEK_CUR);
796 fseek ( tfile, lSize, SEEK_CUR);
797 fseek ( tfile, lSize, SEEK_CUR);
800 for (j = 0; j < num_muscles; j++) {
801 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
802 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
803 modellow.owner[muscles[j].verticeslow[i]] = j;
808 // use opengl for its matrix math
809 for (int i = 0; i < modellow.vertexNum; i++) {
810 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
811 glMatrixMode(GL_MODELVIEW);
814 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
815 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
816 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
817 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
818 glGetFloatv(GL_MODELVIEW_MATRIX, M);
819 modellow.vertex[i].x = M[12];
820 modellow.vertex[i].y = M[13];
821 modellow.vertex[i].z = M[14];
825 modellow.CalculateNormals(0);
830 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
833 fseek(tfile, sizeof(num_joints), SEEK_CUR);
835 for (int i = 0; i < num_joints; i++) {
849 fseek(tfile, lSize, SEEK_CUR);
853 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
855 for (int i = 0; i < num_muscles; i++) {
857 lSize = sizeof(float)
863 fseek(tfile, lSize, SEEK_CUR);
865 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
868 lSize = 1; //sizeof(bool);
869 fseek ( tfile, lSize, SEEK_CUR);
871 fseek ( tfile, lSize, SEEK_CUR);
872 fseek ( tfile, lSize, SEEK_CUR);
877 for (j = 0; j < num_muscles; j++) {
878 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
879 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
880 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
885 // use opengl for its matrix math
886 for (int i = 0; i < modelclothes.vertexNum; i++) {
887 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
888 glMatrixMode(GL_MODELVIEW);
891 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
892 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
893 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
894 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
895 glGetFloatv(GL_MODELVIEW_MATRIX, M);
896 modelclothes.vertex[i].x = M[12];
897 modelclothes.vertex[i].y = M[13];
898 modelclothes.vertex[i].z = M[14];
902 modelclothes.CalculateNormals(0);
906 for (int i = 0; i < num_joints; i++) {
907 for (j = 0; j < num_joints; j++) {
908 if (joints[i].label == j)