Пример #1
0
        protected virtual void HandleRotation()
        {
            // Acceleration affects rotation.
            // float aAcceleration = acceleration.X / (10.0f * Mass);
            // exAngSpeed.Value += aAcceleration;

            // Angular friction:

            if (friction)
            {
                float aFriction = mew * -1.0f * exAngSpeed.Value;
                exAngSpeed.Value += aFriction;
            }

            if (exAngSpeed.CloseToZero(exAngSpeed.Value))
            {
                exAngSpeed.Value = 0.0f;
            }

            aVelocity        = exAngSpeed.Value;
            exAngSpeed.Value = exAngSpeed.Clamp(exAngSpeed.Value);
            aVelocity        = exAngSpeed.Clamp(aVelocity);
            rotation        += aVelocity * delta;

            rotation = MathHelper.WrapAngle(rotation);
        }
Пример #2
0
        // Clamp the velocity.
        private void ClampVelocity()
        {
            if (IsEmpty(velocity))
            {
                this.velocity = new Vector2(0f, 0f); return;
            }

            // Clamp the vector.
            float mag = exSpeed.Clamp(velocity.Length()); // Auto-clamps value.

            if (exSpeed.CloseToZero(mag))
            {
                velocity = new Vector2(0, 0);
            }
            else
            {
                velocity.Normalize();
                velocity *= mag;
            }
        }
Пример #3
0
        // Clamp the acceleration.
        private void ClampAcceleration()
        {
            if (IsEmpty(acceleration))
            {
                this.acceleration = new Vector2(0f, 0f); return;
            }

            // Clamp the vector.
            float mag = exAcc.Clamp(acceleration.Length()); // Auto-clamps value.

            accelerationTrack = Vector2.Multiply(Vector2.Normalize(acceleration), mag);

            if (exAcc.CloseToZero(mag))
            {
                acceleration = new Vector2(0, 0);
            }
            else
            {
                acceleration.Normalize();
                acceleration *= mag;
            }
        }