public Spring(float stiffness, float damping, PhysicEntity pEntityA, PhysicEntity pEntityB, float restLength) : base() { this.stiffness = stiffness; this.damping = damping; this.pEntityA = pEntityA; this.pEntityB = pEntityB; this.restLength = restLength; }
public void ApplyForce(PhysicEntity pEntity = null) { //get the direction vector direction = pEntityA.CurrPosition - pEntityB.CurrPosition; //check for zero vector if (direction != Vector2.zero) { //get length currLength = direction.magnitude; //normalize direction.Normalize(); //add spring force force = -stiffness * ((currLength - restLength) * direction); //add spring damping force force += -damping *Vector2.Dot(pEntityA.CurrVelocity - pEntityB.CurrVelocity, direction) * direction; //apply the equal and opposite forces to the objects pEntityA.ResultantForce += force; pEntityB.ResultantForce += -force; } }
public Spring(float stiffness, float damping, PhysicEntity pEntityA, PhysicEntity pEntityB) : this(stiffness, damping, pEntityA, pEntityB, (pEntityA.CurrPosition - pEntityB.CurrPosition).magnitude) { }
public abstract void Process(Vector2 acceleration, PhysicEntity pEntity, float time);
public override void Process(Vector2 acceleration, PhysicEntity pEntity, float time) { pEntity.CurrPosition += pEntity.CurrVelocity * time; pEntity.CurrVelocity += acceleration * time; }
public void AddPhysEnity(PhysicEntity simObject) { pEntities.Add(simObject); }
public void ApplyForce(PhysicEntity pEntity) { pEntity.ResultantForce += pEntity.Mass * acceleration; }
public void ApplyForce(PhysicEntity pEntity) { pEntity.ResultantForce += -dragCoefficient * pEntity.CurrVelocity; }