Gjsify LogoGjsify Logo

A quaternion is comprised of a scalar component and a 3D vector component. The scalar component is normally referred to as w and the vector might either be referred to as v or a (for axis) or expanded with the individual components: (x, y, z) A full quaternion would then be written as [w (x, y, z)].

Quaternions can be considered to represent an axis and angle pair although sadly these numbers are buried somewhat under some maths...

For the curious you can see here that a given axis (a) and angle (šœƒ) pair are represented in a quaternion as follows: |[ [w=cos(šœƒ/2) ( x=sin(šœƒ/2)*a.x, y=sin(šœƒ/2)*a.y, z=sin(šœƒ/2)*a.x )]



Unit Quaternions:
When using Quaternions to represent spatial orientations for 3D
graphics it's always assumed you have a unit quaternion. The
magnitude of a quaternion is defined as:
|[
sqrt (wĀ² + xĀ² + yĀ² + zĀ²)

and a unit quaternion satisfies this equation: |[ wĀ² + xĀ² + yĀ² + zĀ² = 1



Thankfully most of the time we don't actually have to worry about
the maths that goes on behind the scenes but if you are curious to
learn more here are some external references:

<itemizedlist>
<listitem>
<ulink url="http://mathworld.wolfram.com/Quaternion.html"/>
</listitem>
<listitem>
<ulink url="http://www.gamedev.net/reference/articles/article1095.asp"/>
</listitem>
<listitem>
<ulink url="http://www.cprogramming.com/tutorial/3d/quaternions.html"/>
</listitem>
<listitem>
<ulink url="http://www.isner.com/tutorials/quatSpells/quaternion_spells_12.htm"/>
</listitem>
<listitem>
3D Maths Primer for Graphics and Game Development ISBN-10: 1556229119
</listitem>
<listitem>
<ulink url="http://www.cs.caltech.edu/courses/cs171/quatut.pdf"/>
</listitem>
<listitem>
<ulink url="http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q56"/>
</listitem>
</itemizedlist>
@record

Hierarchy

  • Quaternion

Index

Constructors

Properties

w: number

based on the angle of rotation it is cos(šœƒ/2)

field
x: number

based on the angle of rotation and x component of the axis of rotation it is sin(šœƒ/2)*axis.x

field
y: number

based on the angle of rotation and y component of the axis of rotation it is sin(šœƒ/2)*axis.y

field
z: number

based on the angle of rotation and z component of the axis of rotation it is sin(šœƒ/2)*axis.z

field
name: string

Methods

  • free(): void
  • Frees a #CoglQuaternion that was previously allocated via cogl_quaternion_copy().

    Returns void

  • getRotationAngle(): number
  • getRotationAxis(): number
  • init(angle: number, x: number, y: number, z: number): void
  • Initializes a quaternion that rotates angle degrees around the axis vector (x, y, z). The axis vector does not need to be normalized.

    Parameters

    • angle: number

      The angle you want to rotate around the given axis

    • x: number

      The x component of your axis vector about which you want to rotate.

    • y: number

      The y component of your axis vector about which you want to rotate.

    • z: number

      The z component of your axis vector about which you want to rotate.

    Returns void

  • initFromAngleVector(angle: number, axis3f: number): void
  • Initializes a quaternion that rotates angle degrees around the given axis vector. The axis vector does not need to be normalized.

    Parameters

    • angle: number

      The angle to rotate around axis3f

    • axis3f: number

      your 3 component axis vector about which you want to rotate.

    Returns void

  • initFromArray(array: number): void
  • Initializes a [w (x, y,z)] quaternion directly from an array of 4 floats: [w,x,y,z].

    Parameters

    • array: number

      An array of 4 floats w,(x,y,z)

    Returns void

  • Initializes a quaternion from a rotation matrix.

    Parameters

    • matrix: Cogl.Matrix

      A rotation matrix with which to initialize the quaternion

    Returns void

  • initFromXRotation(angle: number): void
  • XXX: check which direction this rotates

    Parameters

    • angle: number

      The angle to rotate around the x axis

    Returns void

  • initFromYRotation(angle: number): void
  • initFromZRotation(angle: number): void
  • initIdentity(): void
  • Initializes the quaternion with the canonical quaternion identity [1 (0, 0, 0)] which represents no rotation. Multiplying a quaternion with this identity leaves the quaternion unchanged.

    You might also want to consider using cogl_get_static_identity_quaternion().

    Returns void

  • invert(): void
  • This combines the rotations of two quaternions into result. The operation is not commutative so the order is important because AxB != BxA. Cogl follows the standard convention for quaternions here so the rotations are applied right to left. This is similar to the combining of matrices.

    It is possible to multiply the a quaternion in-place, so result can be equal to a but can't be equal to b.

    Parameters

    Returns void

  • Performs a normalized linear interpolation between two quaternions. That is it does a linear interpolation of the quaternion components and then normalizes the result. This will follow the shortest arc between the two orientations (just like the slerp() function) but will not progress at a constant speed. Unlike slerp() nlerp is commutative which is useful if you are blending animations together. (I.e. nlerp (tmp, a, b) followed by nlerp (result, tmp, d) is the same as nlerp (tmp, a, d) followed by nlerp (result, tmp, b)). Finally nlerp is cheaper than slerp so it can be a good choice if you don't need the constant speed property of the slerp() function.

    Notable properties: commutative: Yes constant velocity: No torque minimal (travels along the surface of the 4-sphere): Yes faster than cogl_quaternion_slerp()

    Parameters

    • a: Cogl.Quaternion

      The first #CoglQuaternion

    • b: Cogl.Quaternion

      The second #CoglQuaternion

    • t: number

      The factor in the range [0,1] used to interpolate between quaterion a and b.

    Returns void

  • normalize(): void
  • pow(exponent: number): void
  • Performs a spherical linear interpolation between two quaternions.

    Noteable properties: commutative: No constant velocity: Yes torque minimal (travels along the surface of the 4-sphere): Yes more expensive than cogl_quaternion_nlerp()

    Parameters

    • a: Cogl.Quaternion

      The first #CoglQuaternion

    • b: Cogl.Quaternion

      The second #CoglQuaternion

    • t: number

      The factor in the range [0,1] used to interpolate between quaternion a and b.

    Returns void

  • equal(v1: object, v2: object): number
  • Compares that all the components of quaternions a and b are equal.

    An epsilon value is not used to compare the float components, but the == operator is at least used so that 0 and -0 are considered equal.

    Parameters

    • v1: object

      A #CoglQuaternion

    • v2: object

      A #CoglQuaternion

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method