diff options
Diffstat (limited to 'src/Skeleton.cpp')
-rw-r--r-- | src/Skeleton.cpp | 65 |
1 files changed, 20 insertions, 45 deletions
diff --git a/src/Skeleton.cpp b/src/Skeleton.cpp index 62861b4..8d5ae3b 100644 --- a/src/Skeleton.cpp +++ b/src/Skeleton.cpp @@ -11,31 +11,13 @@ extern float rad2deg; extern Camera camera; extern float soundscalefactor; -extern XYZ vel; -extern XYZ midp; -extern XYZ newpoint1,newpoint2; - -extern float oldlength; -extern float relaxlength; - -extern float friction; -extern int numrepeats; -extern float groundlevel; -extern float offset; -extern XYZ impact; -extern XYZ overpoint; -extern XYZ underpoint; -extern int whichtri; -extern XYZ normalrotated; -extern bool groundish; - void Joint::DoConstraint() { if(hasparent){ //Find midpoint - midp=(position+parent->position)/2; + XYZ midp = (position + parent->position) / 2; // Find vector from midpoint to second vector - vel = normalize(parent->position - midp); + XYZ vel = normalize(parent->position - midp); //Apply velocity change velocity+=((midp-vel*length/2)-position); parent->velocity+=((midp+vel*length/2)-parent->position); @@ -47,8 +29,8 @@ void Joint::DoConstraint() void Muscle::DoConstraint(int broken) { - oldlength=length; - relaxlength = len(parent1->position - parent2->position); + float oldlength = this->length; + float relaxlength = len(parent1->position - parent2->position); if(type==boneconnect)strength=1; if(type==constraint)strength=0; @@ -66,12 +48,12 @@ void Muscle::DoConstraint(int broken) if(length>maxlength&&!broken)length=maxlength; //Find midpoint - midp=(parent1->position+parent2->position)/2; + XYZ midp = (parent1->position + parent2->position) / 2; // Find vector from midpoint to second vector - vel = normalize(parent2->position - midp); + XYZ vel = normalize(parent2->position - midp); //Apply velocity change - newpoint1=midp-vel*length/2; - newpoint2=midp+vel*length/2; + XYZ newpoint1 = midp - vel * length / 2; + XYZ newpoint2 = midp + vel * length / 2; parent1->velocity+=(newpoint1-parent1->position); parent2->velocity+=(newpoint2-parent2->position); //Move child point to within certain distance of parent point @@ -81,19 +63,15 @@ void Muscle::DoConstraint(int broken) void Skeleton::DoConstraints() { - numrepeats = 3; - for(int i = 0; i < numrepeats; ++i) + for (int i = 0; i < 3; ++i) for (auto& joint : joints) joint.DoConstraint(); } void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) { - friction = 20; move->y += 0.35; - groundlevel = 0; - numrepeats = 2; - for (int j = 0; j < numrepeats; j++) { + for (int j = 0; j < 2; j++) { for (int i = 0; i < max_joints; i++) { if (!joints[i].existing && i != lefthand && i != righthand) continue; @@ -102,11 +80,11 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) joints[i].DoConstraint(); // Ground constraint auto& pos = joints[i].position; - overpoint = pos; + XYZ overpoint = pos; overpoint.y += 10; - underpoint = pos; - underpoint.y -= offset = 0; - whichtri = collide->LineCheck2(overpoint, underpoint, + XYZ underpoint = pos; + XYZ impact; + int whichtri = collide->LineCheck2(overpoint, underpoint, &impact, *move, rotation); if (whichtri == -1 || collide->normals[whichtri].y <= 0.8) @@ -114,25 +92,22 @@ void Skeleton::DoConstraints(Model *collide, XYZ *move, float rotation) joints[i].realoldposition, pos, &impact, *move, rotation); - if (pos.y <= groundlevel + offset || whichtri != -1) { + if (pos.y <= 0 || whichtri != -1) { if (whichtri == -1 || collide->normals[whichtri].y > 0.8) { - if (whichtri == -1) { - pos.y = groundlevel + offset; - } else { + if (whichtri == -1) + pos.y = 0; + else pos = impact; - pos.y += offset; - } joints[i].velocity.y *= -0.3; joints[i].velocity.x *= 0.3; joints[i].velocity.z *= 0.3; } - offset = true; if (whichtri != -1 && collide->normals[whichtri].y <= 0.8) { - normalrotated = rotate(collide->normals[whichtri], 0, rotation, 0); - pos = impact + normalrotated * offset; + XYZ normalrotated = rotate(collide->normals[whichtri], 0, rotation, 0); + pos = impact + normalrotated; reflect(&joints[i].velocity, normalrotated); joints[i].velocity *= 0.3; } |