예제 #1
0
        private void UpdateForce(RigidBody body, RigidBody other, Vector3d connection, Vector3d otherConnection, double dt)
        {
            if (body.HasInfiniteMass)
            {
                return;
            }

            // Calculate the two ends in world space
            Vector3d lws = body.GetPointInWorldSpace(connection);
            Vector3d ows = other.GetPointInWorldSpace(otherConnection);

            // Calculate the vector of the spring
            Vector3d force = lws - ows;

            // Calculate the magnitude of the force
            double magnitude = force.Magnitude;

            // Calculate the magnitude of the force
            magnitude = (m_restLength - magnitude) * m_springConstant;

            // Calculate the final force and apply it
            force.Normalize();
            force *= magnitude;
            body.AddForceAtPoint(force, lws);
        }
예제 #2
0
 public override void UpdateForce(RigidBody body, float duration)
 {
     Vector3 lws = body.GetPointInWorldSpace(ConnectionPoint);
     Vector3 ows = body.GetPointInWorldSpace(OtherConnectionPoint);
     Vector3 force = lws - ows;
     float magnitude = force.Magnitude;
     magnitude = MathHelper.Abs(magnitude - RestLength);
     magnitude *= SpringConstant;
     force.Normalize();
     force *= -magnitude;
     body.AddForceAtPoint(force, lws);
 }