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 /**> HEADER FILES <**/
23 #include "Animation/Skeleton.h"
24 #include "openal_wrapper.h"
25 #include "Animation/Animation.h"
26 #include "Utils/Folders.h"
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;
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 objects.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 (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 (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 (tutoriallevel != 1 || 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 (tutoriallevel != 1 || 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 (tutoriallevel != 1 || 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 //objects.model[k].MakeDecal(breakdecal, DoRotation(temp - objects.position[k], 0, -objects.yaw[k], 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 < objects.numobjects && k >= 0)
330 if (objects.possible[k]) {
331 friction = objects.friction[k];
332 XYZ start = joints[i].realoldposition;
333 XYZ end = joints[i].position * (*scale) + *coords;
334 whichhit = objects.model[k].LineCheckPossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]);
335 if (whichhit != -1) {
336 if (joints[i].label == groin && !joints[i].locked && joints[i].delay <= 0) {
337 joints[i].locked = 1;
339 if (tutoriallevel != 1 || 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 (tutoriallevel != 1 || id == 0) {
349 emit_sound_at(landsound2, joints[i].position * (*scale) + *coords, 128.);
353 terrainnormal = DoRotation(objects.model[k].facenormals[whichhit], 0, objects.yaw[k], 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 (tutoriallevel != 1 || id == 0)
362 if (findLengthfast(&bounceness) > 4000 && breaking) {
363 objects.model[k].MakeDecal(breakdecal, DoRotation(temp - objects.position[k], 0, -objects.yaw[k], 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 (objects.type[k] == treetrunktype) {
373 objects.rotx[k] += joints[i].velocity.x * multiplier * .4;
374 objects.roty[k] += joints[i].velocity.z * multiplier * .4;
375 objects.rotx[k + 1] += joints[i].velocity.x * multiplier * .4;
376 objects.roty[k + 1] += 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 (objects.possible[k]) {
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 = objects.model[k].LineCheckSlidePossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]);
421 if (whichhit != -1) {
422 joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale);
423 for (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)
480 for (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);
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 i, 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 (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 ((tutoriallevel == 1) && (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 (tutoriallevel == 1 && id != 0)
661 drawmodellow.UniformTexCoords();
662 if (tutoriallevel == 1 && 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 (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 (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 (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;
726 // calculate some stuff
728 for (i = 0; i < num_muscles; i++) {
729 FindRotationMuscle(i, -1);
731 // this seems to use opengl purely for matrix calculations
732 for (int k = 0; k < num_models; k++) {
733 for (i = 0; i < model[k].vertexNum; i++) {
734 model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
735 glMatrixMode(GL_MODELVIEW);
738 glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
739 glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
740 glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
741 glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
742 glGetFloatv(GL_MODELVIEW_MATRIX, M);
743 model[k].vertex[i].x = M[12] * 1;
744 model[k].vertex[i].y = M[13] * 1;
745 model[k].vertex[i].z = M[14] * 1;
748 model[k].CalculateNormals(0);
754 tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
756 // skip joints section
758 fseek(tfile, sizeof(num_joints), SEEK_CUR);
759 for (i = 0; i < num_joints; i++) {
773 fseek(tfile, lSize, SEEK_CUR);
777 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
779 for (i = 0; i < num_muscles; i++) {
781 lSize = sizeof(float)
787 fseek(tfile, lSize, SEEK_CUR);
789 muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
792 lSize = 1; //sizeof(bool);
793 fseek ( tfile, lSize, SEEK_CUR);
795 fseek ( tfile, lSize, SEEK_CUR);
796 fseek ( tfile, lSize, SEEK_CUR);
799 for (j = 0; j < num_muscles; j++) {
800 for (i = 0; i < muscles[j].verticeslow.size(); i++) {
801 if (muscles[j].verticeslow[i] < modellow.vertexNum)
802 modellow.owner[muscles[j].verticeslow[i]] = j;
806 // use opengl for its matrix math
807 for (i = 0; i < modellow.vertexNum; i++) {
808 modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
809 glMatrixMode(GL_MODELVIEW);
812 glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
813 glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
814 glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
815 glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
816 glGetFloatv(GL_MODELVIEW_MATRIX, M);
817 modellow.vertex[i].x = M[12];
818 modellow.vertex[i].y = M[13];
819 modellow.vertex[i].z = M[14];
823 modellow.CalculateNormals(0);
828 tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
831 fseek(tfile, sizeof(num_joints), SEEK_CUR);
833 for (i = 0; i < num_joints; i++) {
847 fseek(tfile, lSize, SEEK_CUR);
851 fseek(tfile, sizeof(num_muscles), SEEK_CUR);
853 for (i = 0; i < num_muscles; i++) {
855 lSize = sizeof(float)
861 fseek(tfile, lSize, SEEK_CUR);
863 muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
866 lSize = 1; //sizeof(bool);
867 fseek ( tfile, lSize, SEEK_CUR);
869 fseek ( tfile, lSize, SEEK_CUR);
870 fseek ( tfile, lSize, SEEK_CUR);
875 for (j = 0; j < num_muscles; j++) {
876 for (i = 0; i < muscles[j].verticesclothes.size(); i++) {
877 if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum)
878 modelclothes.owner[muscles[j].verticesclothes[i]] = j;
882 // use opengl for its matrix math
883 for (i = 0; i < modelclothes.vertexNum; i++) {
884 modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
885 glMatrixMode(GL_MODELVIEW);
888 glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
889 glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
890 glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
891 glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
892 glGetFloatv(GL_MODELVIEW_MATRIX, M);
893 modelclothes.vertex[i].x = M[12];
894 modelclothes.vertex[i].y = M[13];
895 modelclothes.vertex[i].z = M[14];
899 modelclothes.CalculateNormals(0);
903 for (i = 0; i < num_joints; i++) {
904 for (j = 0; j < num_joints; j++) {
905 if (joints[i].label == j)