Ejemplo n.º 1
0
        public void ApplyForce(SimObject simObject)
        {
            //get the direction vector
            direction = simObjectA.CurrPosition - simObjectB.CurrPosition;

            //check for zero vector
            if (direction != Vector3.Zero)
            {
                //get length
                currLength = direction.Length();

                //normalize
                direction.Normalize();

                //add spring force
                force = -stiffness * ((currLength - restLength) * direction);

                //add spring damping force
                force += -damping * Vector3.Dot(simObjectA.CurrVelocity - simObjectB.CurrVelocity, direction) * direction;

                //apply the equal and opposite forces to the objects
                simObjectA.ResultantForce += force;
                simObjectB.ResultantForce += -force;
            }
        }
        public override void Integrate(Vector3 acceleration, SimObject simObject)
        {
            //calculate new position using the velocity at current time
            simObject.CurrPosition += simObject.CurrVelocity * fixedTimeStep;

            //calculate new velocity using the acceleration at current time
            simObject.CurrVelocity += acceleration * fixedTimeStep;
        }
        public override void Integrate(Vector3 acceleration, SimObject simObject)
        {
            newPosition = (2 - drag) * simObject.CurrPosition
                - (1 - drag) * simObject.PrevPosition
                + acceleration * fixedTimeStep * fixedTimeStep;

            simObject.PrevPosition = simObject.CurrPosition;
            simObject.CurrPosition = newPosition;
        }
Ejemplo n.º 4
0
 public Spring(float stiffness, float damping, SimObject simObjectA, SimObject simObjectB, float restLength)
     : base()
 {
     this.stiffness = stiffness;
     this.damping = damping;
     this.simObjectA = simObjectA;
     this.simObjectB = simObjectB;
     this.restLength = restLength;
 }
 public void AddSpring(float stiffness, float damping, SimObject simObjA, SimObject simObjB)
 {
     Spring spring = new Spring(stiffness, damping, simObjA, simObjB);
     springs.Add(spring);
 }
 public void AddSimObject(SimObject simObject)
 {
     simObjects.Add(simObject);
 }
 //------------------------------------------------------------
 public LengthConstraint(float length, SimObject simObj1, SimObject simObj2)
 {
     this.length = length;
     this.simObj1 = simObj1;
     this.simObj2 = simObj2;
 }
Ejemplo n.º 8
0
 public void ApplyForce(SimObject simObject)
 {
     simObject.ResultantForce += simObject.Mass * acceleration;
 }
 public abstract void Integrate(Vector3 acceleration, SimObject simObject);
Ejemplo n.º 10
0
 public void ApplyForce(SimObject simObject)
 {
     simObject.ResultantForce += - dragCoefficient * simObject.CurrVelocity;
 }
 //------------------------------------------------------
 public PointConstraint(Vector3 point, SimObject simObject)
 {
     this.point = point;
     this.simObject = simObject;
 }
Ejemplo n.º 12
0
 //-----------------------------------------------------------
 public Spring(float stiffness, float damping, SimObject simObjectA, SimObject simObjectB)
     : this(stiffness, damping, simObjectA, simObjectB, (simObjectA.CurrPosition - simObjectB.CurrPosition).Length())
 {
 }