BEPUphysics.Vehicle.WheelShape.UpdateSpin C# (CSharp) Метод

UpdateSpin() приватный Метод

Updates the spin velocity and spin angle for the shape.
private UpdateSpin ( float dt ) : void
dt float Simulation timestep.
Результат void
        internal void UpdateSpin(float dt)
        {
            if (wheel.HasSupport && !(wheel.brake.IsBraking && FreezeWheelsWhileBraking))
            {
                //On the ground, not braking.
                spinVelocity = wheel.drivingMotor.RelativeVelocity / Radius;
            }
            else if (wheel.HasSupport && wheel.brake.IsBraking && FreezeWheelsWhileBraking)
            {
                //On the ground, braking
                float deceleratedValue = 0;
                if (spinVelocity > 0)
                    deceleratedValue = Math.Max(spinVelocity - brakeFreezeWheelDeceleration * dt, 0);
                else if (spinVelocity < 0)
                    deceleratedValue = Math.Min(spinVelocity + brakeFreezeWheelDeceleration * dt, 0);

                spinVelocity = wheel.drivingMotor.RelativeVelocity / Radius;

                if (Math.Abs(deceleratedValue) < Math.Abs(spinVelocity))
                    spinVelocity = deceleratedValue;
            }
            else if (!wheel.HasSupport && wheel.drivingMotor.TargetSpeed != 0)
            {
                //Airborne and accelerating, increase spin velocity.
                float maxSpeed = Math.Abs(wheel.drivingMotor.TargetSpeed) / Radius;
                spinVelocity = MathHelper.Clamp(spinVelocity + Math.Sign(wheel.drivingMotor.TargetSpeed) * airborneWheelAcceleration * dt, -maxSpeed, maxSpeed);
            }
            else if (!wheel.HasSupport && wheel.Brake.IsBraking)
            {
                //Airborne and braking
                if (spinVelocity > 0)
                    spinVelocity = Math.Max(spinVelocity - brakeFreezeWheelDeceleration * dt, 0);
                else if (spinVelocity < 0)
                    spinVelocity = Math.Min(spinVelocity + brakeFreezeWheelDeceleration * dt, 0);
            }
            else if (!wheel.HasSupport)
            {
                //Just idly slowing down.
                if (spinVelocity > 0)
                    spinVelocity = Math.Max(spinVelocity - airborneWheelDeceleration * dt, 0);
                else if (spinVelocity < 0)
                    spinVelocity = Math.Min(spinVelocity + airborneWheelDeceleration * dt, 0);
            }
            spinAngle += spinVelocity * dt;
        }

Usage Example

Пример #1
0
 internal void UpdateAtEndOfUpdate(float dt)
 {
     shape.UpdateSpin(dt);
 }
All Usage Examples Of BEPUphysics.Vehicle.WheelShape::UpdateSpin