Beispiel #1
0
 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;
 }
Beispiel #2
0
    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;
        }
    }
Beispiel #3
0
 public Spring(float stiffness, float damping, PhysicEntity pEntityA, PhysicEntity pEntityB)
     : this(stiffness, damping, pEntityA, pEntityB, (pEntityA.CurrPosition - pEntityB.CurrPosition).magnitude)
 {
 }
Beispiel #4
0
 public abstract void Process(Vector2 acceleration, PhysicEntity pEntity, float time);
Beispiel #5
0
 public override void Process(Vector2 acceleration, PhysicEntity pEntity, float time)
 {
     pEntity.CurrPosition += pEntity.CurrVelocity * time;
     pEntity.CurrVelocity += acceleration * time;
 }
Beispiel #6
0
 public void AddPhysEnity(PhysicEntity simObject)
 {
     pEntities.Add(simObject);
 }
Beispiel #7
0
 public void ApplyForce(PhysicEntity pEntity)
 {
     pEntity.ResultantForce += pEntity.Mass * acceleration;
 }
Beispiel #8
0
 public void ApplyForce(PhysicEntity pEntity)
 {
     pEntity.ResultantForce += -dragCoefficient * pEntity.CurrVelocity;
 }