예제 #1
0
        private void BuildFrame(Tick tick, out MovementFrame frame)
        {
            frame = MovementFrame.Invalid;
            Stack <Maneuver> stack = GetManeuvers(tick);

            if (stack == null)
            {
                frame.valid = false;
                return;
            }
            Maneuver      maneuver = stack.Pop();
            MovementFrame frame2   = GetTickFrame(tick - 1);

            if (!frame2.valid && tick > oldTick)
            {
                BuildFrame(tick - 1, out frame2);
            }
            frame2.valid = true;
            frame        = maneuver.NextFrame(tick, frame2);
            Vector3 position = frame.position;
            Euler3  euler    = frame.euler3;

            foreach (Maneuver item in stack)
            {
                frame = item.NextFrame(tick, frame);
            }
            frame.position = position;
            frame.euler3   = euler;
        }
예제 #2
0
 protected MovementFrame MoveToDirection(MovementFrame prevFrame, Euler3 direction)
 {
     if (!prevFrame.valid)
     {
         return(MovementFrame.Invalid);
     }
     return(Simulation.MoveToDirection(prevFrame, direction, options));
 }
예제 #3
0
 protected MovementFrame Drift(MovementFrame prevFrame)
 {
     if (!prevFrame.valid)
     {
         return(MovementFrame.Invalid);
     }
     return(Simulation.WASD(prevFrame, 0, 0, 0, options));
 }
 public override MovementFrame NextFrame(Tick tick, MovementFrame prevFrame)
 {
     if (!prevFrame.valid)
     {
         return(MovementFrame.Invalid);
     }
     if (qweasd == null)
     {
         qweasd = new QWEASD();
     }
     return(Simulation.QWEASD(prevFrame, qweasd.Pitch, qweasd.Yaw, qweasd.Roll, options));
 }
예제 #5
0
        private static MovementFrame InvalidFrame()
        {
            MovementFrame result = default(MovementFrame);

            result.position    = Vector3.zero;
            result.linearSpeed = Vector3.zero;
            result.Euler3Speed = Euler3.zero;
            result.euler3      = Euler3.identity;
            result.mode        = 0;
            result.valid       = false;
            return(result);
        }
예제 #6
0
        public void AddSyncFrame(Tick tick, MovementFrame frame)
        {
            int num = TickIndex(tick);

            if (num >= 0 && num < 5)
            {
                frames[num] = frame;
            }
            if (num >= 4)
            {
                syncFrames[tick] = frame;
            }
        }
예제 #7
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);
        }
예제 #8
0
        public static Vector3 AdvanceStrafingSpeed(MovementFrame prevFrame, MovementOptions options, float strafeX, float strafeY)
        {
            Vector3 strafeSpeed = prevFrame.strafeSpeed;

            strafeX = Mathf.Clamp(strafeX, -1f, 1f);
            strafeY = Mathf.Clamp(strafeY, -1f, 1f);
            Vector3 point = Quaternion.Inverse(prevFrame.rotation) * strafeSpeed;
            float   num   = strafeX * options.strafeMaxSpeed;
            float   num2  = strafeY * options.strafeMaxSpeed;

            point.x = GetNewSpeed(point.x, num, (float)((!(point.x * num < -1f)) ? 1 : 2) * options.strafeAcceleration);
            point.y = GetNewSpeed(point.y, num2, (float)((!(point.y * num2 < -1f)) ? 1 : 2) * options.strafeAcceleration);
            point.z = GetNewSpeed(point.z, 0f, options.strafeAcceleration);
            return(prevFrame.rotation * point);
        }
예제 #9
0
        public static Vector3 AdvanceLinearSpeed(MovementFrame prevFrame, MovementOptions options)
        {
            Vector3 linearSpeed = prevFrame.linearSpeed;
            Vector3 result      = linearSpeed;

            if (options.gear != Gear.RCS)
            {
                Vector3 direction = prevFrame.euler3.direction;
                float   num       = Vector3.Dot(direction, linearSpeed);
                Vector3 b         = direction * num;
                Vector3 vector    = linearSpeed - b;
                float   magnitude = vector.magnitude;
                Vector3 a         = vector.normalized * GetNewSpeed(magnitude, 0f, options.inertiaCompensation);
                Vector3 b2        = direction * GetNewSpeed(num, options.speed, options.acceleration);
                result = a + b2;
            }
            return(result);
        }
