67 explicit Quaternion(
bool init) {
if (init) {
X = 0.0f;
Y = 0.0f;
Z = 0.0f;
W = 1.0f; } }
68 explicit Quaternion(
float a,
float b,
float c,
float d) {
X=a;
Y=b;
Z=c;
W=d; }
72 void Set(
float a = 0.0,
float b = 0.0,
float c = 0.0,
float d = 1.0) {
X = a;
Y = b;
Z = c;
W = d; }
74 void Scale(
float s) {
X = (float)(s*
X);
Y = (float)(s*
Y);
Z = (float)(s*
Z);
W = (float)(s*
W); }
130 return Quaternion(a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]);
136 return Quaternion(a[0] - b[0], a[1] - b[1], a[2] - b[2], a[3] - b[3]);
142 return Quaternion(scl*a[0], scl*a[1], scl*a[2], scl*a[3]);
156 a.
W*b.
X + b.
W*a.
X + (a.
Y*b.
Z - b.
Y*a.
Z),
157 a.
W*b.
Y + b.
W*a.
Y - (a.
X*b.
Z - b.
X*a.
Z),
158 a.
W*b.
Z + b.
W*a.
Z + (a.
X*b.
Y - b.
X*a.
Y),
159 a.
W * b.
W - (a.
X * b.
X + a.
Y * b.
Y + a.
Z * b.
Z)
176 float oomag = 1.0f / mag;
177 return Quaternion(a[0] * oomag, a[1] * oomag, a[2] * oomag, a[3] * oomag);
224 float x =
W*v.
X + (
Y*v.
Z - v.
Y*
Z);
225 float y =
W*v.
Y - (
X*v.
Z - v.
X*
Z);
226 float z =
W*v.
Z + (
X*v.
Y - v.
X*
Y);
227 float w = -(
X*v.
X +
Y*v.
Y +
Z*v.
Z);
231 w*(-
X) +
W*x + (y*(-
Z) - (-
Y)*z),
232 w*(-
Y) +
W*y - (x*(-
Z) - (-
X)*z),
233 w*(-
Z) +
W*z + (x*(-
Y) - (-
X)*y)
239 assert(result !=
NULL);
241 float x =
W*v.
X + (
Y*v.
Z - v.
Y*
Z);
242 float y =
W*v.
Y - (
X*v.
Z - v.
X*
Z);
243 float z =
W*v.
Z + (
X*v.
Y - v.
X*
Y);
244 float w = -(
X*v.
X +
Y*v.
Y +
Z*v.
Z);
246 result->
X = w*(-
X) +
W*x + (y*(-
Z) - (-
Y)*z);
247 result->
Y = w*(-
Y) +
W*y - (x*(-
Z) - (-
X)*z);
248 result->
Z = w*(-
Z) +
W*z + (x*(-
Y) - (-
X)*y);
float Length2(void) const
WWINLINE Quaternion(void)
void Rotate_Y(float theta)
void Rotate_Vector(const Vector3 &v, Vector3 *set_result) const
Quaternion & Make_Closest(const Quaternion &qto)
Quaternion(float a, float b, float c, float d)
Vector3 Rotate_Vector(const Vector3 &v) const
WWINLINE float Length(void) const
Quaternion & operator=(const Quaternion &source)
void Rotate_X(float theta)
WWINLINE float Length2(void) const
Quaternion operator+() const
void Rotate_Z(float theta)
WWINLINE float & operator[](int i)
void Set(float a=0.0, float b=0.0, float c=0.0, float d=1.0)
bool Is_Valid(void) const
Quaternion(const Vector3 &axis, float angle)
WWINLINE void Set(float a=0.0, float b=0.0, float c=0.0, float d=1.0)
Quaternion operator-() const
static float Sqrt(float val)
static bool Is_Valid_Float(float x)
Matrix3 Build_Matrix3(const Quaternion &quat)
Quaternion operator-(const Quaternion &a, const Quaternion &b)
void Slerp_Setup(const Quaternion &p, const Quaternion &q, SlerpInfoStruct *slerpinfo)
Quaternion Inverse(const Quaternion &a)
Quaternion Slerp(const Quaternion &a, const Quaternion &b, float t)
Quaternion Conjugate(const Quaternion &a)
Quaternion operator/(const Quaternion &a, const Quaternion &b)
Matrix3D Build_Matrix3D(const Quaternion &quat)
Quaternion Axis_To_Quat(const Vector3 &a, float angle)
void Cached_Slerp(const Quaternion &p, const Quaternion &q, float alpha, SlerpInfoStruct *slerpinfo, Quaternion *set_q)
Quaternion Normalize(const Quaternion &a)
Quaternion Trackball(float x0, float y0, float x1, float y1, float sphsize)
Quaternion operator+(const Quaternion &a, const Quaternion &b)
Matrix4 Build_Matrix4(const Quaternion &quat)
Quaternion Build_Quaternion(const Matrix3 &matrix)
Quaternion operator*(float scl, const Quaternion &a)