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 "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;
173 jointPos(rightankle) += lowforward * .025;
175 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
177 jointVel(rightankle) += lowforward * .25;
178 jointPos(righthip) += lowforward * .025;
180 jointVel(righthip) += lowforward * .025 / multiplier / 4;
182 jointVel(righthip) += lowforward * .025;
183 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
187 // left leg constraints?
188 if (!joint(leftknee).locked && !joint(lefthip).locked) {
189 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
190 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
191 jointPos(leftknee) -= lowforward * .05;
193 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
195 jointVel(leftknee) -= lowforward * .05;
196 jointPos(leftankle) += lowforward * .025;
198 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
200 jointVel(leftankle) += lowforward * .25;
201 jointPos(lefthip) += lowforward * .025;
203 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
205 jointVel(lefthip) += lowforward * .025;
206 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
210 for (i = 0; i < joints.size(); i++) {
211 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320)
212 joints[i].locked = 0;
213 if (spinny && findLengthfast(&joints[i].velocity) > 600)
214 joints[i].locked = 0;
215 if (joints[i].delay > 0) {
217 for (unsigned j = 0; j < joints.size(); j++) {
218 if (joints[j].locked)
222 joints[i].delay -= multiplier * 3;
226 for (i = 0; i < muscles.size(); i++) {
228 muscles[i].DoConstraint(spinny);
232 for (i = 0; i < joints.size(); i++) {
236 if (joints[i].position.y * (*scale) + coords->y < terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel) {
239 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
240 joints[i].locked = 1;
242 if (!Tutorial::active || id == 0) {
243 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
248 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
249 joints[i].locked = 1;
251 if (!Tutorial::active || id == 0) {
252 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
256 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
257 ReflectVector(&joints[i].velocity, &terrainnormal);
258 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
259 if (!joints[i].locked)
260 damage += findLengthfast(&bounceness) / 4000;
261 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness))
263 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
264 joints[i].velocity -= bounceness;
265 if (1 - friction * frictionness > 0)
266 joints[i].velocity *= 1 - friction * frictionness;
268 joints[i].velocity = 0;
270 if (!Tutorial::active || id == 0)
271 if (findLengthfast(&bounceness) > 8000 && breaking) {
272 // FIXME: this crashes because k is not initialized!
273 // to reproduce, type 'wolfie' in console and play a while
274 // I'll just comment it out for now
275 //Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
276 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
280 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
282 addEnvSound(*coords, 64);
285 if (findLengthfast(&bounceness) > 2500) {
286 Normalise(&bounceness);
287 bounceness = bounceness * 50;
290 joints[i].velocity += bounceness * elasticity;
292 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
294 joints[i].velocity = joints[i].oldvelocity;
297 if (joints[i].locked == 0)
298 if (findLengthfast(&joints[i].velocity) < 1)
299 joints[i].locked = 1;
301 if (environment == snowyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
302 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
303 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .7);
305 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
306 } else if (environment == desertenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
307 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
308 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);
311 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
312 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
313 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);
314 } else if (findLengthfast(&bounceness) > 500)
315 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
317 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
321 for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) {
322 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
323 if (k < Object::objects.size()) {
324 if (Object::objects[k]->possible) {
325 friction = Object::objects[k]->friction;
326 XYZ start = joints[i].realoldposition;
327 XYZ end = joints[i].position * (*scale) + *coords;
328 whichhit = Object::objects[k]->model.LineCheckPossible(&start, &end, &temp, &Object::objects[k]->position, &Object::objects[k]->yaw);
329 if (whichhit != -1) {
330 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
331 joints[i].locked = 1;
333 if (!Tutorial::active || id == 0) {
334 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
339 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
340 joints[i].locked = 1;
342 if (!Tutorial::active || id == 0) {
343 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
347 terrainnormal = DoRotation(Object::objects[k]->model.Triangles[whichhit].facenormal, 0, Object::objects[k]->yaw, 0) * -1;
348 if (terrainnormal.y > .8)
350 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
351 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
353 joints[i].velocity = joints[i].oldvelocity;
355 if (!Tutorial::active || id == 0)
356 if (findLengthfast(&bounceness) > 4000 && breaking) {
357 Object::objects[k]->model.MakeDecal(breakdecal, DoRotation(temp - Object::objects[k]->position, 0, -Object::objects[k]->yaw, 0), .4, .5, Random() % 360);
358 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
362 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
364 addEnvSound(*coords, 64);
366 if (Object::objects[k]->type == treetrunktype) {
367 Object::objects[k]->rotx += joints[i].velocity.x * multiplier * .4;
368 Object::objects[k]->roty += joints[i].velocity.z * multiplier * .4;
369 Object::objects[k + 1]->rotx += joints[i].velocity.x * multiplier * .4;
370 Object::objects[k + 1]->roty += joints[i].velocity.z * multiplier * .4;
372 if (!joints[i].locked)
373 damage += findLengthfast(&bounceness) / 2500;
374 ReflectVector(&joints[i].velocity, &terrainnormal);
375 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
376 joints[i].velocity -= bounceness;
377 if (1 - friction * frictionness > 0)
378 joints[i].velocity *= 1 - friction * frictionness;
380 joints[i].velocity = 0;
381 if (findLengthfast(&bounceness) > 2500) {
382 Normalise(&bounceness);
383 bounceness = bounceness * 50;
385 joints[i].velocity += bounceness * elasticity;
387 if (!joints[i].locked)
388 if (findLengthfast(&joints[i].velocity) < 1) {
389 joints[i].locked = 1;
391 if (findLengthfast(&bounceness) > 500)
392 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
393 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
400 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
403 multiplier = tempmult;
405 for (unsigned int m = 0; m < terrain.patchobjects[whichpatchx][whichpatchz].size(); m++) {
406 unsigned int k = terrain.patchobjects[whichpatchx][whichpatchz][m];
407 if (Object::objects[k]->possible) {
408 for (i = 0; i < 26; i++) {
409 //Make this less stupid
410 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
411 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
412 whichhit = Object::objects[k]->model.LineCheckSlidePossible(&start, &end, &Object::objects[k]->position, &Object::objects[k]->yaw);
413 if (whichhit != -1) {
414 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
415 for (unsigned j = 0; j < muscles.size(); j++) {
416 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]))
417 muscles[j].DoConstraint(spinny);
424 for (i = 0; i < joints.size(); i++) {
425 switch (joints[i].label) {
441 joints[i].position.y += groundlevel;
443 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)
445 if (joints[i].locked) {
454 for (i = 0; i < muscles.size(); i++) {
455 if (muscles[i].type == boneconnect)
456 muscles[i].DoConstraint(0);
464 * applies gravity to the skeleton
467 * Person/Person::DoStuff
469 void Skeleton::DoGravity(float* scale)
471 for (unsigned i = 0; i < joints.size(); i++) {
474 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
475 (lowforward.y > -.1) ||
476 (joints[i].mass < 5)) &&
477 (((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
479 joints[i].velocity.y += gravity * multiplier / (*scale);
485 * set muscles[which].rotate1
489 * special case if animation == hanganim
491 void Skeleton::FindRotationMuscle(int which, int animation)
496 p1 = muscles[which].parent1->position;
497 p2 = muscles[which].parent2->position;
498 dist = findDistance(&p1, &p2);
499 if (p1.y - p2.y <= dist)
500 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
501 if (p1.y - p2.y > dist)
502 muscles[which].rotate2 = asin(1.f);
503 muscles[which].rotate2 *= 360.0 / 6.2831853;
507 dist = findDistance(&p1, &p2);
508 if (p1.z - p2.z <= dist)
509 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
510 if (p1.z - p2.z > dist)
511 muscles[which].rotate1 = acos(1.f);
512 muscles[which].rotate1 *= 360.0 / 6.2831853;
514 muscles[which].rotate1 = 360 - muscles[which].rotate1;
515 if (!isnormal(muscles[which].rotate1))
516 muscles[which].rotate1 = 0;
517 if (!isnormal(muscles[which].rotate2))
518 muscles[which].rotate2 = 0;
520 const int label1 = muscles[which].parent1->label;
521 const int label2 = muscles[which].parent2->label;
524 fwd = specialforward[0];
530 fwd = specialforward[1];
536 fwd = specialforward[2];
542 fwd = specialforward[3];
548 fwd = specialforward[4];
551 if (muscles[which].parent1->lower)
558 if (animation == hanganim) {
559 if (label1 == righthand || label2 == righthand) {
563 if (label1 == lefthand || label2 == lefthand) {
570 if (label1 == rightfoot || label2 == rightfoot) {
573 if (label1 == leftfoot || label2 == leftfoot) {
578 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
579 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
581 fwd /= findLength(&fwd);
582 if (fwd.z <= 1 && fwd.z >= -1)
583 muscles[which].rotate3 = acos(0 - fwd.z);
585 muscles[which].rotate3 = acos(-1.f);
586 muscles[which].rotate3 *= 360.0 / 6.2831853;
588 muscles[which].rotate3 = 360 - muscles[which].rotate3;
589 if (!isnormal(muscles[which].rotate3))
590 muscles[which].rotate3 = 0;
595 * takes filenames for three skeleton files and various models
597 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
598 const std::string& modelfilename, const std::string& model2filename,
599 const std::string& model3filename, const std::string& model4filename,
600 const std::string& model5filename, const std::string& model6filename,
601 const std::string& model7filename, const std::string& modellowfilename,
602 const std::string& modelclothesfilename, bool clothes)
607 int j, num_joints, num_muscles;
613 // load various models
614 // rotate, scale, do normals, do texcoords for each as needed
616 model[0].loadnotex(modelfilename);
617 model[1].loadnotex(model2filename);
618 model[2].loadnotex(model3filename);
619 model[3].loadnotex(model4filename);
620 model[4].loadnotex(model5filename);
621 model[5].loadnotex(model6filename);
622 model[6].loadnotex(model7filename);
624 for (int i = 0; i < num_models; i++) {
625 model[i].Rotate(180, 0, 0);
626 model[i].Scale(.04, .04, .04);
627 model[i].CalculateNormals(0);
630 drawmodel.load(modelfilename);
631 drawmodel.Rotate(180, 0, 0);
632 drawmodel.Scale(.04, .04, .04);
633 drawmodel.FlipTexCoords();
634 if ((Tutorial::active) && (id != 0)) {
635 drawmodel.UniformTexCoords();
636 drawmodel.ScaleTexCoords(0.1);
638 drawmodel.CalculateNormals(0);
640 modellow.loadnotex(modellowfilename);
641 modellow.Rotate(180, 0, 0);
642 modellow.Scale(.04, .04, .04);
643 modellow.CalculateNormals(0);
645 drawmodellow.load(modellowfilename);
646 drawmodellow.Rotate(180, 0, 0);
647 drawmodellow.Scale(.04, .04, .04);
648 drawmodellow.FlipTexCoords();
649 if (Tutorial::active && id != 0)
650 drawmodellow.UniformTexCoords();
651 if (Tutorial::active && id != 0)
652 drawmodellow.ScaleTexCoords(0.1);
653 drawmodellow.CalculateNormals(0);
656 modelclothes.loadnotex(modelclothesfilename);
657 modelclothes.Rotate(180, 0, 0);
658 modelclothes.Scale(.041, .04, .041);
659 modelclothes.CalculateNormals(0);
661 drawmodelclothes.load(modelclothesfilename);
662 drawmodelclothes.Rotate(180, 0, 0);
663 drawmodelclothes.Scale(.04, .04, .04);
664 drawmodelclothes.FlipTexCoords();
665 drawmodelclothes.CalculateNormals(0);
668 // FIXME: three similar blocks follow, one for each of:
669 // filename, lowfilename, clothesfilename
673 tfile = Folders::openMandatoryFile(Folders::getResourcePath(filename), "rb");
676 funpackf(tfile, "Bi", &num_joints);
678 joints.resize(num_joints);
680 // read info for each joint
681 for (int i = 0; i < num_joints; i++) {
682 joints[i].load(tfile, joints);
686 funpackf(tfile, "Bi", &num_muscles);
689 muscles.resize(num_muscles);
691 // for each muscle...
692 for (int i = 0; i < num_muscles; i++) {
693 muscles[i].load(tfile, model[0].vertexNum, joints);
696 // read forwardjoints (?)
697 for (j = 0; j < 3; j++) {
698 funpackf(tfile, "Bi", &forwardjoints[j]);
700 // read lowforwardjoints (?)
701 for (j = 0; j < 3; j++) {
702 funpackf(tfile, "Bi", &lowforwardjoints[j]);
706 for (j = 0; j < num_muscles; j++) {
707 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
708 for (int k = 0; k < num_models; k++) {
709 if (muscles[j].vertices[i] < model[k].vertexNum) {
710 model[k].owner[muscles[j].vertices[i]] = j;
716 // calculate some stuff
718 for (int i = 0; i < num_muscles; i++) {
719 FindRotationMuscle(i, -1);
721 // this seems to use opengl purely for matrix calculations
722 for (int k = 0; k < num_models; k++) {
723 for (int i = 0; i < model[k].vertexNum; i++) {
724 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
725 glMatrixMode(GL_MODELVIEW);
728 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
729 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
730 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
731 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
732 glGetFloatv(GL_MODELVIEW_MATRIX, M);
733 model[k].vertex[i].x = M[12] * 1;
734 model[k].vertex[i].y = M[13] * 1;
735 model[k].vertex[i].z = M[14] * 1;
738 model[k].CalculateNormals(0);
744 tfile = Folders::openMandatoryFile(Folders::getResourcePath(lowfilename), "rb");
746 // skip joints section
748 fseek(tfile, sizeof(num_joints), SEEK_CUR);
749 for (int i = 0; i < num_joints; i++) {
751 lSize = sizeof(XYZ) + sizeof(float) + sizeof(float) + 1 //sizeof(bool)
753 + sizeof(int) + 1 //sizeof(bool)
755 + sizeof(int) + sizeof(int) + 1 //sizeof(bool)
757 fseek(tfile, lSize, SEEK_CUR);
761 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
763 for (int i = 0; i < num_muscles; i++) {
765 lSize = sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(int);
766 fseek(tfile, lSize, SEEK_CUR);
768 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
771 lSize = 1; //sizeof(bool);
772 fseek(tfile, lSize, SEEK_CUR);
774 fseek(tfile, lSize, SEEK_CUR);
775 fseek(tfile, lSize, SEEK_CUR);
778 for (j = 0; j < num_muscles; j++) {
779 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
780 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
781 modellow.owner[muscles[j].verticeslow[i]] = j;
786 // use opengl for its matrix math
787 for (int i = 0; i < modellow.vertexNum; i++) {
788 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
789 glMatrixMode(GL_MODELVIEW);
792 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
793 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
794 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
795 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
796 glGetFloatv(GL_MODELVIEW_MATRIX, M);
797 modellow.vertex[i].x = M[12];
798 modellow.vertex[i].y = M[13];
799 modellow.vertex[i].z = M[14];
803 modellow.CalculateNormals(0);
808 tfile = Folders::openMandatoryFile(Folders::getResourcePath(clothesfilename), "rb");
811 fseek(tfile, sizeof(num_joints), SEEK_CUR);
813 for (int i = 0; i < num_joints; i++) {
815 lSize = sizeof(XYZ) + sizeof(float) + sizeof(float) + 1 //sizeof(bool)
817 + sizeof(int) + 1 //sizeof(bool)
819 + sizeof(int) + sizeof(int) + 1 //sizeof(bool)
821 fseek(tfile, lSize, SEEK_CUR);
825 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
827 for (int i = 0; i < num_muscles; i++) {
829 lSize = sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(float) + sizeof(int);
830 fseek(tfile, lSize, SEEK_CUR);
832 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
835 lSize = 1; //sizeof(bool);
836 fseek(tfile, lSize, SEEK_CUR);
838 fseek(tfile, lSize, SEEK_CUR);
839 fseek(tfile, lSize, SEEK_CUR);
844 for (j = 0; j < num_muscles; j++) {
845 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
846 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
847 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
852 // use opengl for its matrix math
853 for (int i = 0; i < modelclothes.vertexNum; i++) {
854 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
855 glMatrixMode(GL_MODELVIEW);
858 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
859 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
860 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
861 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
862 glGetFloatv(GL_MODELVIEW_MATRIX, M);
863 modelclothes.vertex[i].x = M[12];
864 modelclothes.vertex[i].y = M[13];
865 modelclothes.vertex[i].z = M[14];
869 modelclothes.CalculateNormals(0);
873 for (int i = 0; i < num_joints; i++) {
874 for (j = 0; j < num_joints; j++) {
875 if (joints[i].label == j)