2using System.Runtime.CompilerServices;
27 return new Quaternion(lhs.
w * rhs.
x + lhs.
x * rhs.
w + lhs.
y * rhs.
z - lhs.
z * rhs.
y, lhs.
w * rhs.
y + lhs.
y * rhs.
w + lhs.
z * rhs.
x - lhs.
x * rhs.
z, lhs.
w * rhs.
z + lhs.
z * rhs.
w + lhs.
x * rhs.
y - lhs.
y * rhs.
x, lhs.
w * rhs.
w - lhs.
x * rhs.
x - lhs.
y * rhs.
y - lhs.
z * rhs.
z);
32 float num = rotation.
x * 2f;
33 float num2 = rotation.
y * 2f;
34 float num3 = rotation.
z * 2f;
35 float num4 = rotation.
x * num;
36 float num5 = rotation.
y * num2;
37 float num6 = rotation.
z * num3;
38 float num7 = rotation.
x * num2;
39 float num8 = rotation.
x * num3;
40 float num9 = rotation.
y * num3;
41 float num10 = rotation.
w * num;
42 float num11 = rotation.
w * num2;
43 float num12 = rotation.
w * num3;
45 result.
x = (1f - (num5 + num6)) * point.
x + (num7 - num12) * point.
y + (num8 + num11) * point.
z;
46 result.
y = (num7 + num12) * point.
x + (1f - (num4 + num6)) * point.
y + (num9 - num10) * point.
z;
47 result.
z = (num8 - num11) * point.
x + (num9 + num10) * point.
y + (1f - (num4 + num5)) * point.
z;
62 private static bool IsEqualUsingDot(
float dot)
71 return IsEqualUsingDot(
Dot(lhs, rhs));
84 return a.
x * b.
x + a.
y * b.
y + a.
z * b.
z + a.
w * b.
w;
89 INTERNAL_Euler(ref angles, out
Quaternion value);
102 INTERNAL_AngleAxis(angle, ref axis, out
Quaternion ret);
108 INTERNAL_LookRotation(ref direction, out
Quaternion ret);
114 public void Set(
float newX,
float newY,
float newZ,
float newW)
139 float dot =
Dot(a, b);
145 INTERNAL_Slerp(ref q1, ref q2, t, out
Quaternion ret);
153 if (angle == 0.0f)
return to;
154 return Slerp(from, to,
Mathf.
Min(1.0f, maxDegreesDelta / angle));
164 return new Quaternion(q.
x / mag, q.
y / mag, q.
z / mag, q.
w / mag);
180 return x.GetHashCode() ^ (
y.GetHashCode() << 2) ^ (
z.GetHashCode() >> 2) ^ (
w.GetHashCode() >> 1);
184 public override bool Equals(
object other)
193 return x.Equals(other.
x) &&
y.Equals(other.
y) &&
z.Equals(other.
z) &&
w.Equals(other.
w);
196 public string ToString(
string format, IFormatProvider formatProvider)
198 if (
string.IsNullOrEmpty(format))
200 return string.Format(
"({0}, {1}, {2}, {3})",
x.ToString(format, formatProvider),
y.ToString(format, formatProvider),
z.ToString(format, formatProvider),
w.ToString(format, formatProvider));
206 INTERNAL_EulerAngles(ref
this, out
Vector3 ret);
227 float norm =
x *
x +
y *
y +
z *
z +
w *
w;
234 [MethodImpl(MethodImplOptions.InternalCall)]
235 private extern static void INTERNAL_Euler(ref
Vector3 euler, out
Quaternion value);
237 [MethodImpl(MethodImplOptions.InternalCall)]
238 private extern static void INTERNAL_AngleAxis(
float angle, ref
Vector3 axis, out
Quaternion value);
240 [MethodImpl(MethodImplOptions.InternalCall)]
241 private extern static void INTERNAL_LookRotation(ref
Vector3 direction, out
Quaternion ret);
243 [MethodImpl(MethodImplOptions.InternalCall)]
244 private extern static void INTERNAL_EulerAngles(ref
Quaternion quaternion, out
Vector3 ret);
246 [MethodImpl(MethodImplOptions.InternalCall)]
static float Acos(float f)
static float Min(float a, float b)
static float Abs(float f)
static float Sqrt(float f)
static readonly float Epsilon
bool Equals(Quaternion other)
string ToString(string format, IFormatProvider formatProvider)
Quaternion Scale(float s)
override int GetHashCode()
override bool Equals(object other)
static Quaternion AngleAxis(float angle, Vector3 axis)
void SetLookRotation(Vector3 view, Vector3 up)
static Quaternion operator+(Quaternion a, Quaternion b)
static Quaternion Normalize(Quaternion q)
void Set(float newX, float newY, float newZ, float newW)
static bool operator==(Quaternion lhs, Quaternion rhs)
static Quaternion identity
static float Angle(Quaternion a, Quaternion b)
static float Dot(Quaternion a, Quaternion b)
static Quaternion LookRotation(Vector3 direction, Vector3 axis)
static Quaternion Slerp(Quaternion q1, Quaternion q2, float t)
void SetLookRotation(Vector3 view)
static Quaternion RotateTowards(Quaternion from, Quaternion to, float maxDegreesDelta)
static bool operator!=(Quaternion lhs, Quaternion rhs)
Quaternion(float x, float y, float z, float w)
static Quaternion operator*(Quaternion lhs, Quaternion rhs)
static Quaternion Euler(float x, float y, float z)
static Quaternion operator-(Quaternion q)
static Quaternion Euler(Vector3 angles)