public void Read(ManeuverType maneuverType, int startTick, QWEASD qweasd, MovementOptions movementOptions) { base.ManeuverType = maneuverType; this.startTick = new Tick(startTick); this.qweasd = qweasd; options = movementOptions; }
public void Read(ManeuverType maneuverType, int startTick, Euler3 direction, MovementOptions movementOptions) { base.ManeuverType = maneuverType; this.startTick = new Tick(startTick); this.direction = direction; options = movementOptions; }
public DirectionalWithoutRollManeuver(ManeuverType maneuverType, int startTick, Euler3 direction, MovementOptions movementOptions) { base.ManeuverType = maneuverType; this.startTick = new Tick(startTick); this.direction = direction; options = movementOptions; }
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); }
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); }
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 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); }
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); }
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 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); }
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); }