2 Copyright (C) 2003, 2010 - Wolfire Games
3 Copyright (C) 2010-2017 - 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 "Tutorial.hpp"
27 #include "Utils/Folders.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];
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;
174 jointPos(rightankle) += lowforward * .025;
176 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
178 jointVel(rightankle) += lowforward * .25;
180 jointPos(righthip) += lowforward * .025;
182 jointVel(righthip) += lowforward * .025 / multiplier / 4;
184 jointVel(righthip) += lowforward * .025;
186 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
190 // left leg constraints?
191 if (!joint(leftknee).locked && !joint(lefthip).locked) {
192 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
193 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
194 jointPos(leftknee) -= lowforward * .05;
196 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
198 jointVel(leftknee) -= lowforward * .05;
200 jointPos(leftankle) += lowforward * .025;
202 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
204 jointVel(leftankle) += lowforward * .25;
206 jointPos(lefthip) += lowforward * .025;
208 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
210 jointVel(lefthip) += lowforward * .025;
212 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
216 for (i = 0; i < joints.size(); i++) {
217 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320) {
218 joints[i].locked = 0;
220 if (spinny && findLengthfast(&joints[i].velocity) > 600) {
221 joints[i].locked = 0;
223 if (joints[i].delay > 0) {
225 for (unsigned j = 0; j < joints.size(); j++) {
226 if (joints[j].locked) {
231 joints[i].delay -= multiplier * 3;
236 for (i = 0; i < muscles.size(); i++) {
238 muscles[i].DoConstraint(spinny);
242 for (i = 0; i < joints.size(); i++) {
246 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) {
249 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
250 joints[i].locked = 1;
252 if (!Tutorial::active || id == 0) {
253 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
258 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
259 joints[i].locked = 1;
261 if (!Tutorial::active || id == 0) {
262 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
266 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
267 ReflectVector(&joints[i].velocity, &terrainnormal);
268 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
269 if (!joints[i].locked) {
270 damage += findLengthfast(&bounceness) / 4000;
272 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness)) {
275 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
276 joints[i].velocity -= bounceness;
277 if (1 - friction * frictionness > 0) {
278 joints[i].velocity *= 1 - friction * frictionness;
280 joints[i].velocity = 0;
283 if (!Tutorial::active || id == 0) {
284 if (findLengthfast(&bounceness) > 8000 && breaking) {
285 // FIXME: this crashes because k is not initialized!
286 // to reproduce, type 'wolfie' in console and play a while
287 // I'll just comment it out for now
288 //Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
289 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
293 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
295 addEnvSound(*coords, 64);
299 if (findLengthfast(&bounceness) > 2500) {
300 Normalise(&bounceness);
301 bounceness = bounceness * 50;
304 joints[i].velocity += bounceness * elasticity;
306 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
308 joints[i].velocity = joints[i].oldvelocity;
311 if (joints[i].locked == 0) {
312 if (findLengthfast(&joints[i].velocity) < 1) {
313 joints[i].locked = 1;
317 if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
318 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
319 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7);
321 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
323 } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
324 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
325 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);
328 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
329 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
330 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);
331 } else if (findLengthfast(&bounceness) > 500) {
332 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
335 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
336 if (longdead > 100) {
340 for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) {
341 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
342 if (k < Object::objects.size()) {
343 if (Object::objects[k]->possible) {
344 friction = Object::objects[k]->friction;
345 XYZ start = joints[i].realoldposition;
346 XYZ end = joints[i].position * (*scale) + *coords;
347 whichhit = Object::objects[k]->model.LineCheckPossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
348 if (whichhit != -1) {
349 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
350 joints[i].locked = 1;
352 if (!Tutorial::active || id == 0) {
353 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
358 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
359 joints[i].locked = 1;
361 if (!Tutorial::active || id == 0) {
362 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
366 terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
367 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 (!Tutorial::active || id == 0) {
376 if (findLengthfast(&bounceness) > 4000 && breaking) {
377 Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 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);
387 if (Object::objects[k]->type == treetrunktype) {
388 Object::objects[k]->rotx += joints[i].velocity.x * multiplier * .4;
389 Object::objects[k]->roty += joints[i].velocity.z * multiplier * .4;
390 Object::objects[k + 1]->rotx += joints[i].velocity.x * multiplier * .4;
391 Object::objects[k + 1]->roty += joints[i].velocity.z * multiplier * .4;
393 if (!joints[i].locked) {
394 damage += findLengthfast(&bounceness) / 2500;
396 ReflectVector(&joints[i].velocity, &terrainnormal);
397 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
398 joints[i].velocity -= bounceness;
399 if (1 - friction * frictionness > 0) {
400 joints[i].velocity *= 1 - friction * frictionness;
402 joints[i].velocity = 0;
404 if (findLengthfast(&bounceness) > 2500) {
405 Normalise(&bounceness);
406 bounceness = bounceness * 50;
408 joints[i].velocity += bounceness * elasticity;
410 if (!joints[i].locked) {
411 if (findLengthfast(&joints[i].velocity) < 1) {
412 joints[i].locked = 1;
415 if (findLengthfast(&bounceness) > 500) {
416 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
418 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
419 if (longdead > 100) {
426 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
429 multiplier = tempmult;
431 for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) {
432 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
433 if (Object::objects[k]->possible) {
434 for (i = 0; i < 26; i++) {
435 //Make this less stupid
436 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
437 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
438 whichhit = Object::objects[k]->model.LineCheckSlidePossible(&start, &end, &Object::objects[k]->position, &Object::objects[k]->yaw);
439 if (whichhit != -1) {
440 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
441 for (unsigned j = 0; j < muscles.size(); j++) {
442 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])) {
443 muscles[j].DoConstraint(spinny);
451 for (i = 0; i < joints.size(); i++) {
452 switch (joints[i].label) {
468 joints[i].position.y += groundlevel;
470 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) {
473 if (joints[i].locked) {
482 for (i = 0; i < muscles.size(); i++) {
483 if (muscles[i].type == boneconnect) {
484 muscles[i].DoConstraint(0);
493 * applies gravity to the skeleton
496 * Person/Person::DoStuff
498 void Skeleton::DoGravity(float* scale)
500 for (unsigned i = 0; i < joints.size(); i++) {
503 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
504 (lowforward.y > -.1) ||
505 (joints[i].mass < 5)) &&
506 (((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
508 joints[i].velocity.y += gravity * multiplier / (*scale);
514 * set muscles[which].rotate1
518 * special case if animation == hanganim
520 void Skeleton::FindRotationMuscle(int which, int animation)
525 p1 = muscles[which].parent1->position;
526 p2 = muscles[which].parent2->position;
527 dist = findDistance(&p1, &p2);
528 if (p1.y - p2.y <= dist) {
529 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
531 if (p1.y - p2.y > dist) {
532 muscles[which].rotate2 = asin(1.f);
534 muscles[which].rotate2 *= 360.0 / 6.2831853;
538 dist = findDistance(&p1, &p2);
539 if (p1.z - p2.z <= dist) {
540 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
542 if (p1.z - p2.z > dist) {
543 muscles[which].rotate1 = acos(1.f);
545 muscles[which].rotate1 *= 360.0 / 6.2831853;
547 muscles[which].rotate1 = 360 - muscles[which].rotate1;
549 if (!isnormal(muscles[which].rotate1)) {
550 muscles[which].rotate1 = 0;
552 if (!isnormal(muscles[which].rotate2)) {
553 muscles[which].rotate2 = 0;
556 const int label1 = muscles[which].parent1->label;
557 const int label2 = muscles[which].parent2->label;
560 fwd = specialforward[0];
566 fwd = specialforward[1];
572 fwd = specialforward[2];
578 fwd = specialforward[3];
584 fwd = specialforward[4];
587 if (muscles[which].parent1->lower) {
595 if (animation == hanganim) {
596 if (label1 == righthand || label2 == righthand) {
600 if (label1 == lefthand || label2 == lefthand) {
607 if (label1 == rightfoot || label2 == rightfoot) {
610 if (label1 == leftfoot || label2 == leftfoot) {
615 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
616 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
618 fwd /= findLength(&fwd);
619 if (fwd.z <= 1 && fwd.z >= -1) {
620 muscles[which].rotate3 = acos(0 - fwd.z);
622 muscles[which].rotate3 = acos(-1.f);
624 muscles[which].rotate3 *= 360.0 / 6.2831853;
626 muscles[which].rotate3 = 360 - muscles[which].rotate3;
628 if (!isnormal(muscles[which].rotate3)) {
629 muscles[which].rotate3 = 0;
635 * takes filenames for three skeleton files and various models
637 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
638 const std::string& modelfilename, const std::string& model2filename,
639 const std::string& model3filename, const std::string& model4filename,
640 const std::string& model5filename, const std::string& model6filename,
641 const std::string& model7filename, const std::string& modellowfilename,
642 const std::string& modelclothesfilename, bool clothes)
647 int j, num_joints, num_muscles;
653 // load various models
654 // rotate, scale, do normals, do texcoords for each as needed
656 model[0].loadnotex(modelfilename);
657 model[1].loadnotex(model2filename);
658 model[2].loadnotex(model3filename);
659 model[3].loadnotex(model4filename);
660 model[4].loadnotex(model5filename);
661 model[5].loadnotex(model6filename);
662 model[6].loadnotex(model7filename);
664 for (int i = 0; i < num_models; i++) {
665 model[i].Rotate(180, 0, 0);
666 model[i].Scale(.04, .04, .04);
667 model[i].CalculateNormals(0);
670 drawmodel.load(modelfilename);
671 drawmodel.Rotate(180, 0, 0);
672 drawmodel.Scale(.04, .04, .04);
673 drawmodel.FlipTexCoords();
674 if ((Tutorial::active) && (id != 0)) {
675 drawmodel.UniformTexCoords();
676 drawmodel.ScaleTexCoords(0.1);
678 drawmodel.CalculateNormals(0);
680 modellow.loadnotex(modellowfilename);
681 modellow.Rotate(180, 0, 0);
682 modellow.Scale(.04, .04, .04);
683 modellow.CalculateNormals(0);
685 drawmodellow.load(modellowfilename);
686 drawmodellow.Rotate(180, 0, 0);
687 drawmodellow.Scale(.04, .04, .04);
688 drawmodellow.FlipTexCoords();
689 if (Tutorial::active && id != 0) {
690 drawmodellow.UniformTexCoords();
692 if (Tutorial::active && id != 0) {
693 drawmodellow.ScaleTexCoords(0.1);
695 drawmodellow.CalculateNormals(0);
698 modelclothes.loadnotex(modelclothesfilename);
699 modelclothes.Rotate(180, 0, 0);
700 modelclothes.Scale(.041, .04, .041);
701 modelclothes.CalculateNormals(0);
703 drawmodelclothes.load(modelclothesfilename);
704 drawmodelclothes.Rotate(180, 0, 0);
705 drawmodelclothes.Scale(.04, .04, .04);
706 drawmodelclothes.FlipTexCoords();
707 drawmodelclothes.CalculateNormals(0);
710 // FIXME: three similar blocks follow, one for each of:
711 // filename, lowfilename, clothesfilename
715 tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb");
718 funpackf(tfile, "Bi", &num_joints);
721 joints.resize(num_joints);
723 // read info for each joint
724 for (int i = 0; i < num_joints; i++) {
725 joints[i].load(tfile, joints);
729 funpackf(tfile, "Bi", &num_muscles);
733 muscles.resize(num_muscles);
735 // for each muscle...
736 for (int i = 0; i < num_muscles; i++) {
737 muscles[i].load(tfile, model[0].vertexNum, joints);
740 // read forwardjoints (?)
741 for (j = 0; j < 3; j++) {
742 funpackf(tfile, "Bi", &forwardjoints[j]);
744 // read lowforwardjoints (?)
745 for (j = 0; j < 3; j++) {
746 funpackf(tfile, "Bi", &lowforwardjoints[j]);
750 for (j = 0; j < num_muscles; j++) {
751 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
752 for (int k = 0; k < num_models; k++) {
753 if (muscles[j].vertices[i] < model[k].vertexNum) {
754 model[k].owner[muscles[j].vertices[i]] = j;
760 // calculate some stuff
762 for (int i = 0; i < num_muscles; i++) {
763 FindRotationMuscle(i, -1);
765 // this seems to use opengl purely for matrix calculations
766 for (int k = 0; k < num_models; k++) {
767 for (int i = 0; i < model[k].vertexNum; i++) {
768 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
769 glMatrixMode(GL_MODELVIEW);
772 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
773 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
774 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
775 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
776 glGetFloatv(GL_MODELVIEW_MATRIX, M);
777 model[k].vertex[i].x = M[12] * 1;
778 model[k].vertex[i].y = M[13] * 1;
779 model[k].vertex[i].z = M[14] * 1;
782 model[k].CalculateNormals(0);
788 tfile = Folders::openMandatoryFile(Folders::getResourcePath(lowfilename), "rb");
790 // skip joints section
792 fseek(tfile, sizeof(num_joints), SEEK_CUR);
793 for (int i = 0; i < num_joints; i++) {
795 lSize = sizeof(XYZ) + sizeof(float) + sizeof(float) + 1 //sizeof(bool)
797 + sizeof(int) + 1 //sizeof(bool)
799 + sizeof(int) + sizeof(int) + 1 //sizeof(bool)
801 fseek(tfile, lSize, SEEK_CUR);
805 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
807 for (int i = 0; i < num_muscles; i++) {
809 lSize = sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(int);
810 fseek(tfile, lSize, SEEK_CUR);
812 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
815 lSize = 1; //sizeof(bool);
816 fseek(tfile, lSize, SEEK_CUR);
818 fseek(tfile, lSize, SEEK_CUR);
819 fseek(tfile, lSize, SEEK_CUR);
822 for (j = 0; j < num_muscles; j++) {
823 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
824 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
825 modellow.owner[muscles[j].verticeslow[i]] = j;
830 // use opengl for its matrix math
831 for (int i = 0; i < modellow.vertexNum; i++) {
832 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
833 glMatrixMode(GL_MODELVIEW);
836 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
837 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
838 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
839 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
840 glGetFloatv(GL_MODELVIEW_MATRIX, M);
841 modellow.vertex[i].x = M[12];
842 modellow.vertex[i].y = M[13];
843 modellow.vertex[i].z = M[14];
847 modellow.CalculateNormals(0);
852 tfile = Folders::openMandatoryFile(Folders::getResourcePath(clothesfilename), "rb");
855 fseek(tfile, sizeof(num_joints), SEEK_CUR);
857 for (int i = 0; i < num_joints; i++) {
859 lSize = sizeof(XYZ) + sizeof(float) + sizeof(float) + 1 //sizeof(bool)
861 + sizeof(int) + 1 //sizeof(bool)
863 + sizeof(int) + sizeof(int) + 1 //sizeof(bool)
865 fseek(tfile, lSize, SEEK_CUR);
869 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
871 for (int i = 0; i < num_muscles; i++) {
873 lSize = sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(int);
874 fseek(tfile, lSize, SEEK_CUR);
876 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
879 lSize = 1; //sizeof(bool);
880 fseek(tfile, lSize, SEEK_CUR);
882 fseek(tfile, lSize, SEEK_CUR);
883 fseek(tfile, lSize, SEEK_CUR);
888 for (j = 0; j < num_muscles; j++) {
889 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
890 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
891 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
896 // use opengl for its matrix math
897 for (int 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 (int i = 0; i < num_joints; i++) {
918 for (j = 0; j < num_joints; j++) {
919 if (joints[i].label == j) {