예제 #10
0
        public static MovementFrame QWEASD(MovementFrame prevFrame, float pitch, float yaw, float roll, MovementOptions options)
        {
            Vector3 vector = new Vector3(pitch, yaw, roll);
            Vector3 b      = (options.maxTurnAcceleration * 0.1f).ComponentsToVector3();

            vector = Vector3.Scale(vector, b);
            Vector3 vector2 = prevFrame.Euler3Speed.ComponentsToVector3();

            if (true)
            {
                Vector3 vector3 = Quaternion.Inverse(prevFrame.rotation) * vector2;
                if (vector.x == 0f)
                {
                    vector.x = SlowingThrust(vector3.x, b.x);
                }
                if (vector.y == 0f)
                {
                    vector.y = SlowingThrust(vector3.y, b.y);
                }
                if (vector.z == 0f)
                {
                    vector.z = SlowingThrust(vector3.z, b.z);
                }
            }
            Vector3 b2 = prevFrame.rotation * vector;
            Vector3 v  = vector2 + b2;

            vector2 = ClampToRotatedBox(v, options.maxTurnSpeed.ComponentsToVector3(), prevFrame.rotation);
            Euler3 euler3Speed = default(Euler3);

            euler3Speed.ComponentsFromVector3(vector2);
            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);

            result.mode = 2;
            Quaternion rotationDelta = nextEuler.rotation * Quaternion.Inverse(prevFrame.rotation) * Quaternion.identity;

            //result.ActiveThrusterEffects = DetermineThrusterEffects(rotationDelta, 0f, 0f);
            return(result);
        }
예제 #11
0
        public static MovementFrame MoveToDirectionWithoutRoll(MovementFrame prevFrame, Euler3 targetEuler3, MovementOptions options)
        {
            Quaternion    rotation        = prevFrame.Euler3Speed.rotation;
            Quaternion    q               = Quaternion.FromToRotation(prevFrame.euler3.direction, targetEuler3.direction);
            Quaternion    lhs             = ScaleWithMax(q, 2f, options.yawMaxSpeed);
            Quaternion    q2              = lhs * Quaternion.Inverse(rotation);
            Quaternion    to              = ScaleWithMax(q2, 8f, options.yawAcceleration);
            Quaternion    changePerSecond = Quaternion.RotateTowards(Quaternion.identity, to, options.yawAcceleration);
            Quaternion    to2             = Euler3.RotateOverTime(rotation, changePerSecond, 0.1f);
            Quaternion    quat            = Quaternion.RotateTowards(Quaternion.identity, to2, options.yawMaxSpeed);
            Euler3        euler3Speed     = Euler3.Rotation(quat);
            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);

            result.mode = 2;
            Quaternion rotationDelta = nextEuler.rotation * Quaternion.Inverse(prevFrame.rotation) * Quaternion.identity;

            //result.ActiveThrusterEffects = DetermineThrusterEffects(rotationDelta, 0f, 0f);
            return(result);
        }
예제 #12
0
        public static MovementFrame TurnByPitchYawStrikes(MovementFrame prevFrame, Vector3 pitchYawRollFactor, Vector3 strafeDirection, float strafeMagnitude, MovementOptions options)
        {
            Vector3    a            = options.maxTurnAcceleration.ComponentsToVector3();
            Vector3    scale        = options.maxTurnSpeed.ComponentsToVector3();
            Vector3    nextPosition = prevFrame.nextPosition;
            Euler3     nextEuler    = prevFrame.NextEuler3;
            Quaternion rotation     = nextEuler.rotation;

            ClampVectorComponents(ref pitchYawRollFactor, -1, 1);
            Vector3    linearSpeed = AdvanceLinearSpeed(prevFrame, options);
            float      strafeX     = strafeDirection.x * strafeMagnitude;
            float      strafeY     = strafeDirection.y * strafeMagnitude;
            Vector3    strafeSpeed = AdvanceStrafingSpeed(prevFrame, options, strafeX, strafeY);
            Quaternion rotation2   = Quaternion.Inverse(rotation);
            Vector3    vector      = rotation2 * prevFrame.Euler3Speed.ComponentsToVector3();
            Vector3    a2          = pitchYawRollFactor;

            a2.Scale(scale);
            Vector3 vec     = a2 - vector;
            Vector3 vector2 = a * 0.1f;

            ClampVectorComponents(ref vec, -vector2, vector2);
            Vector3 vector3 = vector;

            vector3 += vec;
            if (Mathf.Abs(pitchYawRollFactor.z) < 0.01f)
            {
                vector3.z = GetNewSpeed(vector3.z, 0f, options.rollAcceleration);
            }
            Vector3       vector4 = rotation * vector3;
            MovementFrame result  = new MovementFrame(euler3Speed: new Euler3(vector4.x, vector4.y, vector4.z), position: nextPosition, euler3: nextEuler, linearSpeed: linearSpeed, strafeSpeed: strafeSpeed);

            result.mode = 2;
            Quaternion rotationDelta = rotation * Quaternion.Inverse(prevFrame.rotation) * Quaternion.identity;

            //result.ActiveThrusterEffects = DetermineThrusterEffects(rotationDelta, strafeX, strafeY);
            return(result);
        }
 public override MovementFrame NextFrame(Tick tick, MovementFrame prevFrame)
 {
     return(MoveToDirection(prevFrame, direction));
 }
예제 #14
0
 public override MovementFrame NextFrame(Tick tick, MovementFrame prevFrame)
 {
     return(new MovementFrame(position, euler3, Vector3.zero, Vector3.zero, Euler3.zero));
 }
