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"
28 extern float multiplier;
30 extern Terrain terrain;
31 extern Objects objects;
32 extern int environment;
33 extern float camerashake;
36 extern int tutoriallevel;
38 extern int whichjointstartarray[26];
39 extern int whichjointendarray[26];
41 extern bool visibleloading;
43 Skeleton::Skeleton() :
58 memset(forwardjoints, 0, sizeof(forwardjoints));
59 memset(lowforwardjoints, 0, sizeof(lowforwardjoints));
60 memset(jointlabels, 0, sizeof(jointlabels));
61 memset(skinText, 0, sizeof(skinText));
65 * sets forward, lowforward, specialforward[]
69 * Person/Person::DoAnimations
70 * Person/Person::DrawSkeleton
72 void Skeleton::FindForwards()
74 //Find forward vectors
75 CrossProduct(joints[forwardjoints[1]].position - joints[forwardjoints[0]].position, joints[forwardjoints[2]].position - joints[forwardjoints[0]].position, &forward);
78 CrossProduct(joints[lowforwardjoints[1]].position - joints[lowforwardjoints[0]].position, joints[lowforwardjoints[2]].position - joints[lowforwardjoints[0]].position, &lowforward);
79 Normalise(&lowforward);
82 specialforward[0] = forward;
84 specialforward[1] = jointPos(rightshoulder) + jointPos(rightwrist);
85 specialforward[1] = jointPos(rightelbow) - specialforward[1] / 2;
86 specialforward[1] += forward * .4;
87 Normalise(&specialforward[1]);
88 specialforward[2] = jointPos(leftshoulder) + jointPos(leftwrist);
89 specialforward[2] = jointPos(leftelbow) - specialforward[2] / 2;
90 specialforward[2] += forward * .4;
91 Normalise(&specialforward[2]);
93 specialforward[3] = jointPos(righthip) + jointPos(rightankle);
94 specialforward[3] = specialforward[3] / 2 - jointPos(rightknee);
95 specialforward[3] += lowforward * .4;
96 Normalise(&specialforward[3]);
97 specialforward[4] = jointPos(lefthip) + jointPos(leftankle);
98 specialforward[4] = specialforward[4] / 2 - jointPos(leftknee);
99 specialforward[4] += lowforward * .4;
100 Normalise(&specialforward[4]);
107 * Person/Person::RagDoll
108 * Person/Person::DoStuff
111 float Skeleton::DoConstraints(XYZ *coords, float *scale)
113 float friction = 1.5;
114 const float elasticity = .3;
116 const int numrepeats = 3;
117 float groundlevel = .15;
127 float damage = 0; // eventually returned from function
128 bool breaking = false;
131 freetime += multiplier;
133 whichpatchx = coords->x / (terrain.size / subdivision * terrain.scale);
134 whichpatchz = coords->z / (terrain.size / subdivision * terrain.scale);
136 terrainlight = *coords;
137 objects.SphereCheckPossible(&terrainlight, 1);
140 for (i = 0; i < joints.size(); i++) {
141 joints[i].position = joints[i].position + joints[i].velocity * multiplier;
143 switch (joints[i].label) {
160 joints[i].position.y -= groundlevel;
161 joints[i].oldvelocity = joints[i].velocity;
164 float tempmult = multiplier;
165 //multiplier/=numrepeats;
167 for (int j = 0; j < numrepeats; j++) {
169 // right leg constraints?
170 if (!joint(rightknee).locked && !joint(righthip).locked) {
171 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
172 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(righthip), &jointPos(rightankle), &jointPos(rightknee), &r)) {
173 jointPos(rightknee) -= lowforward * .05;
175 jointVel(rightknee) -= lowforward * .05 / multiplier / 4;
177 jointVel(rightknee) -= lowforward * .05;
178 jointPos(rightankle) += lowforward * .025;
180 jointVel(rightankle) += lowforward * .025 / multiplier / 4;
182 jointVel(rightankle) += lowforward * .25;
183 jointPos(righthip) += lowforward * .025;
185 jointVel(righthip) += lowforward * .025 / multiplier / 4;
187 jointVel(righthip) += lowforward * .025;
188 temp = jointPos(rightknee) - (jointPos(righthip) + jointPos(rightankle)) / 2;
192 // left leg constraints?
193 if (!joint(leftknee).locked && !joint(lefthip).locked) {
194 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
195 while (normaldotproduct(temp, lowforward) > -.1 && !sphere_line_intersection(&jointPos(lefthip), &jointPos(leftankle), &jointPos(leftknee), &r)) {
196 jointPos(leftknee) -= lowforward * .05;
198 jointVel(leftknee) -= lowforward * .05 / multiplier / 4;
200 jointVel(leftknee) -= lowforward * .05;
201 jointPos(leftankle) += lowforward * .025;
203 jointVel(leftankle) += lowforward * .025 / multiplier / 4;
205 jointVel(leftankle) += lowforward * .25;
206 jointPos(lefthip) += lowforward * .025;
208 jointVel(lefthip) += lowforward * .025 / multiplier / 4;
210 jointVel(lefthip) += lowforward * .025;
211 temp = jointPos(leftknee) - (jointPos(lefthip) + jointPos(leftankle)) / 2;
215 for (i = 0; i < joints.size(); i++) {
216 if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320)
217 joints[i].locked = 0;
218 if (spinny && findLengthfast(&joints[i].velocity) > 600)
219 joints[i].locked = 0;
220 if (joints[i].delay > 0) {
222 for (unsigned j = 0; j < joints.size(); j++) {
223 if (joints[j].locked)
227 joints[i].delay -= multiplier * 3;
231 for (i = 0; i < muscles.size(); i++) {
233 muscles[i].DoConstraint(spinny);
236 for (i = 0; i < joints.size(); i++) {
240 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) {
243 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
244 joints[i].locked = 1;
246 if (tutoriallevel != 1 || id == 0) {
247 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
252 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
253 joints[i].locked = 1;
255 if (tutoriallevel != 1 || id == 0) {
256 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
260 terrainnormal = terrain.getNormal(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
261 ReflectVector(&joints[i].velocity, &terrainnormal);
262 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
263 if (!joints[i].locked)
264 damage += findLengthfast(&bounceness) / 4000;
265 if (findLengthfast(&joints[i].velocity) < findLengthfast(&bounceness))
267 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
268 joints[i].velocity -= bounceness;
269 if (1 - friction * frictionness > 0)
270 joints[i].velocity *= 1 - friction * frictionness;
272 joints[i].velocity = 0;
274 if (tutoriallevel != 1 || id == 0)
275 if (findLengthfast(&bounceness) > 8000 && breaking) {
276 // FIXME: this crashes because k is not initialized!
277 // to reproduce, type 'wolfie' in console and play a while
278 // I'll just comment it out for now
279 //objects.model[k].MakeDecal(breakdecal, DoRotation(temp - objects.position[k], 0, -objects.yaw[k], 0), .4, .5, Random() % 360);
280 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
284 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
286 addEnvSound(*coords, 64);
289 if (findLengthfast(&bounceness) > 2500) {
290 Normalise(&bounceness);
291 bounceness = bounceness * 50;
294 joints[i].velocity += bounceness * elasticity;
296 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
298 joints[i].velocity = joints[i].oldvelocity;
302 if (joints[i].locked == 0)
303 if (findLengthfast(&joints[i].velocity) < 1)
304 joints[i].locked = 1;
306 if (environment == snowyenvironment && 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, terrainlight.y, terrainlight.z, .5, .7);
310 terrain.MakeDecal(bodyprintdecal, joints[i].position * (*scale) + *coords, .4, .4, 0);
311 } else if (environment == desertenvironment && 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 * 190 / 255, terrainlight.y * 170 / 255, terrainlight.z * 108 / 255, .5, .7);
316 else if (environment == grassyenvironment && findLengthfast(&bounceness) > 500 && terrain.getOpacity(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) < .2) {
317 terrainlight = terrain.getLighting(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z);
318 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);
319 } else if (findLengthfast(&bounceness) > 500)
320 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, terrainlight.x, terrainlight.y, terrainlight.z, .5, .2);
323 joints[i].position.y = (terrain.getHeight(joints[i].position.x * (*scale) + coords->x, joints[i].position.z * (*scale) + coords->z) + groundlevel - coords->y) / (*scale);
327 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
328 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
329 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
330 if (k < objects.numobjects && k >= 0)
331 if (objects.possible[k]) {
332 friction = objects.friction[k];
333 XYZ start = joints[i].realoldposition;
334 XYZ end = joints[i].position * (*scale) + *coords;
335 whichhit = objects.model[k].LineCheckPossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]);
336 if (whichhit != -1) {
337 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
338 joints[i].locked = 1;
340 if (tutoriallevel != 1 || id == 0) {
341 emit_sound_at(landsound1, joints[i].position * (*scale) + *coords, 128.);
346 if (joints[i].label == head && !joints[i].locked && joints[i].delay <= 0) {
347 joints[i].locked = 1;
349 if (tutoriallevel != 1 || id == 0) {
350 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
354 terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 0) * -1;
355 if (terrainnormal.y > .8)
357 bounceness = terrainnormal * findLength(&joints[i].velocity) * (abs(normaldotproduct(joints[i].velocity, terrainnormal)));
358 if (findLengthfast(&joints[i].velocity) > findLengthfast(&joints[i].oldvelocity)) {
360 joints[i].velocity = joints[i].oldvelocity;
362 if (tutoriallevel != 1 || id == 0)
363 if (findLengthfast(&bounceness) > 4000 && breaking) {
364 objects.model[k].MakeDecal(breakdecal, DoRotation(temp - objects.position[k], 0, -objects.yaw[k], 0), .4, .5, Random() % 360);
365 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, 4, .2);
369 emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
371 addEnvSound(*coords, 64);
373 if (objects.type[k] == treetrunktype) {
374 objects.rotx[k] += joints[i].velocity.x * multiplier * .4;
375 objects.roty[k] += joints[i].velocity.z * multiplier * .4;
376 objects.rotx[k + 1] += joints[i].velocity.x * multiplier * .4;
377 objects.roty[k + 1] += joints[i].velocity.z * multiplier * .4;
379 if (!joints[i].locked)
380 damage += findLengthfast(&bounceness) / 2500;
381 ReflectVector(&joints[i].velocity, &terrainnormal);
382 frictionness = abs(normaldotproduct(joints[i].velocity, terrainnormal));
383 joints[i].velocity -= bounceness;
384 if (1 - friction * frictionness > 0)
385 joints[i].velocity *= 1 - friction * frictionness;
387 joints[i].velocity = 0;
388 if (findLengthfast(&bounceness) > 2500) {
389 Normalise(&bounceness);
390 bounceness = bounceness * 50;
392 joints[i].velocity += bounceness * elasticity;
395 if (!joints[i].locked)
396 if (findLengthfast(&joints[i].velocity) < 1) {
397 joints[i].locked = 1;
399 if (findLengthfast(&bounceness) > 500)
400 Sprite::MakeSprite(cloudsprite, joints[i].position * (*scale) + *coords, joints[i].velocity * .06, 1, 1, 1, .5, .2);
401 joints[i].position = (temp - *coords) / (*scale) + terrainnormal * .005;
407 joints[i].realoldposition = joints[i].position * (*scale) + *coords;
410 multiplier = tempmult;
413 if (terrain.patchobjectnum[whichpatchx][whichpatchz])
414 for (m = 0; m < terrain.patchobjectnum[whichpatchx][whichpatchz]; m++) {
415 k = terrain.patchobjects[whichpatchx][whichpatchz][m];
416 if (objects.possible[k]) {
417 for (i = 0; i < 26; i++) {
418 //Make this less stupid
419 XYZ start = joints[jointlabels[whichjointstartarray[i]]].position * (*scale) + *coords;
420 XYZ end = joints[jointlabels[whichjointendarray[i]]].position * (*scale) + *coords;
421 whichhit = objects.model[k].LineCheckSlidePossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]);
422 if (whichhit != -1) {
423 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
424 for (unsigned j = 0; j < muscles.size(); j++) {
425 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]))
426 muscles[j].DoConstraint(spinny);
433 for (i = 0; i < joints.size(); i++) {
434 switch (joints[i].label) {
450 joints[i].position.y += groundlevel;
452 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)
454 if (joints[i].locked) {
463 for (i = 0; i < muscles.size(); i++) {
464 if (muscles[i].type == boneconnect)
465 muscles[i].DoConstraint(0);
473 * applies gravity to the skeleton
476 * Person/Person::DoStuff
478 void Skeleton::DoGravity(float *scale)
480 for (unsigned i = 0; i < joints.size(); i++) {
483 ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
484 (lowforward.y > -.1) ||
487 ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
491 joints[i].velocity.y += gravity * multiplier / (*scale);
497 * set muscles[which].rotate1
501 * special case if animation == hanganim
503 void Skeleton::FindRotationMuscle(int which, int animation)
508 p1 = muscles[which].parent1->position;
509 p2 = muscles[which].parent2->position;
510 dist = findDistance(&p1, &p2);
511 if (p1.y - p2.y <= dist)
512 muscles[which].rotate2 = asin((p1.y - p2.y) / dist);
513 if (p1.y - p2.y > dist)
514 muscles[which].rotate2 = asin(1.f);
515 muscles[which].rotate2 *= 360.0 / 6.2831853;
519 dist = findDistance(&p1, &p2);
520 if (p1.z - p2.z <= dist)
521 muscles[which].rotate1 = acos((p1.z - p2.z) / dist);
522 if (p1.z - p2.z > dist)
523 muscles[which].rotate1 = acos(1.f);
524 muscles[which].rotate1 *= 360.0 / 6.2831853;
526 muscles[which].rotate1 = 360 - muscles[which].rotate1;
527 if (!isnormal(muscles[which].rotate1))
528 muscles[which].rotate1 = 0;
529 if (!isnormal(muscles[which].rotate2))
530 muscles[which].rotate2 = 0;
532 const int label1 = muscles[which].parent1->label;
533 const int label2 = muscles[which].parent2->label;
536 fwd = specialforward[0];
542 fwd = specialforward[1];
548 fwd = specialforward[2];
554 fwd = specialforward[3];
560 fwd = specialforward[4];
563 if (muscles[which].parent1->lower)
570 if (animation == hanganim) {
571 if (label1 == righthand || label2 == righthand) {
575 if (label1 == lefthand || label2 == lefthand) {
582 if (label1 == rightfoot || label2 == rightfoot) {
585 if (label1 == leftfoot || label2 == leftfoot) {
590 fwd = DoRotation(fwd, 0, muscles[which].rotate1 - 90, 0);
591 fwd = DoRotation(fwd, 0, 0, muscles[which].rotate2 - 90);
593 fwd /= findLength(&fwd);
594 if (fwd.z <= 1 && fwd.z >= -1)
595 muscles[which].rotate3 = acos(0 - fwd.z);
597 muscles[which].rotate3 = acos(-1.f);
598 muscles[which].rotate3 *= 360.0 / 6.2831853;
600 muscles[which].rotate3 = 360 - muscles[which].rotate3;
601 if (!isnormal(muscles[which].rotate3))
602 muscles[which].rotate3 = 0;
607 * takes filenames for three skeleton files and various models
609 void Skeleton::Load(const std::string& filename, const std::string& lowfilename, const std::string& clothesfilename,
610 const std::string& modelfilename, const std::string& model2filename,
611 const std::string& model3filename, const std::string& model4filename,
612 const std::string& model5filename, const std::string& model6filename,
613 const std::string& model7filename, const std::string& modellowfilename,
614 const std::string& modelclothesfilename, bool clothes)
619 int j, num_joints, num_muscles;
625 // load various models
626 // rotate, scale, do normals, do texcoords for each as needed
628 model[0].loadnotex(modelfilename);
629 model[1].loadnotex(model2filename);
630 model[2].loadnotex(model3filename);
631 model[3].loadnotex(model4filename);
632 model[4].loadnotex(model5filename);
633 model[5].loadnotex(model6filename);
634 model[6].loadnotex(model7filename);
636 for (int i = 0; i < num_models; i++) {
637 model[i].Rotate(180, 0, 0);
638 model[i].Scale(.04, .04, .04);
639 model[i].CalculateNormals(0);
642 drawmodel.load(modelfilename, 0);
643 drawmodel.Rotate(180, 0, 0);
644 drawmodel.Scale(.04, .04, .04);
645 drawmodel.FlipTexCoords();
646 if ((tutoriallevel == 1) && (id != 0)) {
647 drawmodel.UniformTexCoords();
648 drawmodel.ScaleTexCoords(0.1);
650 drawmodel.CalculateNormals(0);
652 modellow.loadnotex(modellowfilename);
653 modellow.Rotate(180, 0, 0);
654 modellow.Scale(.04, .04, .04);
655 modellow.CalculateNormals(0);
657 drawmodellow.load(modellowfilename, 0);
658 drawmodellow.Rotate(180, 0, 0);
659 drawmodellow.Scale(.04, .04, .04);
660 drawmodellow.FlipTexCoords();
661 if (tutoriallevel == 1 && id != 0)
662 drawmodellow.UniformTexCoords();
663 if (tutoriallevel == 1 && id != 0)
664 drawmodellow.ScaleTexCoords(0.1);
665 drawmodellow.CalculateNormals(0);
668 modelclothes.loadnotex(modelclothesfilename);
669 modelclothes.Rotate(180, 0, 0);
670 modelclothes.Scale(.041, .04, .041);
671 modelclothes.CalculateNormals(0);
673 drawmodelclothes.load(modelclothesfilename, 0);
674 drawmodelclothes.Rotate(180, 0, 0);
675 drawmodelclothes.Scale(.04, .04, .04);
676 drawmodelclothes.FlipTexCoords();
677 drawmodelclothes.CalculateNormals(0);
680 // FIXME: three similar blocks follow, one for each of:
681 // filename, lowfilename, clothesfilename
685 tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
688 funpackf(tfile, "Bi", &num_joints);
690 joints.resize(num_joints);
692 // read info for each joint
693 for (int i = 0; i < num_joints; i++) {
694 joints[i].load(tfile, joints);
698 funpackf(tfile, "Bi", &num_muscles);
701 muscles.resize(num_muscles);
703 // for each muscle...
704 for (int i = 0; i < num_muscles; i++) {
705 muscles[i].load(tfile, model[0].vertexNum, joints);
708 // read forwardjoints (?)
709 for (j = 0; j < 3; j++) {
710 funpackf(tfile, "Bi", &forwardjoints[j]);
712 // read lowforwardjoints (?)
713 for (j = 0; j < 3; j++) {
714 funpackf(tfile, "Bi", &lowforwardjoints[j]);
718 for (j = 0; j < num_muscles; j++) {
719 for (unsigned i = 0; i < muscles[j].vertices.size(); i++) {
720 for (int k = 0; k < num_models; k++) {
721 if (muscles[j].vertices[i] < model[k].vertexNum) {
722 model[k].owner[muscles[j].vertices[i]] = j;
728 // calculate some stuff
730 for (int i = 0; i < num_muscles; i++) {
731 FindRotationMuscle(i, -1);
733 // this seems to use opengl purely for matrix calculations
734 for (int k = 0; k < num_models; k++) {
735 for (int i = 0; i < model[k].vertexNum; i++) {
736 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
737 glMatrixMode(GL_MODELVIEW);
740 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
741 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
742 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
743 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
744 glGetFloatv(GL_MODELVIEW_MATRIX, M);
745 model[k].vertex[i].x = M[12] * 1;
746 model[k].vertex[i].y = M[13] * 1;
747 model[k].vertex[i].z = M[14] * 1;
750 model[k].CalculateNormals(0);
756 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
758 // skip joints section
760 fseek(tfile, sizeof(num_joints), SEEK_CUR);
761 for (int i = 0; i < num_joints; i++) {
775 fseek(tfile, lSize, SEEK_CUR);
779 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
781 for (int i = 0; i < num_muscles; i++) {
783 lSize = sizeof(float)
789 fseek(tfile, lSize, SEEK_CUR);
791 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
794 lSize = 1; //sizeof(bool);
795 fseek ( tfile, lSize, SEEK_CUR);
797 fseek ( tfile, lSize, SEEK_CUR);
798 fseek ( tfile, lSize, SEEK_CUR);
801 for (j = 0; j < num_muscles; j++) {
802 for (unsigned i = 0; i < muscles[j].verticeslow.size(); i++) {
803 if (muscles[j].verticeslow[i] < modellow.vertexNum) {
804 modellow.owner[muscles[j].verticeslow[i]] = j;
809 // use opengl for its matrix math
810 for (int i = 0; i < modellow.vertexNum; i++) {
811 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
812 glMatrixMode(GL_MODELVIEW);
815 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
816 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
817 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
818 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
819 glGetFloatv(GL_MODELVIEW_MATRIX, M);
820 modellow.vertex[i].x = M[12];
821 modellow.vertex[i].y = M[13];
822 modellow.vertex[i].z = M[14];
826 modellow.CalculateNormals(0);
831 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
834 fseek(tfile, sizeof(num_joints), SEEK_CUR);
836 for (int i = 0; i < num_joints; i++) {
850 fseek(tfile, lSize, SEEK_CUR);
854 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
856 for (int i = 0; i < num_muscles; i++) {
858 lSize = sizeof(float)
864 fseek(tfile, lSize, SEEK_CUR);
866 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
869 lSize = 1; //sizeof(bool);
870 fseek ( tfile, lSize, SEEK_CUR);
872 fseek ( tfile, lSize, SEEK_CUR);
873 fseek ( tfile, lSize, SEEK_CUR);
878 for (j = 0; j < num_muscles; j++) {
879 for (unsigned i = 0; i < muscles[j].verticesclothes.size(); i++) {
880 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum) {
881 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
886 // use opengl for its matrix math
887 for (int i = 0; i < modelclothes.vertexNum; i++) {
888 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
889 glMatrixMode(GL_MODELVIEW);
892 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
893 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
894 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
895 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
896 glGetFloatv(GL_MODELVIEW_MATRIX, M);
897 modelclothes.vertex[i].x = M[12];
898 modelclothes.vertex[i].y = M[13];
899 modelclothes.vertex[i].z = M[14];
903 modelclothes.CalculateNormals(0);
907 for (int i = 0; i < num_joints; i++) {
908 for (j = 0; j < num_joints; j++) {
909 if (joints[i].label == j)