12 public Quaternion
rot;
16 get {
return new RigidTransform(Vector3.zero, Quaternion.identity); }
32 this.pos = t.position;
33 this.rot = t.rotation;
38 var inv = Quaternion.Inverse(from.rotation);
39 rot = inv * to.rotation;
40 pos = inv * (to.position - from.position);
45 var m = Matrix4x4.identity;
62 this.pos = m.GetPosition();
63 this.rot = m.GetRotation();
68 var m = Matrix4x4.identity;
90 this.pos = m.GetPosition();
91 this.rot = m.GetRotation();
96 var m = Matrix4x4.TRS(
pos,
rot, Vector3.one);
97 var pose =
new HmdMatrix44_t();
124 var m = Matrix4x4.TRS(
pos,
rot, Vector3.one);
125 var pose =
new HmdMatrix34_t();
159 return pos.GetHashCode() ^
rot.GetHashCode();
164 return a.pos == b.pos && a.rot == b.
rot;
169 return a.pos != b.pos || a.rot != b.
rot;
177 pos = a.pos + a.rot * b.pos
183 rot = Quaternion.Inverse(
rot);
197 pos = a.pos + a.rot * b.
pos;
202 return Quaternion.Inverse(
rot) * (point -
pos);
207 return pos + (
rot * point);
228 public static Quaternion
Slerp(Quaternion A, Quaternion B,
float t)
230 var cosom = Mathf.Clamp(A.x * B.x + A.y * B.y + A.z * B.z + A.w * B.w, -1.0f, 1.0f);
233 B =
new Quaternion(-B.x, -B.y, -B.z, -B.w);
238 if ((1.0f - cosom) > 0.0001f)
240 var omega = Mathf.Acos(cosom);
241 var sinom = Mathf.Sin(omega);
242 sclp = Mathf.Sin((1.0f - t) * omega) / sinom;
243 sclq = Mathf.Sin(t * omega) / sinom;
252 return new Quaternion(
253 sclp * A.x + sclq * B.x,
254 sclp * A.y + sclq * B.y,
255 sclp * A.z + sclq * B.z,
256 sclp * A.w + sclq * B.w);
259 public static Vector3
Lerp(Vector3 A, Vector3 B,
float t)
267 public static float Lerp(
float A,
float B,
float t)
269 return A + (B - A) * t;
272 public static double Lerp(
double A,
double B,
double t)
274 return A + (B - A) * t;
277 private static float _copysign(
float sizeval,
float signval)
279 return Mathf.Sign(signval) == 1 ? Mathf.Abs(sizeval) : -Mathf.Abs(sizeval);
284 Quaternion q =
new Quaternion();
285 q.w = Mathf.Sqrt(Mathf.Max(0, 1 + matrix.m00 + matrix.m11 + matrix.m22)) / 2;
286 q.x = Mathf.Sqrt(Mathf.Max(0, 1 + matrix.m00 - matrix.m11 - matrix.m22)) / 2;
287 q.y = Mathf.Sqrt(Mathf.Max(0, 1 - matrix.m00 + matrix.m11 - matrix.m22)) / 2;
288 q.z = Mathf.Sqrt(Mathf.Max(0, 1 - matrix.m00 - matrix.m11 + matrix.m22)) / 2;
289 q.x = _copysign(q.x, matrix.m21 - matrix.m12);
290 q.y = _copysign(q.y, matrix.m02 - matrix.m20);
291 q.z = _copysign(q.z, matrix.m10 - matrix.m01);
301 return new Vector3(x, y, z);
304 public static Vector2
ToVector2(
this VRControllerAxis_t axis)
306 return new Vector2(axis.x, axis.y);
static Quaternion GetRotation(this Matrix4x4 matrix)
static Quaternion Slerp(Quaternion A, Quaternion B, float t)
static Vector3 Lerp(Vector3 A, Vector3 B, float t)
static float Lerp(float A, float B, float t)
static double Lerp(double A, double B, double t)
static Vector3 GetPosition(this Matrix4x4 matrix)
static Vector2 ToVector2(this VRControllerAxis_t axis)