2using System.Collections.Generic;
3using System.Globalization;
6using System.Threading.Tasks;
34 private static readonly
Vector2 positiveInfinityVector =
new Vector2(
float.PositiveInfinity,
float.PositiveInfinity);
36 private static readonly
Vector2 negativeInfinityVector =
new Vector2(
float.NegativeInfinity,
float.NegativeInfinity);
42 public float this[
int index]
53 throw new IndexOutOfRangeException(
"Invalid Vector2 index!");
67 throw new IndexOutOfRangeException(
"Invalid Vector2 index!");
151 public void Set(
float newX,
float newY)
166 return new Vector2(a.
x + (b.
x - a.
x) * t, a.
y + (b.
y - a.
y) * t);
177 return new Vector2(a.
x + (b.
x - a.
x) * t, a.
y + (b.
y - a.
y) * t);
188 float num = target.
x - current.
x;
189 float num2 = target.
y - current.
y;
190 float num3 = num * num + num2 * num2;
191 if (num3 == 0f || (maxDistanceDelta >= 0f && num3 <= maxDistanceDelta * maxDistanceDelta))
195 float num4 = (float)Math.Sqrt((
double)num3);
196 return new Vector2(current.
x + num / num4 * maxDistanceDelta, current.
y + num2 / num4 * maxDistanceDelta);
225 if (magnitude > 1
E-05f)
241 return String.Format(
"({0:F4}, {1:F4})",
x,
y);
250 return String.Format(
"({0}, {1})",
x.ToString(format, CultureInfo.InvariantCulture.NumberFormat),
y.ToString(format, CultureInfo.InvariantCulture.NumberFormat));
255 return x.GetHashCode() ^ (
y.GetHashCode() << 2);
262 public override bool Equals(
object other)
273 return x == other.
x &&
y == other.
y;
283 float num = -2f *
Dot(inNormal, inDirection);
284 return new Vector2(num * inNormal.
x + inDirection.
x, num * inNormal.
y + inDirection.
y);
296 return new Vector2(0f - inDirection.
y, inDirection.
x);
306 return lhs.
x * rhs.
x + lhs.
y * rhs.
y;
322 return (
float)Math.Acos((
double)num2) * 57.29578f;
332 float num =
Angle(from, to);
344 float num = a.
x - b.
x;
345 float num2 = a.
y - b.
y;
346 return (
float)Math.Sqrt((
double)(num * num + num2 * num2));
360 float num2 = vector.
x / num;
361 float num3 = vector.
y / num;
362 return new Vector2(num2 * maxLength, num3 * maxLength);
369 return a.
x * a.
x + a.
y * a.
y;
374 return x *
x +
y *
y;
400 return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
406 float maxSpeed =
float.PositiveInfinity;
407 return SmoothDamp(current, target, ref currentVelocity, smoothTime, maxSpeed, deltaTime);
412 smoothTime =
Mathf.
Max(0.0001f, smoothTime);
413 float num = 2f / smoothTime;
414 float num2 = num * deltaTime;
415 float num3 = 1f / (1f + num2 + 0.48f * num2 * num2 + 0.235f * num2 * num2 * num2);
416 float num4 = current.
x - target.
x;
417 float num5 = current.
y - target.
y;
419 float num6 = maxSpeed * smoothTime;
420 float num7 = num6 * num6;
421 float num8 = num4 * num4 + num5 * num5;
424 float num9 = (float)Math.Sqrt((
double)num8);
425 num4 = num4 / num9 * num6;
426 num5 = num5 / num9 * num6;
428 target.
x = current.
x - num4;
429 target.
y = current.
y - num5;
430 float num10 = (currentVelocity.x + num * num4) * deltaTime;
431 float num11 = (currentVelocity.y + num * num5) * deltaTime;
432 currentVelocity.x = (currentVelocity.x - num * num10) * num3;
433 currentVelocity.y = (currentVelocity.y - num * num11) * num3;
434 float num12 = target.
x + (num4 + num10) * num3;
435 float num13 = target.
y + (num5 + num11) * num3;
436 float num14 = vector.
x - current.
x;
437 float num15 = vector.
y - current.
y;
438 float num16 = num12 - vector.
x;
439 float num17 = num13 - vector.
y;
440 if (num14 * num16 + num15 * num17 > 0f)
444 currentVelocity.x = (num12 - vector.
x) / deltaTime;
445 currentVelocity.y = (num13 - vector.
y) / deltaTime;
447 return new Vector2(num12, num13);
492 float num = lhs.
x - rhs.
x;
493 float num2 = lhs.
y - rhs.
y;
494 return num * num + num2 * num2 < 9.99999944E-11f;
499 return !(lhs == rhs);
static float Min(float a, float b)
static float Clamp(float value, float min, float max)
static float Max(float a, float b)
static float Clamp01(float value)
static float Sign(float f)
static float deltaTime
The interval in seconds from the last frame to the current one
const float kEpsilonNormalSqrt
static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed)
void Scale(Vector2 scale)
static Vector2 Scale(Vector2 a, Vector2 b)
static Vector2 Lerp(Vector2 a, Vector2 b, float t)
bool Equals(Vector2 other)
static Vector2 positiveInfinity
static Vector2 Perpendicular(Vector2 inDirection)
static Vector2 ClampMagnitude(Vector2 vector, float maxLength)
string ToString(string format)
static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime)
static float Distance(Vector2 a, Vector2 b)
override bool Equals(object other)
static bool operator==(Vector2 lhs, Vector2 rhs)
override string ToString()
static float SqrMagnitude(Vector2 a)
static float Angle(Vector2 from, Vector2 to)
static Vector2 operator*(Vector2 a, Vector2 b)
static Vector2 SmoothDamp(Vector2 current, Vector2 target, ref Vector2 currentVelocity, float smoothTime, float maxSpeed, float deltaTime)
override int GetHashCode()
static Vector2 MoveTowards(Vector2 current, Vector2 target, float maxDistanceDelta)
static Vector2 negativeInfinity
static Vector2 operator-(Vector2 a, Vector2 b)
static float Dot(Vector2 lhs, Vector2 rhs)
static Vector2 Max(Vector2 lhs, Vector2 rhs)
static Vector2 operator+(Vector2 a, Vector2 b)
static Vector2 LerpUnclamped(Vector2 a, Vector2 b, float t)
Vector2(float x, float y)
static bool operator!=(Vector2 lhs, Vector2 rhs)
static float SignedAngle(Vector2 from, Vector2 to)
static Vector2 Reflect(Vector2 inDirection, Vector2 inNormal)
void Set(float newX, float newY)
static Vector2 Min(Vector2 lhs, Vector2 rhs)
static Vector2 operator/(Vector2 a, Vector2 b)