/*
Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
-Lugaru is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
+Lugaru is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
-This program is distributed in the hope that it will be useful,
+Lugaru is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-See the GNU General Public License for more details.
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+along with Lugaru. If not, see <http://www.gnu.org/licenses/>.
*/
/**> HEADER FILES <**/
#include "Skeleton.h"
#include "openal_wrapper.h"
#include "Animation.h"
+#include "Utils/Folders.h"
extern float multiplier;
extern float gravity;
-extern Skeleton testskeleton;
extern Terrain terrain;
extern Objects objects;
extern int environment;
extern float camerashake;
extern bool freeze;
extern int detail;
-extern XYZ envsound[30];
-extern float envsoundvol[30];
-extern int numenvsounds;
-extern float envsoundlife[30];
extern int tutoriallevel;
extern int whichjointstartarray[26];
void dealloc2(void* param)
{
free(param);
- param = 0; // FIXME: does this *do* anything???
}
enum {boneconnect, constraint, muscle};
emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
- envsound[numenvsounds] = *coords;
- envsoundvol[numenvsounds] = 64;
- envsoundlife[numenvsounds] = .4;
- numenvsounds++;
+ addEnvSound(*coords, 64);
}
if (findLengthfast(&bounceness) > 2500) {
emit_sound_at(breaksound2, joints[i].position * (*scale) + *coords);
- envsound[numenvsounds] = *coords;
- envsoundvol[numenvsounds] = 64;
- envsoundlife[numenvsounds] = .4;
- numenvsounds++;
+ addEnvSound(*coords, 64);
}
if (objects.type[k] == treetrunktype) {
objects.rotx[k] += joints[i].velocity.x * multiplier * .4;
{
static int i;
for (i = 0; i < num_joints; i++) {
- if (((joints[i].label != leftknee && joints[i].label != rightknee) || lowforward.y > -.1 || joints[i].mass < 5) && ((joints[i].label != rightelbow && joints[i].label != rightelbow) || forward.y < .3))
+ if (
+ (
+ ((joints[i].label != leftknee) && (joints[i].label != rightknee)) ||
+ (lowforward.y > -.1) ||
+ (joints[i].mass < 5)
+ ) && (
+ ((joints[i].label != leftelbow) && (joints[i].label != rightelbow)) ||
+ (forward.y < .3)
+ )
+ )
joints[i].velocity.y += gravity * multiplier / (*scale);
}
}
/* EFFECT
* load an animation from file
*/
-void Animation::Load(const char *filename, int aheight, int aattack)
+void Animation::Load(const std::string& filename, int aheight, int aattack)
{
FILE *tfile;
int i, j;
- XYZ startoffset, endoffset;
-
- // path to dir
- const char *anim_prefix = ":Data:Animations:";
-
+ XYZ endoffset;
LOGFUNC;
- // concatenate anim_prefix + filename
- int len = strlen(anim_prefix) + strlen(filename);
- char *buf = new char[len + 1];
- snprintf(buf, len + 1, "%s%s", anim_prefix, filename);
// Changing the filename into something the OS can understand
- char *fixedFN = ConvertFileName(buf);
- delete[] buf;
+ std::string filepath = Folders::getResourcePath("Animations/"+filename);
- LOG(std::string("Loading animation...") + fixedFN);
+ LOG(std::string("Loading animation...") + filepath);
// clear existing data
deallocate();
Game::LoadingScreen();
// read file in binary mode
- tfile = fopen( fixedFN, "rb" );
- if (tfile) {
- // read numframes, joints to know how much memory to allocate
- funpackf(tfile, "Bi Bi", &numframes, &joints);
- /*
- for(i = 0; i < joints; i++){
- if(position[i])dealloc2(position[i]);
- if(twist[i])dealloc2(twist[i]);
- if(twist2[i])dealloc2(twist2[i]);
- if(onground[i])dealloc2(onground[i]);
- }*/
- /*
- if(position)dealloc2(position);
- if(twist)dealloc2(twist);
- if(twist2)dealloc2(twist2);
- if(speed)dealloc2(speed);
- if(onground)dealloc2(onground);
- if(forward)dealloc2(forward);
- if(weapontarget)dealloc2(weapontarget);
- if(label)dealloc2(label);*/
-
-
- // allocate memory for everything
-
- position = (XYZ**)malloc(sizeof(XYZ*) * joints);
- for (i = 0; i < joints; i++)
- position[i] = (XYZ*)malloc(sizeof(XYZ) * numframes);
+ tfile = Folders::openMandatoryFile( filepath, "rb" );
- twist = (float**)malloc(sizeof(float*) * joints);
- for (i = 0; i < joints; i++)
- twist[i] = (float*)malloc(sizeof(float) * numframes);
+ // read numframes, joints to know how much memory to allocate
+ funpackf(tfile, "Bi Bi", &numframes, &joints);
- twist2 = (float**)malloc(sizeof(float*) * joints);
- for (i = 0; i < joints; i++)
- twist2[i] = (float*)malloc(sizeof(float) * numframes);
+ // allocate memory for everything
- speed = (float*)malloc(sizeof(float) * numframes);
+ position = (XYZ**)malloc(sizeof(XYZ*) * joints);
+ for (i = 0; i < joints; i++)
+ position[i] = (XYZ*)malloc(sizeof(XYZ) * numframes);
- onground = (bool**)malloc(sizeof(bool*) * joints);
- for (i = 0; i < joints; i++)
- onground[i] = (bool*)malloc(sizeof(bool) * numframes);
+ twist = (float**)malloc(sizeof(float*) * joints);
+ for (i = 0; i < joints; i++)
+ twist[i] = (float*)malloc(sizeof(float) * numframes);
- forward = (XYZ*)malloc(sizeof(XYZ) * numframes);
- weapontarget = (XYZ*)malloc(sizeof(XYZ) * numframes);
- label = (int*)malloc(sizeof(int) * numframes);
+ twist2 = (float**)malloc(sizeof(float*) * joints);
+ for (i = 0; i < joints; i++)
+ twist2[i] = (float*)malloc(sizeof(float) * numframes);
- /*position = new XYZ[joints][numframes];
- twist = new float[joints][numframes];
- twist2 = new float[joints][numframes];
- speed = new float[numframes];
- onground = new bool[joints][numframes];
- forward = new XYZ[numframes];
- label = new int[numframes];*/
+ speed = (float*)malloc(sizeof(float) * numframes);
+ onground = (bool**)malloc(sizeof(bool*) * joints);
+ for (i = 0; i < joints; i++)
+ onground[i] = (bool*)malloc(sizeof(bool) * numframes);
- // read binary data as animation
+ forward = (XYZ*)malloc(sizeof(XYZ) * numframes);
+ weapontarget = (XYZ*)malloc(sizeof(XYZ) * numframes);
+ label = (int*)malloc(sizeof(int) * numframes);
- // for each frame...
- for (i = 0; i < numframes; i++) {
- // for each joint in the skeleton...
- for (j = 0; j < joints; j++) {
- // read joint position
- funpackf(tfile, "Bf Bf Bf", &position[j][i].x, &position[j][i].y, &position[j][i].z);
- }
- for (j = 0; j < joints; j++) {
- // read twist
- funpackf(tfile, "Bf", &twist[j][i]);
- }
- for (j = 0; j < joints; j++) {
- // read onground (boolean)
- unsigned char uch;
- funpackf(tfile, "Bb", &uch);
- onground[j][i] = (uch != 0);
- }
- // read frame speed (?)
- funpackf(tfile, "Bf", &speed[i]);
+ // read binary data as animation
+
+ // for each frame...
+ for (i = 0; i < numframes; i++) {
+ // for each joint in the skeleton...
+ for (j = 0; j < joints; j++) {
+ // read joint position
+ funpackf(tfile, "Bf Bf Bf", &position[j][i].x, &position[j][i].y, &position[j][i].z);
}
- // read twist2 for whole animation
- for (i = 0; i < numframes; i++) {
- for (j = 0; j < joints; j++) {
- funpackf(tfile, "Bf", &twist2[j][i]);
- }
+ for (j = 0; j < joints; j++) {
+ // read twist
+ funpackf(tfile, "Bf", &twist[j][i]);
}
- // read label for each frame
- for (i = 0; i < numframes; i++) {
- funpackf(tfile, "Bf", &label[i]);
+ for (j = 0; j < joints; j++) {
+ // read onground (boolean)
+ unsigned char uch;
+ funpackf(tfile, "Bb", &uch);
+ onground[j][i] = (uch != 0);
}
- // read weapontargetnum
- funpackf(tfile, "Bi", &weapontargetnum);
- // read weapontarget positions for each frame
- for (i = 0; i < numframes; i++) {
- funpackf(tfile, "Bf Bf Bf", &weapontarget[i].x, &weapontarget[i].y, &weapontarget[i].z);
+ // read frame speed (?)
+ funpackf(tfile, "Bf", &speed[i]);
+ }
+ // read twist2 for whole animation
+ for (i = 0; i < numframes; i++) {
+ for (j = 0; j < joints; j++) {
+ funpackf(tfile, "Bf", &twist2[j][i]);
}
-
- fclose(tfile);
}
+ // read label for each frame
+ for (i = 0; i < numframes; i++) {
+ funpackf(tfile, "Bf", &label[i]);
+ }
+ // read weapontargetnum
+ funpackf(tfile, "Bi", &weapontargetnum);
+ // read weapontarget positions for each frame
+ for (i = 0; i < numframes; i++) {
+ funpackf(tfile, "Bf Bf Bf", &weapontarget[i].x, &weapontarget[i].y, &weapontarget[i].z);
+ }
+
+ fclose(tfile);
- startoffset = 0;
endoffset = 0;
- // find average position of certain joints on first and last frames
- // and save in startoffset, endoffset
+ // find average position of certain joints on last frames
+ // and save in endoffset
// (not sure what exactly this accomplishes. the y < 1 test confuses me.)
for (j = 0; j < joints; j++) {
- if (position[j][0].y < 1)
- startoffset += position[j][0];
if (position[j][numframes - 1].y < 1)
endoffset += position[j][numframes - 1];
}
- startoffset /= joints;
endoffset /= joints;
offset = endoffset;
offset.y = 0;
// load skeleton
- tfile = fopen( ConvertFileName(filename), "rb" );
+ tfile = Folders::openMandatoryFile( Folders::getResourcePath(filename), "rb" );
- if (1) { // FIXME: should this be if(tfile) ?
- // read num_joints
- funpackf(tfile, "Bi", &num_joints);
+ // 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);
+ // allocate memory
+ if (joints)
+ delete [] joints; //dealloc2(joints);
+ joints = (Joint*)new 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
- 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);
-
- // for each muscle...
- for (i = 0; i < num_muscles; i++) {
- // read info
- 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 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 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 num_muscles
+ funpackf(tfile, "Bi", &num_muscles);
+
+ // allocate memory
+ if (muscles)
+ delete [] muscles; //dealloc2(muscles);
+ muscles = (Muscle*)new Muscle[num_muscles]; //malloc(sizeof(Muscle)*num_muscles);
+
+ // for each muscle...
+ for (i = 0; i < num_muscles; i++) {
+ // read info
+ 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 = (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]);
- }
+ // 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];
+ }
- // ???
- 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;
- }
+ // 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);
+ // 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" );
+ tfile = Folders::openMandatoryFile( Folders::getResourcePath(lowfilename), "rb" );
- if (1) { // FIXME: should this be if(tfile) ?
- // skip joints section
+ // skip joints section
- lSize = sizeof(num_joints);
+ lSize = sizeof(num_joints);
+ fseek(tfile, lSize, SEEK_CUR);
+ 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);
- //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];
+ if (joints[i].hasparent)
+ joints[i].parent = &joints[parentID];
+ joints[i].velocity = 0;
+ joints[i].oldposition = joints[i].position;
+ }
- 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 num_muscles
+ funpackf(tfile, "Bi", &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
- funpackf(tfile, "Bi", &muscles[i].numverticeslow);
+ // read 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);
+ if (muscles[i].numverticeslow) {
+ // allocate memory
+ 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--;
- }
+ // 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);
}
- // ???
+ // skip more stuff
+ lSize = 1; //sizeof(bool);
+ 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);
- }*/
+ fseek ( tfile, lSize, SEEK_CUR);
+ fseek ( tfile, lSize, SEEK_CUR);
+ }
- // 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();
+ for (j = 0; j < num_muscles; j++) {
+ for (i = 0; i < muscles[j].numverticeslow; i++) {
+ if (muscles[j].verticeslow[i] < modellow.vertexNum)
+ modellow.owner[muscles[j].verticeslow[i]] = j;
}
+ }
- modellow.CalculateNormals(0);
+ // 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
+ tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" );
// 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
// read num_muscles
funpackf(tfile, "Bi", &num_muscles);
- //muscles = new Muscle[num_muscles];
for (i = 0; i < num_muscles; i++) {
// skip muscle info
// 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++) {
}
}
- /*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;
{
int i = 0;
- bool allocate = true;
-
- allocate = ((ani.numframes != numframes) || (ani.joints != joints));
+ bool allocate = ((ani.numframes != numframes) || (ani.joints != joints));
if (allocate)
deallocate();
attack = ani.attack;
joints = ani.joints;
weapontargetnum = ani.weapontargetnum;
+ offset = ani.offset;
if (allocate)
position = (XYZ**)malloc(sizeof(XYZ*)*ani.joints);
glVertex3f(joints[i].parent->position.x, joints[i].parent->position.y, joints[i].parent->position.z);
}
}
- /*for(int i=0; i<num_joints; i++){
- if(joints[i].hasparent){
- glColor4f(jointcolor[0],jointcolor[1],jointcolor[2],1);
- glVertex3f(joints[i].position.x,joints[i].position.y,joints[i].position.z);
- glColor4f(jointcolor[0],jointcolor[1],jointcolor[2],1);
- glVertex3f(joints[i].position.x+forward.x,joints[i].position.y+forward.y,joints[i].position.z+forward.z);
- }
- }*/
for (int i = 0; i < num_muscles; i++) {
if (muscles[i].type == boneconnect) {
glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / muscles[i].parent1->blurred);
joints[num_joints].mass = 1;
joints[num_joints].locked = 0;
- /*if(which>=num_joints||which<0)*/
joints[num_joints].hasparent = 0;
- /*if(which<num_joints&&which>=0){
- joints[num_joints].parent=&joints[which];
- joints[num_joints].hasparent=1;
- joints[num_joints].length=findDistance(joints[num_joints].position,joints[num_joints].parent->position);
- }*/
num_joints++;
if (which < num_joints && which >= 0)
AddMuscle(num_joints - 1, which, 0, 10, boneconnect);