X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=inline;f=Source%2FSkeleton.cpp;h=af343d6b3261b3a405f876f877e665a7a6813c85;hb=d9af94bbebdd8ab2b276a0a66492c9d97677d4f4;hp=fe99c32f75d977b6abfdc2ac551588461d51e9a2;hpb=7de3125ca72d91329f0d4d0980635cf7355c3082;p=lugaru.git
diff --git a/Source/Skeleton.cpp b/Source/Skeleton.cpp
index fe99c32..af343d6 100644
--- a/Source/Skeleton.cpp
+++ b/Source/Skeleton.cpp
@@ -1,5 +1,6 @@
/*
Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010-2016 - Lugaru contributors (see AUTHORS file)
This file is part of Lugaru.
@@ -25,17 +26,12 @@ along with Lugaru. If not, see .
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];
@@ -350,10 +346,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale)
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) {
@@ -438,10 +431,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale)
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;
@@ -682,7 +672,7 @@ void Animation::Load(const char *filename, int aheight, int aattack)
{
FILE *tfile;
int i, j;
- XYZ startoffset, endoffset;
+ XYZ endoffset;
// path to dir
const char *anim_prefix = ":Data:Animations:";
@@ -714,23 +704,6 @@ void Animation::Load(const char *filename, int aheight, int aattack)
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
@@ -756,15 +729,6 @@ void Animation::Load(const char *filename, int aheight, int aattack)
weapontarget = (XYZ*)malloc(sizeof(XYZ) * numframes);
label = (int*)malloc(sizeof(int) * 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];*/
-
-
// read binary data as animation
// for each frame...
@@ -807,18 +771,14 @@ void Animation::Load(const char *filename, int aheight, int aattack)
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;
@@ -914,10 +874,9 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
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);
+ joints = (Joint*)new Joint[num_joints];
// read info for each joint
for (i = 0; i < num_joints; i++) {
@@ -938,7 +897,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
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);
@@ -949,9 +907,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
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
@@ -1029,8 +984,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
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)
@@ -1055,7 +1008,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
// read num_muscles
funpackf(tfile, "Bi", &num_muscles);
- //muscles = new Muscle[num_muscles];
for (i = 0; i < num_muscles; i++) {
// skip muscle info
@@ -1072,9 +1024,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
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
@@ -1103,14 +1052,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
}
}
- /*FindForwards();
- for(i=0;iposition + muscles[modellow.owner[i]].parent2->position) / 2;
@@ -1139,8 +1080,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
// 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
@@ -1166,7 +1105,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
// read num_muscles
funpackf(tfile, "Bi", &num_muscles);
- //muscles = new Muscle[num_muscles];
for (i = 0; i < num_muscles; i++) {
// skip muscle info
@@ -1183,9 +1121,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
// 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++) {
@@ -1214,14 +1149,6 @@ void Skeleton::Load(const char *filename, const char *lowfilename, const c
}
}
- /*FindForwards();
- for(i=0;iposition + muscles[modelclothes.owner[i]].parent2->position) / 2;
@@ -1592,14 +1519,6 @@ void Skeleton::Draw(int muscleview)
glVertex3f(joints[i].parent->position.x, joints[i].parent->position.y, joints[i].parent->position.z);
}
}
- /*for(int i=0; iblurred);
@@ -1656,13 +1575,7 @@ void Skeleton::AddJoint(float x, float y, float z, int which)
joints[num_joints].mass = 1;
joints[num_joints].locked = 0;
- /*if(which>=num_joints||which<0)*/
joints[num_joints].hasparent = 0;
- /*if(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);