X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FAnimation%2FSkeleton.cpp;h=ee247c51f70e135778c7c1b8a728a0d1859a0650;hb=f83c7bc4ef12b0bbdc1cfa6bdce35d9665510e6c;hp=ee19b81f7edbf745f96c71c81caaa78822d4e504;hpb=1d589bc3024e30dd51e41b6041b57649190bef4d;p=lugaru.git diff --git a/Source/Animation/Skeleton.cpp b/Source/Animation/Skeleton.cpp index ee19b81..ee247c5 100644 --- a/Source/Animation/Skeleton.cpp +++ b/Source/Animation/Skeleton.cpp @@ -40,11 +40,25 @@ extern int whichjointendarray[26]; extern bool visibleloading; -/* EFFECT - */ -void dealloc2(void* param) +Skeleton::Skeleton() : + selected(0), + id(0), + num_models(0), + clothes(false), + spinny(false), + skinsize(0), + checkdelay(0), + longdead(0), + broken(false), + free(0), + oldfree(0), + freetime(0), + freefall(false) { - free(param); + memset(forwardjoints, 0, sizeof(forwardjoints)); + memset(lowforwardjoints, 0, sizeof(lowforwardjoints)); + memset(jointlabels, 0, sizeof(jointlabels)); + memset(skinText, 0, sizeof(skinText)); } /* EFFECT @@ -122,7 +136,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) objects.SphereCheckPossible(&terrainlight, 1); //Add velocity - for (i = 0; i < num_joints; i++) { + for (i = 0; i < joints.size(); i++) { joints[i].position = joints[i].position + joints[i].velocity * multiplier; switch (joints[i].label) { @@ -197,14 +211,14 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } } - for (i = 0; i < num_joints; i++) { + for (i = 0; i < joints.size(); i++) { if (joints[i].locked && !spinny && findLengthfast(&joints[i].velocity) > 320) joints[i].locked = 0; if (spinny && findLengthfast(&joints[i].velocity) > 600) joints[i].locked = 0; if (joints[i].delay > 0) { bool freely = true; - for (j = 0; j < num_joints; j++) { + for (j = 0; j < joints.size(); j++) { if (joints[j].locked) freely = false; } @@ -213,13 +227,12 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } } - if (num_muscles) - for (i = 0; i < num_muscles; i++) { - //Length constraints - muscles[i].DoConstraint(spinny); - } + for (i = 0; i < muscles.size(); i++) { + //Length constraints + muscles[i].DoConstraint(spinny); + } - for (i = 0; i < num_joints; i++) { + for (i = 0; i < joints.size(); i++) { //Length constraints //Ground constraint groundlevel = 0; @@ -407,7 +420,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) whichhit = objects.model[k].LineCheckSlidePossible(&start, &end, &temp, &objects.position[k], &objects.yaw[k]); if (whichhit != -1) { joints[jointlabels[whichjointendarray[i]]].position = (end - *coords) / (*scale); - for (j = 0; j < num_muscles; j++) { + for (j = 0; j < muscles.size(); j++) { 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])) muscles[j].DoConstraint(spinny); } @@ -416,7 +429,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } } - for (i = 0; i < num_joints; i++) { + for (i = 0; i < joints.size(); i++) { switch (joints[i].label) { case head: groundlevel = .8; @@ -446,7 +459,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) } if (!free) { - for (i = 0; i < num_muscles; i++) { + for (i = 0; i < muscles.size(); i++) { if (muscles[i].type == boneconnect) muscles[i].DoConstraint(0); } @@ -464,7 +477,7 @@ float Skeleton::DoConstraints(XYZ *coords, float *scale) void Skeleton::DoGravity(float *scale) { static int i; - for (i = 0; i < num_joints; i++) { + for (i = 0; i < joints.size(); i++) { if ( ( ((joints[i].label != leftknee) && (joints[i].label != rightknee)) || @@ -600,11 +613,9 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil const std::string& modelclothesfilename, bool clothes) { GLfloat M[16]; - int parentID; FILE *tfile; float lSize; - int i, j; - int edit; + int i, j, num_joints, num_muscles; LOGFUNC; @@ -631,10 +642,10 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil 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); @@ -675,57 +686,22 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // read num_joints funpackf(tfile, "Bi", &num_joints); - // allocate memory - if (joints) - delete [] joints; //dealloc2(joints); - joints = (Joint*)new Joint[num_joints]; + joints.resize(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; + joints[i].load(tfile, joints); } // 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); + muscles.resize(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 (?) @@ -739,9 +715,9 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // ??? 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; } } @@ -749,9 +725,6 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // 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); } @@ -782,8 +755,7 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // skip joints section - lSize = sizeof(num_joints); - fseek(tfile, lSize, SEEK_CUR); + fseek(tfile, sizeof(num_joints), SEEK_CUR); for (i = 0; i < num_joints; i++) { // skip joint info lSize = sizeof(XYZ) @@ -799,15 +771,10 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil + 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); + // skip num_muscles + fseek(tfile, sizeof(num_muscles), SEEK_CUR); for (i = 0; i < num_muscles; i++) { // skip muscle info @@ -819,23 +786,7 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil + 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); @@ -846,7 +797,7 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil } 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; } @@ -877,8 +828,7 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil tfile = Folders::openMandatoryFile( Folders::getResourcePath(clothesfilename), "rb" ); // skip num_joints - lSize = sizeof(num_joints); - fseek ( tfile, lSize, SEEK_CUR); + fseek(tfile, sizeof(num_joints), SEEK_CUR); for (i = 0; i < num_joints; i++) { // skip joint info @@ -895,15 +845,10 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil + 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); + // skip num_muscles + fseek(tfile, sizeof(num_muscles), SEEK_CUR); for (i = 0; i < num_muscles; i++) { // skip muscle info @@ -915,21 +860,7 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil + 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); @@ -942,8 +873,8 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil // ??? 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; } } @@ -978,363 +909,3 @@ void Skeleton::Load(const std::string& filename, const std::string& lowfil 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 - -/* EFFECT - * sets forward, lowforward, specialforward[] - * - * USES: - * NONE - */ -void Skeleton::FindForwardsfirst() -{ - //Find forward vectors - CrossProduct(joints[forwardjoints[1]].position - joints[forwardjoints[0]].position, joints[forwardjoints[2]].position - joints[forwardjoints[0]].position, &forward); - Normalise(&forward); - - CrossProduct(joints[lowforwardjoints[1]].position - joints[lowforwardjoints[0]].position, joints[lowforwardjoints[2]].position - joints[lowforwardjoints[0]].position, &lowforward); - Normalise(&lowforward); - - //Special forwards - specialforward[0] = forward; - specialforward[1] = forward; - specialforward[2] = forward; - specialforward[3] = forward; - specialforward[4] = forward; - -} - -/* EFFECT - * - * USES: - * NONE - */ -void Skeleton::Draw(int muscleview) -{ - static float jointcolor[4]; - - if (muscleview == 2) { - jointcolor[0] = 0; - jointcolor[1] = 0; - jointcolor[2] = 0; - jointcolor[3] = .5; - } else { - jointcolor[0] = 0; - jointcolor[1] = 0; - jointcolor[2] = .5; - jointcolor[3] = 1; - } - - //Calc motionblur-ness - for (int i = 0; i < num_joints; i++) { - joints[i].oldposition = joints[i].position; - joints[i].blurred = findDistance(&joints[i].position, &joints[i].oldposition) * 100; - if (joints[i].blurred < 1) - joints[i].blurred = 1; - } - - //Do Motionblur - glDepthMask(0); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBegin(GL_QUADS); - for (int i = 0; i < num_joints; i++) { - if (joints[i].hasparent) { - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / joints[i].blurred); - glVertex3f(joints[i].position.x, joints[i].position.y, joints[i].position.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / joints[i].parent->blurred); - glVertex3f(joints[i].parent->position.x, joints[i].parent->position.y, joints[i].parent->position.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / joints[i].parent->blurred); - glVertex3f(joints[i].parent->oldposition.x, joints[i].parent->oldposition.y, joints[i].parent->oldposition.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / joints[i].blurred); - glVertex3f(joints[i].oldposition.x, joints[i].oldposition.y, joints[i].oldposition.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].parent2->blurred); - glVertex3f(muscles[i].parent1->position.x, muscles[i].parent1->position.y, muscles[i].parent1->position.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / muscles[i].parent2->blurred); - glVertex3f(muscles[i].parent2->position.x, muscles[i].parent2->position.y, muscles[i].parent2->position.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / muscles[i].parent2->blurred); - glVertex3f(muscles[i].parent2->oldposition.x, muscles[i].parent2->oldposition.y, muscles[i].parent2->oldposition.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / muscles[i].parent1->blurred); - glVertex3f(muscles[i].parent1->oldposition.x, muscles[i].parent1->oldposition.y, muscles[i].parent1->oldposition.z); - } - } - glEnd(); - - glBegin(GL_LINES); - for (int i = 0; i < num_joints; i++) { - if (joints[i].hasparent) { - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / joints[i].blurred); - glVertex3f(joints[i].position.x, joints[i].position.y, joints[i].position.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / joints[i].parent->blurred); - glVertex3f(joints[i].parent->position.x, joints[i].parent->position.y, joints[i].parent->position.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); - glVertex3f(muscles[i].parent1->position.x, muscles[i].parent1->position.y, muscles[i].parent1->position.z); - glColor4f(jointcolor[0], jointcolor[1], jointcolor[2], jointcolor[3] / muscles[i].parent2->blurred); - glVertex3f(muscles[i].parent2->position.x, muscles[i].parent2->position.y, muscles[i].parent2->position.z); - } - } - glColor3f(.6, .6, 0); - if (muscleview == 1) - for (int i = 0; i < num_muscles; i++) { - if (muscles[i].type != boneconnect) { - glVertex3f(muscles[i].parent1->position.x, muscles[i].parent1->position.y, muscles[i].parent1->position.z); - glVertex3f(muscles[i].parent2->position.x, muscles[i].parent2->position.y, muscles[i].parent2->position.z); - } - } - glEnd(); - - if (muscleview != 2) { - glPointSize(3); - glBegin(GL_POINTS); - for (int i = 0; i < num_joints; i++) { - if (i != selected) - glColor4f(0, 0, .5, 1); - if (i == selected) - glColor4f(1, 1, 0, 1); - if (joints[i].locked && i != selected) - glColor4f(1, 0, 0, 1); - glVertex3f(joints[i].position.x, joints[i].position.y, joints[i].position.z); - } - glEnd(); - } - - //Set old position to current position - if (muscleview == 2) - for (int i = 0; i < num_joints; i++) { - joints[i].oldposition = joints[i].position; - } - glDepthMask(1); -} - -/* EFFECT - * - * USES: - * NONE - */ -void Skeleton::AddJoint(float x, float y, float z, int which) -{ - if (num_joints < max_joints - 1) { - joints[num_joints].velocity = 0; - joints[num_joints].position.x = x; - joints[num_joints].position.y = y; - joints[num_joints].position.z = z; - joints[num_joints].mass = 1; - joints[num_joints].locked = 0; - - joints[num_joints].hasparent = 0; - num_joints++; - if (which < num_joints && which >= 0) - AddMuscle(num_joints - 1, which, 0, 10, boneconnect); - } -} - -/* EFFECT - * - * USES: - * NONE - */ -void Skeleton::DeleteJoint(int whichjoint) -{ - if (whichjoint < num_joints && whichjoint >= 0) { - joints[whichjoint].velocity = joints[num_joints - 1].velocity; - joints[whichjoint].position = joints[num_joints - 1].position; - joints[whichjoint].oldposition = joints[num_joints - 1].oldposition; - joints[whichjoint].hasparent = joints[num_joints - 1].hasparent; - joints[whichjoint].parent = joints[num_joints - 1].parent; - joints[whichjoint].length = joints[num_joints - 1].length; - joints[whichjoint].locked = joints[num_joints - 1].locked; - joints[whichjoint].modelnum = joints[num_joints - 1].modelnum; - joints[whichjoint].visible = joints[num_joints - 1].visible; - - for (int i = 0; i < num_muscles; i++) { - while (muscles[i].parent1 == &joints[whichjoint] && i < num_muscles)DeleteMuscle(i); - while (muscles[i].parent2 == &joints[whichjoint] && i < num_muscles)DeleteMuscle(i); - } - for (int i = 0; i < num_muscles; i++) { - while (muscles[i].parent1 == &joints[num_joints - 1] && i < num_muscles)muscles[i].parent1 = &joints[whichjoint]; - while (muscles[i].parent2 == &joints[num_joints - 1] && i < num_muscles)muscles[i].parent2 = &joints[whichjoint]; - } - for (int i = 0; i < num_joints; i++) { - if (joints[i].parent == &joints[whichjoint]) - joints[i].hasparent = 0; - } - for (int i = 0; i < num_joints; i++) { - if (joints[i].parent == &joints[num_joints - 1]) - joints[i].parent = &joints[whichjoint]; - } - - num_joints--; - } -} - -/* EFFECT - * - * USES: - * Skeleton::DeleteJoint - UNUSED - */ -void Skeleton::DeleteMuscle(int whichmuscle) -{ - if (whichmuscle < num_muscles) { - muscles[whichmuscle].minlength = muscles[num_muscles - 1].minlength; - muscles[whichmuscle].maxlength = muscles[num_muscles - 1].maxlength; - muscles[whichmuscle].strength = muscles[num_muscles - 1].strength; - muscles[whichmuscle].parent1 = muscles[num_muscles - 1].parent1; - muscles[whichmuscle].parent2 = muscles[num_muscles - 1].parent2; - muscles[whichmuscle].length = muscles[num_muscles - 1].length; - muscles[whichmuscle].visible = muscles[num_muscles - 1].visible; - muscles[whichmuscle].type = muscles[num_muscles - 1].type; - muscles[whichmuscle].targetlength = muscles[num_muscles - 1].targetlength; - - num_muscles--; - } -} - -/* EFFECT - * - * USES: - * NONE - */ -void Skeleton::SetJoint(float x, float y, float z, int which, int whichjoint) -{ - if (whichjoint < num_joints) { - joints[whichjoint].velocity = 0; - joints[whichjoint].position.x = x; - joints[whichjoint].position.y = y; - joints[whichjoint].position.z = z; - - if (which >= num_joints || which < 0) - joints[whichjoint].hasparent = 0; - if (which < num_joints && which >= 0) { - joints[whichjoint].parent = &joints[which]; - joints[whichjoint].hasparent = 1; - joints[whichjoint].length = findDistance(&joints[whichjoint].position, &joints[whichjoint].parent->position); - } - } -} - -/* EFFECT - * - * USES: - * Skeleton::AddJoint - UNUSED - */ -void Skeleton::AddMuscle(int attach1, int attach2, float minlength, float maxlength, int type) -{ - const int max_muscles = 100; // FIXME: Probably can be dropped - if (num_muscles < max_muscles - 1 && attach1 < num_joints && attach1 >= 0 && attach2 < num_joints && attach2 >= 0 && attach1 != attach2) { - muscles[num_muscles].parent1 = &joints[attach1]; - muscles[num_muscles].parent2 = &joints[attach2]; - muscles[num_muscles].length = findDistance(&muscles[num_muscles].parent1->position, &muscles[num_muscles].parent2->position); - muscles[num_muscles].targetlength = findDistance(&muscles[num_muscles].parent1->position, &muscles[num_muscles].parent2->position); - muscles[num_muscles].strength = .7; - muscles[num_muscles].type = type; - muscles[num_muscles].minlength = minlength; - muscles[num_muscles].maxlength = maxlength; - - num_muscles++; - } -} - -/* EFFECT - * - * USES: - * NONE - */ -void Skeleton::MusclesSet() -{ - for (int i = 0; i < num_muscles; i++) { - muscles[i].length = findDistance(&muscles[i].parent1->position, &muscles[i].parent2->position); - } -} - -/* EFFECT - * - * USES: - * NONE - */ -void Skeleton::DoBalance() -{ - /*XYZ newpoint; - newpoint=joints[0].position; - newpoint.x=(joints[2].position.x+joints[4].position.x)/2; - newpoint.z=(joints[2].position.z+joints[4].position.z)/2; - joints[0].velocity=joints[0].velocity+(newpoint-joints[0].position); - //Move child point to within certain distance of parent point - joints[0].position=newpoint; - - MusclesSet();*/ -} - -#endif -