コード例 #1
0
        public FP Area()
        {
            FP b = Points[0].X - Points[1].X;
            FP h = Points[2].Y - Points[1].Y;

            return(FP.Abs((b * h * 0.5f)));
        }
コード例 #2
0
        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;
                    }
                }
            }
        }