*/
#include "Animation/Muscle.h"
+#include "binio.h"
extern float multiplier;
extern bool freeze;
Muscle::Muscle()
{
- vertices = 0;
- verticeslow = 0;
- verticesclothes = 0;
-
- numvertices = 0;
- numverticeslow = 0;
- numverticesclothes = 0;
length = 0;
targetlength = 0;
parent1 = 0;
Muscle::~Muscle()
{
- free(vertices);
- free(verticeslow);
- free(verticesclothes);
+}
+
+void Muscle::load(FILE* tfile, int vertexNum, Joint* joints)
+{
+ int numvertices, vertice, parentID;
+
+ // read info
+ funpackf(tfile, "Bf Bf Bf Bf Bf Bi Bi", &length, &targetlength, &minlength, &maxlength, &strength, &type, &numvertices);
+
+ // read vertices
+ for (int j = 0; j < numvertices; j++) {
+ funpackf(tfile, "Bi", &vertice);
+ if (vertice < vertexNum) {
+ vertices.push_back(vertice);
+ }
+ }
+
+ // read more info
+ funpackf(tfile, "Bb Bi", &visible, &parentID);
+ parent1 = &joints[parentID];
+ funpackf(tfile, "Bi", &parentID);
+ parent2 = &joints[parentID];
+}
+
+void Muscle::loadVerticesLow(FILE* tfile, int vertexNum)
+{
+ int numvertices, vertice;
+
+ // read numvertices
+ funpackf(tfile, "Bi", &numvertices);
+
+ // read vertices
+ for (int j = 0; j < numvertices; j++) {
+ funpackf(tfile, "Bi", &vertice);
+ if (vertice < vertexNum) {
+ verticeslow.push_back(vertice);
+ }
+ }
+}
+
+void Muscle::loadVerticesClothes(FILE* tfile, int vertexNum)
+{
+ int numvertices, vertice;
+
+ // read numvertices
+ funpackf(tfile, "Bi", &numvertices);
+
+ // read vertices
+ for (int j = 0; j < numvertices; j++) {
+ funpackf(tfile, "Bi", &vertice);
+ if (vertice < vertexNum) {
+ verticesclothes.push_back(vertice);
+ }
+ }
}
extern bool visibleloading;
-/* EFFECT
- */
-void dealloc2(void* param)
+Skeleton::Skeleton()
+{
+ num_joints = 0;
+
+ num_muscles = 0;
+
+ selected = 0;
+
+ memset(forwardjoints, 0, sizeof(forwardjoints));
+
+ id = 0;
+
+ memset(lowforwardjoints, 0, sizeof(lowforwardjoints));
+
+ memset(jointlabels, 0, sizeof(jointlabels));
+
+ num_models = 0;
+
+ clothes = 0;
+ spinny = 0;
+
+ memset(skinText, 0, sizeof(skinText));
+ skinsize = 0;
+
+ checkdelay = 0;
+
+ longdead = 0;
+ broken = 0;
+
+ free = 0;
+ oldfree = 0;
+ freetime = 0;
+ freefall = 0;
+
+ joints = 0;
+ muscles = 0;
+}
+
+Skeleton::~Skeleton()
{
- free(param);
+ if (muscles) {
+ delete [] muscles;
+ }
+ muscles = 0;
+
+ if (joints) {
+ delete [] joints;
+ }
+ joints = 0;
}
/* EFFECT
drawmodel.Rotate(180, 0, 0);
drawmodel.Scale(.04, .04, .04);
drawmodel.FlipTexCoords();
- if (tutoriallevel == 1 && id != 0)
+ if ((tutoriallevel == 1) && (id != 0)) {
drawmodel.UniformTexCoords();
- if (tutoriallevel == 1 && id != 0)
drawmodel.ScaleTexCoords(0.1);
+ }
drawmodel.CalculateNormals(0);
modellow.loadnotex(modellowfilename);
joints[i].parent = &joints[parentID];
joints[i].velocity = 0;
joints[i].oldposition = joints[i].position;
+ joints[i].startpos = joints[i].position;
}
// read 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];
+ muscles[i].load(tfile, model[0].vertexNum, joints);
}
// read forwardjoints (?)
// ???
for (j = 0; j < num_muscles; j++) {
- for (i = 0; i < muscles[j].numvertices; i++) {
+ for (i = 0; i < muscles[j].vertices.size(); i++) {
for (int k = 0; k < num_models; k++) {
- if (muscles[j].numvertices && muscles[j].vertices[i] < model[k].vertexNum)
+ if (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);
}
+ 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
+ sizeof(int);
fseek(tfile, lSize, SEEK_CUR);
- // read numverticeslow
- funpackf(tfile, "Bi", &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--;
- }
- }
- }
+ muscles[i].loadVerticesLow(tfile, modellow.vertexNum);
// skip more stuff
lSize = 1; //sizeof(bool);
}
for (j = 0; j < num_muscles; j++) {
- for (i = 0; i < muscles[j].numverticeslow; i++) {
+ for (i = 0; i < muscles[j].verticeslow.size(); i++) {
if (muscles[j].verticeslow[i] < modellow.vertexNum)
modellow.owner[muscles[j].verticeslow[i]] = j;
}
+ 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
+ sizeof(int);
fseek(tfile, lSize, SEEK_CUR);
- // read numverticesclothes
- funpackf(tfile, "Bi", &muscles[i].numverticesclothes);
-
- // read verticesclothes
- if (muscles[i].numverticesclothes) {
- 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--;
- }
- }
- }
+ muscles[i].loadVerticesClothes(tfile, modelclothes.vertexNum);
// skip more stuff
lSize = 1; //sizeof(bool);
// ???
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)
+ for (i = 0; i < muscles[j].verticesclothes.size(); i++) {
+ if (muscles[j].verticesclothes.size() && muscles[j].verticesclothes[i] < modelclothes.vertexNum)
modelclothes.owner[muscles[j].verticesclothes[i]] = j;
}
}
free = 0;
}
-Skeleton::Skeleton()
-{
- num_joints = 0;
-
- num_muscles = 0;
-
- selected = 0;
-
- memset(forwardjoints, 0, sizeof(forwardjoints));
- // XYZ forward;
-
- id = 0;
-
- memset(lowforwardjoints, 0, sizeof(lowforwardjoints));
- // XYZ lowforward;
-
- // XYZ specialforward[5];
- memset(jointlabels, 0, sizeof(jointlabels));
-
- // Model model[7];
- // Model modellow;
- // Model modelclothes;
- num_models = 0;
-
- // Model drawmodel;
- // Model drawmodellow;
- // Model drawmodelclothes;
-
- clothes = 0;
- spinny = 0;
-
- memset(skinText, 0, sizeof(skinText));
- skinsize = 0;
-
- checkdelay = 0;
-
- longdead = 0;
- broken = 0;
-
- free = 0;
- oldfree = 0;
- freetime = 0;
- freefall = 0;
-
- joints = 0;
- muscles = 0;
-}
-
-Skeleton::~Skeleton()
-{
- if (muscles) {
- delete [] muscles;
- }
- muscles = 0;
-
- if (joints) {
- delete [] joints;
- }
- joints = 0;
-}
-
#if 0
// the following functions are not used anywhere
const int p1 = skeleton.muscles[i].parent1->label;
const int p2 = skeleton.muscles[i].parent2->label;
- if ((skeleton.muscles[i].numvertices > 0 && playerdetail) || (skeleton.muscles[i].numverticeslow > 0 && !playerdetail)) {
+ if ((skeleton.muscles[i].vertices.size() > 0 && playerdetail) || (skeleton.muscles[i].verticeslow.size() > 0 && !playerdetail)) {
morphness = 0;
start = 0;
endthing = 0;
glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
if (playerdetail || skeleton.free == 3) {
- for (j = 0; j < skeleton.muscles[i].numvertices; j++) {
+ for (j = 0; j < skeleton.muscles[i].vertices.size(); j++) {
XYZ &v0 = skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]];
XYZ &v1 = skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]];
glMatrixMode(GL_MODELVIEW);
}
}
if (!playerdetail || skeleton.free == 3) {
- for (j = 0; j < skeleton.muscles[i].numverticeslow; j++) {
+ for (j = 0; j < skeleton.muscles[i].verticeslow.size(); j++) {
XYZ &v0 = skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]];
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
}
glPopMatrix();
}
- if (skeleton.clothes && skeleton.muscles[i].numverticesclothes > 0) {
+ if (skeleton.clothes && skeleton.muscles[i].verticesclothes.size() > 0) {
mid = (skeleton.muscles[i].parent1->position + skeleton.muscles[i].parent2->position) / 2;
glMatrixMode(GL_MODELVIEW);
skeleton.muscles[i].lastrotate3 = skeleton.muscles[i].rotate3;
glRotatef(-skeleton.muscles[i].lastrotate3, 0, 1, 0);
- for (j = 0; j < skeleton.muscles[i].numverticesclothes; j++) {
+ for (j = 0; j < skeleton.muscles[i].verticesclothes.size(); j++) {
XYZ &v0 = skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]];
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
if (weaponactive == k) {
if (weapons[i].getType() != staff) {
for (j = 0; j < skeleton.num_muscles; j++) {
- if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
+ if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
weaponattachmuscle = j;
}
}
for (j = 0; j < skeleton.num_muscles; j++) {
- if ((skeleton.muscles[j].parent1->label == rightwrist || skeleton.muscles[j].parent2->label == rightwrist) && (skeleton.muscles[j].parent1->label != righthand && skeleton.muscles[j].parent2->label != righthand) && skeleton.muscles[j].numvertices > 0) {
+ if ((skeleton.muscles[j].parent1->label == rightwrist || skeleton.muscles[j].parent2->label == rightwrist) && (skeleton.muscles[j].parent1->label != righthand && skeleton.muscles[j].parent2->label != righthand) && skeleton.muscles[j].vertices.size() > 0) {
weaponrotatemuscle = j;
}
}
}
if (weapons[i].getType() == staff) {
for (j = 0; j < skeleton.num_muscles; j++) {
- if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].numvertices > 0) {
+ if ((skeleton.muscles[j].parent1->label == righthand || skeleton.muscles[j].parent2->label == righthand) && skeleton.muscles[j].vertices.size() > 0) {
weaponattachmuscle = j;
}
}
for (j = 0; j < skeleton.num_muscles; j++) {
- if ((skeleton.muscles[j].parent1->label == rightelbow || skeleton.muscles[j].parent2->label == rightelbow) && (skeleton.muscles[j].parent1->label != rightshoulder && skeleton.muscles[j].parent2->label != rightshoulder) && skeleton.muscles[j].numvertices > 0) {
+ if ((skeleton.muscles[j].parent1->label == rightelbow || skeleton.muscles[j].parent2->label == rightelbow) && (skeleton.muscles[j].parent1->label != rightshoulder && skeleton.muscles[j].parent2->label != rightshoulder) && skeleton.muscles[j].vertices.size() > 0) {
weaponrotatemuscle = j;
}
}
if (weapons[i].getType() == staff)
weaponpoint = jointPos(abdomen) + (jointPos(lefthip) - jointPos(righthip)) * .09 + (jointPos(leftshoulder) - jointPos(rightshoulder)) * .33;
for (j = 0; j < skeleton.num_muscles; j++) {
- if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].numvertices > 0) {
+ if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].vertices.size() > 0) {
weaponrotatemuscle = j;
}
}
else
weaponpoint = jointPos(abdomen) * .5 + jointPos(neck) * .5 + skeleton.forward * .8;
for (j = 0; j < skeleton.num_muscles; j++) {
- if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].numvertices > 0) {
+ if ((skeleton.muscles[j].parent1->label == abdomen || skeleton.muscles[j].parent2->label == abdomen) && (skeleton.muscles[j].parent1->label == neck || skeleton.muscles[j].parent2->label == neck) && skeleton.muscles[j].vertices.size() > 0) {
weaponrotatemuscle = j;
}
}