30 namespace OpenSim.
Region.PhysicsModules.ConvexDecompositionDotNet
42 v = float3.normalize(v);
43 w = (float)Math.Cos(t / 2.0f);
44 v = v * (float)Math.Sin(t / 2.0f);
50 public Quaternion(
float _x,
float _y,
float _z,
float _w)
60 return (
float)Math.Acos(w) * 2.0f;
66 if (Math.Abs(angle()) < 0.0000001f)
67 return new float3(1f, 0f, 0f);
68 return a * (1 / (float)Math.Sin(angle() / 2.0f));
73 return new float3(1 - 2 * (y * y + z * z), 2 * (x * y + w * z), 2 * (x * z - w * y));
78 return new float3(2 * (x * y - w * z), 1 - 2 * (x * x + z * z), 2 * (y * z + w * x));
83 return new float3(2 * (x * z + w * y), 2 * (y * z - w * x), 1 - 2 * (x * x + y * y));
88 return new float3x3(xdir(), ydir(), zdir());
99 c.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;
100 c.x = a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y;
101 c.y = a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x;
102 c.z = a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w;
110 float qx2 = q.x * q.x;
111 float qy2 = q.y * q.y;
112 float qz2 = q.z * q.z;
114 float qxqy = q.x * q.y;
115 float qxqz = q.x * q.z;
116 float qxqw = q.x * q.w;
117 float qyqz = q.y * q.z;
118 float qyqw = q.y * q.w;
119 float qzqw = q.z * q.w;
120 return new float3((1 - 2 * (qy2 + qz2)) * v.
x + (2 * (qxqy - qzqw)) * v.
y + (2 * (qxqz + qyqw)) * v.
z, (2 * (qxqy + qzqw)) * v.
x + (1 - 2 * (qx2 + qz2)) * v.
y + (2 * (qyqz - qxqw)) * v.
z, (2 * (qxqz - qyqw)) * v.
x + (2 * (qyqz + qxqw)) * v.
y + (1 - 2 * (qx2 + qy2)) * v.
z);
135 float m = (float)Math.Sqrt(a.
w * a.
w + a.
x * a.
x + a.
y * a.
y + a.
z * a.
z);
136 if (m < 0.000000001f)
147 return (a.
w * b.
w + a.
x * b.
x + a.
y * b.
y + a.
z * b.
z);
164 float theta = (float)Math.Acos(d);
169 return a * ((float)Math.Sin(theta - interp * theta) / (float)Math.Sin(theta)) + b * ((
float)Math.Sin(interp * theta) / (
float)Math.Sin(theta));
174 return slerp(q0, q1, alpha);
184 roll *= (3.14159264f / 180.0f);
185 yaw *= (3.14159264f / 180.0f);
186 pitch *= (3.14159264f / 180.0f);
193 return (v.
y == 0.0 && v.
x == 0.0) ? 0.0f : (float)Math.Atan2(-v.
x, v.
y) * (180.0f / 3.14159264f);
199 return (
float)Math.Atan2(v.z, Math.Sqrt(v.x * v.x + v.y * v.y)) * (180.0f / 3.14159264f);
204 q =
new Quaternion(
new float3(0.0f, 0.0f, 1.0f), -Yaw(q) * (3.14159264f / 180.0f)) * q;
205 q =
new Quaternion(
new float3(1.0f, 0.0f, 0.0f), -Pitch(q) * (3.14159264f / 180.0f)) * q;
206 return (
float)Math.Atan2(-q.xdir().z, q.
xdir().x) * (180.0f / 3.14159264f);
static float Pitch(Quaternion q)
static Quaternion YawPitchRoll(float yaw, float pitch, float roll)
Quaternion(float3 v, float t)
static Quaternion slerp(Quaternion a, Quaternion b, float interp)
static float dot(Quaternion a, Quaternion b)
static Quaternion Interpolate(Quaternion q0, Quaternion q1, float alpha)
Quaternion(float _x, float _y, float _z, float _w)
static Quaternion normalize(Quaternion a)
static float Roll(Quaternion q)
static Quaternion Inverse(Quaternion q)
static float Yaw(Quaternion q)