public float MaxYawSpeed(float roll, float pitch)
        {
            float num  = 0f - Mathf.Clamp(Algorithm3D.NormalizeAngle(roll) / maxRoll, -1f, 1f);
            float num2 = Mathf.Lerp(minYawSpeed, yawMaxSpeed, (num + 1f) / 2f);

            return(num2 * (1f + Mathf.Abs(Algorithm3D.NormalizeAngle(pitch)) * 1f / 90f));
        }
Пример #2
0
        public static MovementFrame MoveToDirection(MovementFrame prevFrame, Euler3 targetEuler3, MovementOptions options)
        {
            Euler3 euler  = prevFrame.euler3;
            Euler3 to     = options.MaxEulerSpeed(euler);
            Euler3 from   = options.MinEulerSpeed(euler);
            Euler3 euler2 = (targetEuler3 - euler).Normalized(false);
            float  num    = Mathf.Abs(2f * euler2.pitch / options.pitchAcceleration);
            float  num2   = Mathf.Abs(2f * euler2.yaw / options.yawAcceleration);
            float  num3   = 0f;

            if (euler2.yaw > Mathf.Epsilon)
            {
                num3 = options.yawAcceleration * num2;
            }
            else if (euler2.yaw < 0f - Mathf.Epsilon)
            {
                num3 = (0f - options.yawAcceleration) * num2;
            }
            float num4 = 0f;

            if (euler2.pitch > Mathf.Epsilon)
            {
                num4 = options.pitchAcceleration * num;
            }
            else if (euler2.pitch < 0f - Mathf.Epsilon)
            {
                num4 = (0f - options.pitchAcceleration) * num;
            }
            Euler3 zero = Euler3.zero;

            zero.yaw   = (num3 - prevFrame.Euler3Speed.yaw) / 0.1f;
            zero.pitch = (num4 - prevFrame.Euler3Speed.pitch) / 0.1f;
            float num5 = Mathf.Clamp((0f - euler2.yaw) * options.maxRoll / 135f, 0f - options.maxRoll, options.maxRoll);
            float num6 = Algorithm3D.NormalizeAngle(num5 - euler.roll);

            zero.roll = options.rollAcceleration * (num6 / options.maxRoll - prevFrame.Euler3Speed.roll * options.rollFading / options.rollMaxSpeed);
            zero.Clamp(-options.maxTurnAcceleration, options.maxTurnAcceleration);
            Euler3 euler3Speed = prevFrame.Euler3Speed + zero * 0.1f;

            euler3Speed.Clamp(from, to);
            Vector3       linearSpeed   = AdvanceLinearSpeed(prevFrame, options);
            Vector3       strafeSpeed   = AdvanceStrafingSpeed(prevFrame, options, 0f, 0f);
            Euler3        nextEuler     = prevFrame.NextEuler3;
            MovementFrame result        = new MovementFrame(prevFrame.nextPosition, nextEuler, linearSpeed, strafeSpeed, euler3Speed);
            Quaternion    rotationDelta = nextEuler.rotation * Quaternion.Inverse(prevFrame.rotation) * Quaternion.identity;

            //result.ActiveThrusterEffects = DetermineThrusterEffects(rotationDelta, 0f, 0f);
            result.mode = 0;
            return(result);
        }
Пример #3
0
        public static MovementFrame WASD(MovementFrame prevFrame, int pitch, int yaw, int roll, MovementOptions options)
        {
            Euler3 euler = prevFrame.euler3;
            Euler3 to    = options.MaxEulerSpeed(euler);
            Euler3 from  = options.MinEulerSpeed(euler);
            float  num   = 0f;

            if (yaw > 0)
            {
                num = 0f - options.maxRoll;
            }
            if (yaw < 0)
            {
                num = options.maxRoll;
            }
            float  num2 = Algorithm3D.NormalizeAngle(num - euler.roll);
            Euler3 zero = Euler3.zero;

            zero.roll = options.rollAcceleration * (num2 / options.maxRoll - prevFrame.Euler3Speed.roll * options.rollFading / options.rollMaxSpeed);
            if (yaw != 0)
            {
                zero.yaw = (float)yaw * options.yawAcceleration;
            }
            else if (prevFrame.Euler3Speed.yaw > Mathf.Epsilon)
            {
                zero.yaw = (0f - options.yawAcceleration) * options.yawFading;
                from.yaw = 0f;
            }
            else if (prevFrame.Euler3Speed.yaw < 0f - Mathf.Epsilon)
            {
                zero.yaw = options.yawAcceleration * options.yawFading;
                to.yaw   = 0f;
            }
            if (pitch != 0)
            {
                zero.pitch = (float)pitch * options.pitchAcceleration;
            }
            else if (prevFrame.Euler3Speed.pitch > Mathf.Epsilon)
            {
                zero.pitch = (0f - options.pitchAcceleration) * options.pitchFading;
                from.pitch = 0f;
            }
            else if (prevFrame.Euler3Speed.pitch < 0f - Mathf.Epsilon)
            {
                zero.pitch = options.pitchAcceleration * options.pitchFading;
                to.pitch   = 0f;
            }
            Euler3 euler3Speed = prevFrame.Euler3Speed + zero * 0.1f;

            euler3Speed.Clamp(from, to);
            Vector3       linearSpeed   = AdvanceLinearSpeed(prevFrame, options);
            Vector3       strafeSpeed   = AdvanceStrafingSpeed(prevFrame, options, 0f, 0f);
            Euler3        nextEuler     = prevFrame.NextEuler3;
            MovementFrame result        = new MovementFrame(prevFrame.nextPosition, nextEuler, linearSpeed, strafeSpeed, euler3Speed);
            Quaternion    rotationDelta = nextEuler.rotation * Quaternion.Inverse(prevFrame.rotation) * Quaternion.identity;

            //result.ActiveThrusterEffects = DetermineThrusterEffects(rotationDelta, 0f, 0f);
            if (pitch != 0)
            {
                result.mode = 1;
            }
            return(result);
        }