#include "config.h" #include #include #include "joint.h" float Joint::S_gravity = GRAVITY; float Joint::S_mass = JOINT_MASS; float Joint::S_world_width = SIZE_WORLD_X; void Joint::OnTimeSlice(float ndt) { //float dx,dy; Spring *s; Vector F; // Move time dt = ndt; t += dt; if (!fixed) { // Apply forces from attached springs for(int i=0;iResultantForce(springwhich[i],dt); #if DEBUG_FORCES cout << "DEBUG_FORCES: Spring #"<< i <<" applies " << F << "N\n"; #endif this->ApplyForce(F); } // Apply gravity F = Vector(270,Joint::Gravity())*Joint::Mass(); this->ApplyForce(F); // Nix the force if starting friction applies if (y==0.0) { float a = force.angle(); if (((a>PI && a<2*PI) || (a<0 && a>-2*PI)) && force.Xvector().magnitude()Translation dx = velocity.x() * dt; dy = velocity.y() * dt; #if DEBUG_MATH cout<<"DEBUG_MATH: dx,dy="<=Joint::WorldWidth()) { x=Joint::WorldWidth(); velocity = velocity.nabsX(); Spring::MuscleFlow(-1); } } void Joint::ApplyForce(float na, float nf) { force += Vector(na,nf); } void Joint::ApplyForce(Vector F) { force += F; } void Joint::ConnectSpring(Spring &s, int i) { if (springcount == JOINT_MAX_SPRINGS) { throw xTooManySprings(); } else { springs[springcount] = &s; springwhich[springcount++] = i; } } Spring *Joint::DisconnectSpring(int s) { Spring *S; if (springcount == 0) { throw xTooManySprings(); } else { S=springs[s]; for(int i=s+1;iConnectSpring(*s,0); s->AddJoint(j.x,j.y,!j.fixed); j.ConnectSpring(*s,1); return s; } void Joint::MoveTo(float nx, float ny) { x=nx; y=ny; for (int i=0; iSet(springwhich[i], x, y); } } void Joint::Fix() { if (!fixed) for (int i=0;iFix(); } fixed = 1; } void Joint::Unfix() { if (fixed) for (int i=0;iUnfix(); } fixed = 0; } Spring *Joint::ConnectedTo(Joint *J) { Spring *S; for(int x=0;xSprings();x++) { S = this->GetSpring(x); if (S->ConnectedJoint(1-this->SpringEnd(x)) == J->index) return S; } return NULL; } /* for (int y=0;ySprings();y++) if (this->GetSpring(x) == J->GetSpring(y)) return this->GetSpring(x); */