public override void Update(FP dt)
        {
            foreach (Body body in _bodies)
            {
                if (!IsActiveOn(body))
                {
                    continue;
                }

                if (LimitLinearVelocity)
                {
                    //Translation
                    // Check for large velocities.
                    FP translationX = dt * body._linearVelocity.x;
                    FP translationY = dt * body._linearVelocity.y;
                    FP result       = translationX * translationX + translationY * translationY;

                    if (result > dt * _maxLinearSqared)
                    {
                        FP sq = FP.Sqrt(result);

                        FP ratio = _maxLinearVelocity / sq;
                        body._linearVelocity.x *= ratio;
                        body._linearVelocity.y *= ratio;
                    }
                }

                if (LimitAngularVelocity)
                {
                    //Rotation
                    FP rotation = dt * body._angularVelocity;
                    if (rotation * rotation > _maxAngularSqared)
                    {
                        FP ratio = _maxAngularVelocity / FP.Abs(rotation);
                        body._angularVelocity *= ratio;
                    }
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Friction mixing law. Feel free to customize this.
 /// </summary>
 /// <param name="friction1">The friction1.</param>
 /// <param name="friction2">The friction2.</param>
 /// <returns></returns>
 public static FP MixFriction(FP friction1, FP friction2)
 {
     return(FP.Sqrt(friction1 * friction2));
 }