Exemple #1
0
        public void ComputeForce()
        {
            var dist               = (P2.Position - P1.Position);                     //e* //e* = r2 - r1
            var e                  = dist / dist.magnitude;                           //e = e* / l  //l = e*.magnitude
            var p1V1D              = Vector3.Dot(e, P1.Velocity);                     //p1's 1D vector  //v1 = e dot v1
            var p2V1D              = Vector3.Dot(e, P2.Velocity);                     //p2's 1D vector  //v2 = e dot v2
            var springForceLinear  = -SpringConstant * (RestLength - dist.magnitude); //fs //fs = -ks(lo - l)
            var dampingForceLinear = -DampingFactor * (p1V1D - p2V1D);                //fd //fd = -kd(v1 - v2)
            var springDampingForce = (springForceLinear + dampingForceLinear) * e;    //fsd = -ks(lo - l) -kd(v1 - v2) //times e for f1

            P1.AddForce(springDampingForce);                                          //f1 //positive value
            P2.AddForce(-springDampingForce);                                         //f2 //-f1
        }