예제 #15
0
 public abstract MovementFrame NextFrame(Tick tick, MovementFrame prevFrame);
예제 #16
0
        public static MovementFrame TurnToDirectionStrikes(MovementFrame prevFrame, Euler3 targetEuler3, float roll, float strafeX, float strafeY, MovementOptions options)
        {
            Vector3    vector       = options.maxTurnAcceleration.ComponentsToVector3();
            Vector3    a            = FindDamping(vector, options.maxTurnSpeed.ComponentsToVector3());
            float      d            = 3f;
            Vector3    vector2      = options.maxTurnSpeed.ComponentsToVector3();
            Vector3    nextPosition = prevFrame.nextPosition;
            Euler3     nextEuler    = prevFrame.NextEuler3;
            Quaternion rotation     = nextEuler.rotation;
            Vector3    point        = targetEuler3.rotation * Vector3.forward;

            roll = Mathf.Clamp(roll, -1f, 1f);
            Vector3    linearSpeed = AdvanceLinearSpeed(prevFrame, options);
            Quaternion rotation2   = Quaternion.Inverse(rotation);
            Vector3    toDirection = rotation2 * point;
            Vector3    vector3     = rotation2 * prevFrame.Euler3Speed.ComponentsToVector3();
            Vector3    eulerAngles = Quaternion.FromToRotation(Vector3.forward, toDirection).eulerAngles;

            eulerAngles = KeepVectorComponentsWithinPlusMinus180(eulerAngles);
            Vector3 a2      = FindVelocityForRotationDelta(eulerAngles, a * d);
            Vector3 scale   = Vector3.one - a * 0.1f;
            Vector3 vector4 = vector3;

            vector4.Scale(scale);
            Vector3 scale2  = Vector3.one - a * d * 0.1f;
            Vector3 vector5 = vector3;

            vector5.Scale(scale2);
            bool flag  = false;
            bool flag2 = false;

            if (Mathf.Abs(vector4.x) > Mathf.Abs(a2.x))
            {
                scale.x = Mathf.Max(scale2.x, a2.x / vector3.x);
                flag    = true;
            }
            if (Mathf.Abs(vector4.y) > Mathf.Abs(a2.y))
            {
                scale.y = Mathf.Max(scale2.y, a2.y / vector3.y);
                flag2   = true;
            }
            vector3.Scale(scale);
            Vector3 a3     = ScalePitchYawSoThatOneOfThemHasLengthOneAndSetZToZero(eulerAngles);
            Vector3 scale3 = vector;

            a3.Scale(scale3);
            Vector3 vector6 = a2 - vector3;

            if (Mathf.Abs(a3.x) > Mathf.Abs(vector6.x))
            {
                a3.x = vector6.x;
            }
            if (Mathf.Abs(a3.y) > Mathf.Abs(vector6.y))
            {
                a3.y = vector6.y;
            }
            if (flag)
            {
                a3.x = 0f;
            }
            if (flag2)
            {
                a3.y = 0f;
            }
            float num = vector.z * roll;

            vector3.z += num * 0.1f;
            Vector3 val = vector3 + a3 * 0.1f;

            val = Clamp(val, -vector2, vector2);
            Vector3       point2      = val;
            Vector3       vector7     = rotation * point2;
            Euler3        euler3Speed = new Euler3(vector7.x, vector7.y, vector7.z);
            Vector3       strafeSpeed = AdvanceStrafingSpeed(prevFrame, options, 0f, 0f);
            MovementFrame result      = new MovementFrame(nextPosition, nextEuler, linearSpeed, strafeSpeed, euler3Speed);

            result.mode = 2;
            Quaternion rotationDelta = rotation * Quaternion.Inverse(prevFrame.rotation) * Quaternion.identity;

            //result.ActiveThrusterEffects = DetermineThrusterEffects(rotationDelta, strafeX, strafeY);
            return(result);
        }
예제 #17
0
 private bool GetFrame(Tick prevTick, float dt, out Vector3 position, out Quaternion rotation, out float speed, out Vector3 strafingSpeed, out MovementFrame frame)
 {
     frame         = GetTickFrame(prevTick);
     position      = frame.GetFuturePosition(dt);
     rotation      = frame.GetFutureRotation(dt);
     speed         = frame.linearSpeed.magnitude;
     strafingSpeed = frame.strafeSpeed;
     return(frame.valid);
 }
예제 #18
0
        public bool GetFrameFromOldFrame(double time, out Vector3 position, out Quaternion rotation, out float speed, out Vector3 strafingSpeed, out MovementFrame frame)
        {
            Tick  prevTick = Tick.Previous(time - 0.10000000149011612);
            float dt       = (float)(time - prevTick.Time);

            return(GetFrame(prevTick, dt, out position, out rotation, out speed, out strafingSpeed, out frame));
        }
예제 #19
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);
        }
 public override MovementFrame NextFrame(Tick tick, MovementFrame prevFrame)
 {
     return(Simulation.MoveToDirectionWithoutRoll(prevFrame, direction, options));
 }