- static int i,j,joints;
- for(i=0;i<numframes;i++){
- for(j=0;j<joints;j++){
- position[j][i]=0;
- }
- }
-}
-
-void Skeleton::Load(const char *filename, const char *lowfilename, const char *clothesfilename,
- const char *modelfilename, const char *model2filename,
- const char *model3filename, const char *model4filename,
- const char *model5filename, const char *model6filename,
- const char *model7filename, const char *modellowfilename,
- const char *modelclothesfilename, bool aclothes)
-{
- static GLfloat M[16];
- static int parentID;
- static FILE *tfile;
- static float lSize;
- static int i,j,tempmuscle;
- int newload;
- int edit;
-
- LOGFUNC;
-
-
- newload=0;
-
- num_models=7;
-
- clothes=aclothes;
-
- for(i=0;i<num_models;i++){
- if(i==0)model[i].loadnotex(modelfilename);
- if(i==1)model[i].loadnotex(model2filename);
- if(i==2)model[i].loadnotex(model3filename);
- if(i==3)model[i].loadnotex(model4filename);
- if(i==4)model[i].loadnotex(model5filename);
- if(i==5)model[i].loadnotex(model6filename);
- if(i==6)model[i].loadnotex(model7filename);
- model[i].Rotate(180,0,0);
- model[i].Scale(.04,.04,.04);
- model[i].CalculateNormals(0);
- }
-
- drawmodel.load(modelfilename,0);
- drawmodel.Rotate(180,0,0);
- drawmodel.Scale(.04,.04,.04);
- drawmodel.FlipTexCoords();
- if(tutoriallevel==1&&id!=0)drawmodel.UniformTexCoords();
- if(tutoriallevel==1&&id!=0)drawmodel.ScaleTexCoords(0.1);
- drawmodel.CalculateNormals(0);
-
- modellow.loadnotex(modellowfilename);
- modellow.Rotate(180,0,0);
- modellow.Scale(.04,.04,.04);
- modellow.CalculateNormals(0);
-
- drawmodellow.load(modellowfilename,0);
- drawmodellow.Rotate(180,0,0);
- drawmodellow.Scale(.04,.04,.04);
- drawmodellow.FlipTexCoords();
- if(tutoriallevel==1&&id!=0)drawmodellow.UniformTexCoords();
- if(tutoriallevel==1&&id!=0)drawmodellow.ScaleTexCoords(0.1);
- drawmodellow.CalculateNormals(0);
-
- if(clothes){
- modelclothes.loadnotex(modelclothesfilename);
- modelclothes.Rotate(180,0,0);
- modelclothes.Scale(.041,.04,.041);
- modelclothes.CalculateNormals(0);
-
- drawmodelclothes.load(modelclothesfilename,0);
- drawmodelclothes.Rotate(180,0,0);
- drawmodelclothes.Scale(.04,.04,.04);
- drawmodelclothes.FlipTexCoords();
- drawmodelclothes.CalculateNormals(0);
- }
-
- tfile=fopen( ConvertFileName(filename), "rb" );
- if(1){
- funpackf(tfile, "Bi", &num_joints);
- //joints.resize(num_joints);
- if(joints) delete [] joints; //dealloc2(joints);
- joints=(Joint*)new Joint[num_joints]; //malloc(sizeof(Joint)*num_joints);
-
- for(i=0;i<num_joints;i++){
- funpackf(tfile, "Bf Bf Bf Bf Bf", &joints[i].position.x, &joints[i].position.y, &joints[i].position.z, &joints[i].length,&joints[i].mass);
- funpackf(tfile, "Bb Bb", &joints[i].hasparent,&joints[i].locked);
- funpackf(tfile, "Bi", &joints[i].modelnum);
- funpackf(tfile, "Bb Bb", &joints[i].visible,&joints[i].sametwist);
- funpackf(tfile, "Bi Bi", &joints[i].label,&joints[i].hasgun);
- funpackf(tfile, "Bb", &joints[i].lower);
- funpackf(tfile, "Bi", &parentID);
- if(joints[i].hasparent)joints[i].parent=&joints[parentID];
- joints[i].velocity=0;
- joints[i].oldposition=joints[i].position;
- }
- tempmuscle=num_muscles;
- funpackf(tfile, "Bi", &num_muscles);
- //muscles.clear();
- if(muscles) delete [] muscles; //dealloc2(muscles);
- muscles=(Muscle*)new Muscle[num_muscles]; //malloc(sizeof(Muscle)*num_muscles);
- newload=1;
- for(i=0;i<num_muscles;i++){
- tempmuscle=muscles[i].numvertices;
- funpackf(tfile, "Bf Bf Bf Bf Bf Bi Bi", &muscles[i].length, &muscles[i].targetlength,&muscles[i].minlength, &muscles[i].maxlength,&muscles[i].strength,&muscles[i].type,&muscles[i].numvertices);
- //muscles[i].vertices.clear();
- //muscles[i].vertices.resize(muscles[i].numvertices);
- //if(muscles[i].vertices)dealloc2(muscles[i].vertices);
- muscles[i].vertices=(int*)malloc(sizeof(int)*muscles[i].numvertices);
-
- edit=0;
- for(j=0;j<muscles[i].numvertices-edit;j++){
- funpackf(tfile, "Bi", &muscles[i].vertices[j+edit]);
- if(muscles[i].vertices[j+edit]>=model[0].vertexNum){
- muscles[i].numvertices--;
- edit--;
- }
- }
- funpackf(tfile, "Bb Bi", &muscles[i].visible, &parentID);
- muscles[i].parent1=&joints[parentID];
- funpackf(tfile, "Bi", &parentID);
- muscles[i].parent2=&joints[parentID];
- }
- for(j=0;j<3;j++){
- funpackf(tfile, "Bi", &forwardjoints[j]);
- }
- for(j=0;j<3;j++){
- funpackf(tfile, "Bi", &lowforwardjoints[j]);
- }
- for(j=0;j<num_muscles;j++){
- for(i=0;i<muscles[j].numvertices;i++){
- for(int k=0;k<num_models;k++){
- if(muscles[j].numvertices&&muscles[j].vertices[i]<model[k].vertexNum)model[k].owner[muscles[j].vertices[i]]=j;
- }
- }
- }
- FindForwards();
- for(i=0;i<num_joints;i++){
- joints[i].startpos=joints[i].position;
- }
- for(i=0;i<num_muscles;i++){
- FindRotationMuscle(i,-1);
- }
- for(int k=0;k<num_models;k++){
- for(i=0;i<model[k].vertexNum;i++){
- model[k].vertex[i]=model[k].vertex[i]-(muscles[model[k].owner[i]].parent1->position+muscles[model[k].owner[i]].parent2->position)/2;
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- glPushMatrix();
- glLoadIdentity();
- glRotatef(muscles[model[k].owner[i]].rotate3,0,1,0);
- glRotatef(muscles[model[k].owner[i]].rotate2-90,0,0,1);
- glRotatef(muscles[model[k].owner[i]].rotate1-90,0,1,0);
- glTranslatef(model[k].vertex[i].x,model[k].vertex[i].y,model[k].vertex[i].z);
- glGetFloatv(GL_MODELVIEW_MATRIX,M);
- model[k].vertex[i].x=M[12]*1;
- model[k].vertex[i].y=M[13]*1;
- model[k].vertex[i].z=M[14]*1;
- glPopMatrix();
- }
- model[k].CalculateNormals(0);
- }
- }
- fclose(tfile);
-
- tfile=fopen( ConvertFileName(lowfilename), "rb" );
- if(1){
- lSize=sizeof(num_joints);
- fseek ( tfile, lSize, SEEK_CUR);
- //joints = new Joint[num_joints];
- //jointlabels = new int[num_joints];
- for(i=0;i<num_joints;i++){
- lSize=sizeof(XYZ);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- if(joints[i].hasparent)joints[i].parent=&joints[parentID];
- joints[i].velocity=0;
- joints[i].oldposition=joints[i].position;
- }
- funpackf(tfile, "Bi", &num_muscles);
- //muscles = new Muscle[num_muscles];
- for(i=0;i<num_muscles;i++){
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- tempmuscle=muscles[i].numverticeslow;
- funpackf(tfile, "Bi", &muscles[i].numverticeslow);
- if(muscles[i].numverticeslow){
- //muscles[i].verticeslow.clear();
- //muscles[i].verticeslow.resize(muscles[i].numverticeslow);
- //if(muscles[i].verticeslow)dealloc2(muscles[i].verticeslow);
- muscles[i].verticeslow=(int*)malloc(sizeof(int)*muscles[i].numverticeslow);
- edit=0;
- for(j=0;j<muscles[i].numverticeslow-edit;j++){
- funpackf(tfile, "Bi", &muscles[i].verticeslow[j+edit]);
- if(muscles[i].verticeslow[j+edit]>=modellow.vertexNum){
- muscles[i].numverticeslow--;
- edit--;
- }
- }
-
-
- }
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- fseek ( tfile, lSize, SEEK_CUR);
- }
- lSize=sizeof(int);
- for(j=0;j<num_muscles;j++){
- for(i=0;i<muscles[j].numverticeslow;i++){
- if(muscles[j].numverticeslow&&muscles[j].verticeslow[i]<modellow.vertexNum)modellow.owner[muscles[j].verticeslow[i]]=j;
- }
- }
- /*FindForwards();
- for(i=0;i<num_joints;i++){
- joints[i].startpos=joints[i].position;
- }
- for(i=0;i<num_muscles;i++){
- FindRotationMuscle(i,-1);
- }*/
- for(i=0;i<modellow.vertexNum;i++){
- modellow.vertex[i]=modellow.vertex[i]-(muscles[modellow.owner[i]].parent1->position+muscles[modellow.owner[i]].parent2->position)/2;
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- glPushMatrix();
- glLoadIdentity();
- glRotatef(muscles[modellow.owner[i]].rotate3,0,1,0);
- glRotatef(muscles[modellow.owner[i]].rotate2-90,0,0,1);
- glRotatef(muscles[modellow.owner[i]].rotate1-90,0,1,0);
- glTranslatef(modellow.vertex[i].x,modellow.vertex[i].y,modellow.vertex[i].z);
- glGetFloatv(GL_MODELVIEW_MATRIX,M);
- modellow.vertex[i].x=M[12];
- modellow.vertex[i].y=M[13];
- modellow.vertex[i].z=M[14];
- glPopMatrix();
- }
- modellow.CalculateNormals(0);
- }
-
- if(clothes){
- tfile=fopen( ConvertFileName(clothesfilename), "rb" );
- lSize=sizeof(num_joints);
- fseek ( tfile, lSize, SEEK_CUR);
- //joints = new Joint[num_joints];
- //jointlabels = new int[num_joints];
- for(i=0;i<num_joints;i++){
- lSize=sizeof(XYZ);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- if(joints[i].hasparent)joints[i].parent=&joints[parentID];
- joints[i].velocity=0;
- joints[i].oldposition=joints[i].position;
- }
- funpackf(tfile, "Bi", &num_muscles);
- //muscles = new Muscle[num_muscles];
- for(i=0;i<num_muscles;i++){
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(float);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- tempmuscle=muscles[i].numverticesclothes;
- funpackf(tfile, "Bi", &muscles[i].numverticesclothes);
- if(muscles[i].numverticesclothes){
- //muscles[i].verticesclothes.clear();
- //muscles[i].verticesclothes.resize(muscles[i].numverticesclothes);
- //if(muscles[i].verticesclothes)dealloc2(muscles[i].verticesclothes);
- muscles[i].verticesclothes=(int*)malloc(sizeof(int)*muscles[i].numverticesclothes);
- edit=0;
- for(j=0;j<muscles[i].numverticesclothes-edit;j++){
- funpackf(tfile, "Bi", &muscles[i].verticesclothes[j+edit]);
- if(muscles[i].verticesclothes[j+edit]>=modelclothes.vertexNum){
- muscles[i].numverticesclothes--;
- edit--;
- }
- }
- }
- lSize=1;//sizeof(bool);
- fseek ( tfile, lSize, SEEK_CUR);
- lSize=sizeof(int);
- fseek ( tfile, lSize, SEEK_CUR);
- fseek ( tfile, lSize, SEEK_CUR);
- }
- lSize=sizeof(int);
- for(j=0;j<num_muscles;j++){
- for(i=0;i<muscles[j].numverticesclothes;i++){
- if(muscles[j].numverticesclothes&&muscles[j].verticesclothes[i]<modelclothes.vertexNum)modelclothes.owner[muscles[j].verticesclothes[i]]=j;
- }
- }
- /*FindForwards();
- for(i=0;i<num_joints;i++){
- joints[i].startpos=joints[i].position;
- }
- for(i=0;i<num_muscles;i++){
- FindRotationMuscle(i,-1);
- }*/
- for(i=0;i<modelclothes.vertexNum;i++){
- modelclothes.vertex[i]=modelclothes.vertex[i]-(muscles[modelclothes.owner[i]].parent1->position+muscles[modelclothes.owner[i]].parent2->position)/2;
- glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
- glPushMatrix();
- glLoadIdentity();
- glRotatef(muscles[modelclothes.owner[i]].rotate3,0,1,0);
- glRotatef(muscles[modelclothes.owner[i]].rotate2-90,0,0,1);
- glRotatef(muscles[modelclothes.owner[i]].rotate1-90,0,1,0);
- glTranslatef(modelclothes.vertex[i].x,modelclothes.vertex[i].y,modelclothes.vertex[i].z);
- glGetFloatv(GL_MODELVIEW_MATRIX,M);
- modelclothes.vertex[i].x=M[12];
- modelclothes.vertex[i].y=M[13];
- modelclothes.vertex[i].z=M[14];
- glPopMatrix();
- }
- modelclothes.CalculateNormals(0);
- }
- fclose(tfile);
-
- for(i=0;i<num_joints;i++){
- for(j=0;j<num_joints;j++){
- if(joints[i].label==j)jointlabels[j]=i;
- }
- }
-
- free=0;
+ GLfloat M[16];
+ int parentID;
+ FILE *tfile;
+ float lSize;
+ int i, j, tempmuscle;
+
+ int newload;
+ int edit;
+
+ LOGFUNC;
+
+
+ newload = 0;
+
+ num_models = 7;
+
+ // load various models
+ // rotate, scale, do normals, do texcoords for each as needed
+
+ model[0].loadnotex(modelfilename);
+ model[1].loadnotex(model2filename);
+ model[2].loadnotex(model3filename);
+ model[3].loadnotex(model4filename);
+ model[4].loadnotex(model5filename);
+ model[5].loadnotex(model6filename);
+ model[6].loadnotex(model7filename);
+
+ for (i = 0; i < num_models; i++) {
+ model[i].Rotate(180, 0, 0);
+ model[i].Scale(.04, .04, .04);
+ model[i].CalculateNormals(0);
+ }
+
+ drawmodel.load(modelfilename, 0);
+ drawmodel.Rotate(180, 0, 0);
+ drawmodel.Scale(.04, .04, .04);
+ drawmodel.FlipTexCoords();
+ if (tutoriallevel == 1 && id != 0)
+ drawmodel.UniformTexCoords();
+ if (tutoriallevel == 1 && id != 0)
+ drawmodel.ScaleTexCoords(0.1);
+ drawmodel.CalculateNormals(0);
+
+ modellow.loadnotex(modellowfilename);
+ modellow.Rotate(180, 0, 0);
+ modellow.Scale(.04, .04, .04);
+ modellow.CalculateNormals(0);
+
+ drawmodellow.load(modellowfilename, 0);
+ drawmodellow.Rotate(180, 0, 0);
+ drawmodellow.Scale(.04, .04, .04);
+ drawmodellow.FlipTexCoords();
+ if (tutoriallevel == 1 && id != 0)
+ drawmodellow.UniformTexCoords();
+ if (tutoriallevel == 1 && id != 0)
+ drawmodellow.ScaleTexCoords(0.1);
+ drawmodellow.CalculateNormals(0);
+
+ if (clothes) {
+ modelclothes.loadnotex(modelclothesfilename);
+ modelclothes.Rotate(180, 0, 0);
+ modelclothes.Scale(.041, .04, .041);
+ modelclothes.CalculateNormals(0);
+
+ drawmodelclothes.load(modelclothesfilename, 0);
+ drawmodelclothes.Rotate(180, 0, 0);
+ drawmodelclothes.Scale(.04, .04, .04);
+ drawmodelclothes.FlipTexCoords();
+ drawmodelclothes.CalculateNormals(0);
+ }
+
+ // FIXME: three similar blocks follow, one for each of:
+ // filename, lowfilename, clothesfilename
+
+ // load skeleton
+
+ tfile = fopen( ConvertFileName(filename), "rb" );
+
+ if (1) { // FIXME: should this be if(tfile) ?
+ // read num_joints
+ funpackf(tfile, "Bi", &num_joints);
+
+ // allocate memory
+ //joints.resize(num_joints);
+ if (joints)
+ delete [] joints; //dealloc2(joints);
+ joints = (Joint*)new Joint[num_joints]; //malloc(sizeof(Joint)*num_joints);
+
+ // read info for each joint
+ for (i = 0; i < num_joints; i++) {
+ funpackf(tfile, "Bf Bf Bf Bf Bf", &joints[i].position.x, &joints[i].position.y, &joints[i].position.z, &joints[i].length, &joints[i].mass);
+ funpackf(tfile, "Bb Bb", &joints[i].hasparent, &joints[i].locked);
+ funpackf(tfile, "Bi", &joints[i].modelnum);
+ funpackf(tfile, "Bb Bb", &joints[i].visible, &joints[i].sametwist);
+ funpackf(tfile, "Bi Bi", &joints[i].label, &joints[i].hasgun);
+ funpackf(tfile, "Bb", &joints[i].lower);
+ funpackf(tfile, "Bi", &parentID);
+ if (joints[i].hasparent)
+ joints[i].parent = &joints[parentID];
+ joints[i].velocity = 0;
+ joints[i].oldposition = joints[i].position;
+ }
+
+ // read num_muscles
+ tempmuscle = num_muscles;
+ funpackf(tfile, "Bi", &num_muscles);
+
+ // allocate memory
+ //muscles.clear();
+ if (muscles)
+ delete [] muscles; //dealloc2(muscles);
+ muscles = (Muscle*)new Muscle[num_muscles]; //malloc(sizeof(Muscle)*num_muscles);
+
+ newload = 1;
+
+ // for each muscle...
+ for (i = 0; i < num_muscles; i++) {
+ // read info
+ tempmuscle = muscles[i].numvertices;
+ funpackf(tfile, "Bf Bf Bf Bf Bf Bi Bi", &muscles[i].length, &muscles[i].targetlength, &muscles[i].minlength, &muscles[i].maxlength, &muscles[i].strength, &muscles[i].type, &muscles[i].numvertices);
+
+ // allocate memory for vertices
+ //muscles[i].vertices.clear();
+ //muscles[i].vertices.resize(muscles[i].numvertices);
+ //if(muscles[i].vertices)dealloc2(muscles[i].vertices);
+ muscles[i].vertices = (int*)malloc(sizeof(int) * muscles[i].numvertices);
+
+ // read vertices
+ edit = 0;
+ for (j = 0; j < muscles[i].numvertices - edit; j++) {
+ funpackf(tfile, "Bi", &muscles[i].vertices[j + edit]);
+ if (muscles[i].vertices[j + edit] >= model[0].vertexNum) {
+ muscles[i].numvertices--;
+ edit--;
+ }
+ }
+
+ // read more info
+ funpackf(tfile, "Bb Bi", &muscles[i].visible, &parentID);
+ muscles[i].parent1 = &joints[parentID];
+ funpackf(tfile, "Bi", &parentID);
+ muscles[i].parent2 = &joints[parentID];
+ }
+
+ // read forwardjoints (?)
+ for (j = 0; j < 3; j++) {
+ funpackf(tfile, "Bi", &forwardjoints[j]);
+ }
+ // read lowforwardjoints (?)
+ for (j = 0; j < 3; j++) {
+ funpackf(tfile, "Bi", &lowforwardjoints[j]);
+ }
+
+ // ???
+ for (j = 0; j < num_muscles; j++) {
+ for (i = 0; i < muscles[j].numvertices; i++) {
+ for (int k = 0; k < num_models; k++) {
+ if (muscles[j].numvertices && muscles[j].vertices[i] < model[k].vertexNum)
+ model[k].owner[muscles[j].vertices[i]] = j;
+ }
+ }
+ }
+
+ // calculate some stuff
+ FindForwards();
+ for (i = 0; i < num_joints; i++) {
+ joints[i].startpos = joints[i].position;
+ }
+ for (i = 0; i < num_muscles; i++) {
+ FindRotationMuscle(i, -1);
+ }
+ // this seems to use opengl purely for matrix calculations
+ for (int k = 0; k < num_models; k++) {
+ for (i = 0; i < model[k].vertexNum; i++) {
+ model[k].vertex[i] = model[k].vertex[i] - (muscles[model[k].owner[i]].parent1->position + muscles[model[k].owner[i]].parent2->position) / 2;
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glRotatef(muscles[model[k].owner[i]].rotate3, 0, 1, 0);
+ glRotatef(muscles[model[k].owner[i]].rotate2 - 90, 0, 0, 1);
+ glRotatef(muscles[model[k].owner[i]].rotate1 - 90, 0, 1, 0);
+ glTranslatef(model[k].vertex[i].x, model[k].vertex[i].y, model[k].vertex[i].z);
+ glGetFloatv(GL_MODELVIEW_MATRIX, M);
+ model[k].vertex[i].x = M[12] * 1;
+ model[k].vertex[i].y = M[13] * 1;
+ model[k].vertex[i].z = M[14] * 1;
+ glPopMatrix();
+ }
+ model[k].CalculateNormals(0);
+ }
+ }
+ fclose(tfile);
+
+ // load ???
+
+ tfile = fopen( ConvertFileName(lowfilename), "rb" );
+
+ if (1) { // FIXME: should this be if(tfile) ?
+ // skip joints section
+
+ lSize = sizeof(num_joints);
+ fseek(tfile, lSize, SEEK_CUR);
+ //joints = new Joint[num_joints];
+ //jointlabels = new int[num_joints];
+ for (i = 0; i < num_joints; i++) {
+ // skip joint info
+ lSize = sizeof(XYZ)
+ + sizeof(float)
+ + sizeof(float)
+ + 1 //sizeof(bool)
+ + 1 //sizeof(bool)
+ + sizeof(int)
+ + 1 //sizeof(bool)
+ + 1 //sizeof(bool)
+ + sizeof(int)
+ + sizeof(int)
+ + 1 //sizeof(bool)
+ + sizeof(int);
+ fseek(tfile, lSize, SEEK_CUR);
+
+ if (joints[i].hasparent)
+ joints[i].parent = &joints[parentID];
+ joints[i].velocity = 0;
+ joints[i].oldposition = joints[i].position;
+ }
+
+ // read num_muscles
+ funpackf(tfile, "Bi", &num_muscles);
+ //muscles = new Muscle[num_muscles];
+
+ for (i = 0; i < num_muscles; i++) {
+ // skip muscle info
+ lSize = sizeof(float)
+ + sizeof(float)
+ + sizeof(float)
+ + sizeof(float)
+ + sizeof(float)
+ + sizeof(int);
+ fseek(tfile, lSize, SEEK_CUR);
+
+ // read numverticeslow
+ tempmuscle = muscles[i].numverticeslow;
+ funpackf(tfile, "Bi", &muscles[i].numverticeslow);
+
+ if (muscles[i].numverticeslow) {
+ // allocate memory
+ //muscles[i].verticeslow.clear();
+ //muscles[i].verticeslow.resize(muscles[i].numverticeslow);
+ //if(muscles[i].verticeslow)dealloc2(muscles[i].verticeslow);
+ muscles[i].verticeslow = (int*)malloc(sizeof(int) * muscles[i].numverticeslow);
+
+ // read verticeslow
+ edit = 0;
+ for (j = 0; j < muscles[i].numverticeslow - edit; j++) {
+ funpackf(tfile, "Bi", &muscles[i].verticeslow[j + edit]);
+ if (muscles[i].verticeslow[j + edit] >= modellow.vertexNum) {
+ muscles[i].numverticeslow--;
+ edit--;
+ }
+ }
+ }
+
+ // skip more stuff
+ lSize = 1; //sizeof(bool);
+ fseek ( tfile, lSize, SEEK_CUR);
+ lSize = sizeof(int);
+ fseek ( tfile, lSize, SEEK_CUR);
+ fseek ( tfile, lSize, SEEK_CUR);
+ }
+
+ // ???
+ lSize = sizeof(int);
+ for (j = 0; j < num_muscles; j++) {
+ for (i = 0; i < muscles[j].numverticeslow; i++) {
+ if (muscles[j].numverticeslow && muscles[j].verticeslow[i] < modellow.vertexNum)
+ modellow.owner[muscles[j].verticeslow[i]] = j;
+ }
+ }
+
+ /*FindForwards();
+ for(i=0;i<num_joints;i++){
+ joints[i].startpos=joints[i].position;
+ }
+ for(i=0;i<num_muscles;i++){
+ FindRotationMuscle(i,-1);
+ }*/
+
+ // use opengl for its matrix math
+ for (i = 0; i < modellow.vertexNum; i++) {
+ modellow.vertex[i] = modellow.vertex[i] - (muscles[modellow.owner[i]].parent1->position + muscles[modellow.owner[i]].parent2->position) / 2;
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glRotatef(muscles[modellow.owner[i]].rotate3, 0, 1, 0);
+ glRotatef(muscles[modellow.owner[i]].rotate2 - 90, 0, 0, 1);
+ glRotatef(muscles[modellow.owner[i]].rotate1 - 90, 0, 1, 0);
+ glTranslatef(modellow.vertex[i].x, modellow.vertex[i].y, modellow.vertex[i].z);
+ glGetFloatv(GL_MODELVIEW_MATRIX, M);
+ modellow.vertex[i].x = M[12];
+ modellow.vertex[i].y = M[13];
+ modellow.vertex[i].z = M[14];
+ glPopMatrix();
+ }
+
+ modellow.CalculateNormals(0);
+ }
+
+ // load clothes
+
+ if (clothes) {
+ tfile = fopen( ConvertFileName(clothesfilename), "rb" ); // FIXME: where's the check for valid load
+
+ // skip num_joints
+ lSize = sizeof(num_joints);
+ fseek ( tfile, lSize, SEEK_CUR);
+ //joints = new Joint[num_joints];
+ //jointlabels = new int[num_joints];
+
+ for (i = 0; i < num_joints; i++) {
+ // skip joint info
+ lSize = sizeof(XYZ)
+ + sizeof(float)
+ + sizeof(float)
+ + 1 //sizeof(bool)
+ + 1 //sizeof(bool)
+ + sizeof(int)
+ + 1 //sizeof(bool)
+ + 1 //sizeof(bool)
+ + sizeof(int)
+ + sizeof(int)
+ + 1 //sizeof(bool)
+ + sizeof(int);
+ fseek(tfile, lSize, SEEK_CUR);
+
+ if (joints[i].hasparent)
+ joints[i].parent = &joints[parentID];
+ joints[i].velocity = 0;
+ joints[i].oldposition = joints[i].position;
+ }
+
+ // read num_muscles
+ funpackf(tfile, "Bi", &num_muscles);
+ //muscles = new Muscle[num_muscles];
+
+ for (i = 0; i < num_muscles; i++) {
+ // skip muscle info
+ lSize = sizeof(float)
+ + sizeof(float)
+ + sizeof(float)
+ + sizeof(float)
+ + sizeof(float)
+ + sizeof(int);
+ fseek(tfile, lSize, SEEK_CUR);
+
+ // read numverticesclothes
+ tempmuscle = muscles[i].numverticesclothes;
+ funpackf(tfile, "Bi", &muscles[i].numverticesclothes);
+
+ // read verticesclothes
+ if (muscles[i].numverticesclothes) {
+ //muscles[i].verticesclothes.clear();
+ //muscles[i].verticesclothes.resize(muscles[i].numverticesclothes);
+ //if(muscles[i].verticesclothes)dealloc2(muscles[i].verticesclothes);
+ muscles[i].verticesclothes = (int*)malloc(sizeof(int) * muscles[i].numverticesclothes);
+ edit = 0;
+ for (j = 0; j < muscles[i].numverticesclothes - edit; j++) {
+ funpackf(tfile, "Bi", &muscles[i].verticesclothes[j + edit]);
+ if (muscles[i].verticesclothes[j + edit] >= modelclothes.vertexNum) {
+ muscles[i].numverticesclothes--;
+ edit--;
+ }
+ }
+ }
+
+ // skip more stuff
+ lSize = 1; //sizeof(bool);
+ fseek ( tfile, lSize, SEEK_CUR);
+ lSize = sizeof(int);
+ fseek ( tfile, lSize, SEEK_CUR);
+ fseek ( tfile, lSize, SEEK_CUR);
+ }
+
+ // ???
+ lSize = sizeof(int);
+ for (j = 0; j < num_muscles; j++) {
+ for (i = 0; i < muscles[j].numverticesclothes; i++) {
+ if (muscles[j].numverticesclothes && muscles[j].verticesclothes[i] < modelclothes.vertexNum)
+ modelclothes.owner[muscles[j].verticesclothes[i]] = j;
+ }
+ }
+
+ /*FindForwards();
+ for(i=0;i<num_joints;i++){
+ joints[i].startpos=joints[i].position;
+ }
+ for(i=0;i<num_muscles;i++){
+ FindRotationMuscle(i,-1);
+ }*/
+
+ // use opengl for its matrix math
+ for (i = 0; i < modelclothes.vertexNum; i++) {
+ modelclothes.vertex[i] = modelclothes.vertex[i] - (muscles[modelclothes.owner[i]].parent1->position + muscles[modelclothes.owner[i]].parent2->position) / 2;
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glLoadIdentity();
+ glRotatef(muscles[modelclothes.owner[i]].rotate3, 0, 1, 0);
+ glRotatef(muscles[modelclothes.owner[i]].rotate2 - 90, 0, 0, 1);
+ glRotatef(muscles[modelclothes.owner[i]].rotate1 - 90, 0, 1, 0);
+ glTranslatef(modelclothes.vertex[i].x, modelclothes.vertex[i].y, modelclothes.vertex[i].z);
+ glGetFloatv(GL_MODELVIEW_MATRIX, M);
+ modelclothes.vertex[i].x = M[12];
+ modelclothes.vertex[i].y = M[13];
+ modelclothes.vertex[i].z = M[14];
+ glPopMatrix();
+ }
+
+ modelclothes.CalculateNormals(0);
+ }
+ fclose(tfile);
+
+ for (i = 0; i < num_joints; i++) {
+ for (j = 0; j < num_joints; j++) {
+ if (joints[i].label == j)
+ jointlabels[j] = i;
+ }
+ }
+
+ free = 0;