gfm



struct  Quaternion(T);

 Quaternion implementation.

Holds a rotation + angle in a proper but wild space.


pure nothrow @nogc this(U)(U x) if (isAssignable!U);

Construct a Quaternion from a value.


pure nothrow @nogc this(T qw, T qx, T qy, T qz);

Constructs a Quaternion from coordinates.

Warning:
order of coordinates is different from storage.

static pure nothrow @nogc Quaternion  fromAxis(Vector!(T, 3) axis, T angle);

Constructs a Quaternion from axis + angle.


static pure nothrow @nogc Quaternion  fromEulerAngles(T roll, T pitch, T yaw);

Constructs a Quaternion from Euler angles.

All paramers given in radians.

Roll->X axis, Pitch->Y axis, Yaw->Z axis

See Also
https://www.cs.princeton.edu/~gewang/projects/darth/stuff/quat_faq.html

const pure nothrow @nogc vec3!T  toEulerAngles();

Converts a quaternion to Euler angles.

TODO:
adds a EulerAngles type.
Returns
A vector which contains roll-pitch-yaw as x-y-z.

pure nothrow @nogc ref Quaternion  opAssign(U)(U u) if (isQuaternionInstantiation!U && is(U._T : T));

Assign from another Quaternion.


pure nothrow @nogc ref Quaternion  opAssign(U)(U u) if (is(U : Vector!(T, 4u)));

Assign from a vector of 4 elements.


const nothrow string  toString();

Converts to a pretty string.


pure nothrow @nogc void  normalize();

Normalizes a quaternion.


const pure nothrow @nogc Quaternion  normalized();

Returns
Normalized quaternion.

pure nothrow @nogc void  inverse();

Inverses a quaternion in-place.


const pure nothrow @nogc Quaternion  inversed();

Returns
Inverse of quaternion.

const pure bool  opEquals(U)(U other) if (is(U : Quaternion));

Compare two Quaternions.


const pure nothrow bool  opEquals(U)(U other) if (isConvertible!U);

Compare Quaternion and other types.


const pure nothrow @nogc U  opCast(U)() if (isMatrixInstantiation!U && is(U._T : _T) && U._R == 3 && U._C == 3);

Convert to a 3x3 rotation matrix.

TODO:
check out why we can't do is(Unqual!U == mat3!T)

const pure nothrow @nogc U  opCast(U)() if (isMatrixInstantiation!U && is(U._T : _T) && U._R == 4 && U._C == 4);

Converts a to a 4x4 rotation matrix.

Known Bugs
check why we can't do is(Unqual!U == mat4!T)

pure nothrow @nogc Quaternion!T  lerp(T)(Quaternion!T a, Quaternion!T b, float t);

Linear interpolation, for quaternions.


pure nothrow @nogc Quaternion!T  Nlerp(T)(Quaternion!T a, Quaternion!T b, float t);

Returns
 Nlerp of quaternions.
See Also
Math Magician – Lerp

pure nothrow @nogc Quaternion!T  slerp(T)(Quaternion!T a, Quaternion!T b, T t);

Returns
Slerp of quaternions. Slerp is more expensive than Nlerp.
See Also
"Understanding Slerp, Then Not Using It"