GLOW API version 1.0 reference

Back to
Table of contents


class Quatf

General information

type: class
inherits: (none)
module: glowVectorAlgebra

Quatf represents a quaternion of floats. It is used internally by the 3D view transform classes.

Most GLOW programs will not need to use Quatf directly; however, it may be useful for customizing or manipulating the 3D view transform components.

Methods

Constructors

Quatf(void)

Creates a new quaternion with the value set to the identity rotation (1,0,0,0).

Quatf(GLfloat w, GLfloat x, GLfloat y, GLfloat z)

Creates a new quaternion with the given values. Note that the order is wxyz rather than xyzw.

Quatf(const GLfloat* vals)

Creates a new quaternion, copying the given array of values in wxyz order.

Quatf(const Vec3f& vec)

Creates a new quaternion with w set to 0 and xyz set to the given vector.

Quatf(const Vec3f& axis, GLfloat angle)

Creates a new quaternion representing the given rotation. The angle should be given in radians.

Quatf(const Quatf& q)

Copy constructor.

Setters

void Set(GLfloat w, GLfloat x, GLfloat y, GLfloat z)

Sets the quaternion to the specified values.

void Set(const GLfloat* vals)

Sets the quaternion to the specified array of values in wxyz order.

Quatf& operator=(const Quatf& q)

Copies the given quaternion.

Quatf& operator=(const GLfloat* vals)

Sets the quaternion to the specified array of values in wxyz order.

Quatf& operator=(const Vec3f& vec)

Sets w to 0 and xyz to the given vector.

Member access

GLfloat GetW(void) const

GLfloat GetX(void) const

GLfloat GetY(void) const

GLfloat GetZ(void) const

void SetW(GLfloat val)

void SetX(GLfloat val)

void SetY(GLfloat val)

void SetZ(GLfloat val)

GLfloat& W(void)

GLfloat W(void) const

GLfloat& X(void)

GLfloat X(void) const

GLfloat& Y(void)

GLfloat Y(void) const

GLfloat& Z(void)

GLfloat Z(void) const

Indexed member access
You can access members by index. index 0 is the w-coordinate, and index 3 is the z-coordinate. Specifying an index outside those bounds will raise an assertion.

GLfloat GetVal(std::ptrdiff_t i) const

void SetVal(std::ptrdiff_t i, GLfloat val)

GLfloat& operator[](std::ptrdiff_t i)

GLfloat operator[](std::ptrdiff_t i) const

Misc access

void SetZero(void)

Sets the quaternion to the zero quaternion (0,0,0,0).

bool IsZero(void) const

Is the quaternion set to the zero quaternion (0,0,0,0)?

void SetIdentity(void)

Sets the quaternion to the identity rotation (1,0,0,0).

bool IsIdentity(void) const

Is the quaternion set to the identity rotation (1,0,0,0)?

void SetImaginary(const Vec3f& vec)

Sets w to 0 and xyz to the given vector.

void SetImaginary(GLfloat x, GLfloat y, GLfloat z)

Sets w to 0 and xyz to the given vector.

const Vec3f GetImaginary(void) const

Returns the imaginary part (xyz) of this quaterion.

operator const GLfloat*(void) const

You can cast a Quatf directly to a const GLfloat*. In the resulting array, index 0 corresponds to the w-coordinate and index 3 corresponds to the z-coordinate.

Rotation operations

void SetRotation(GLfloat axisx, GLfloat axisy, GLfloat axisz, GLfloat angle)
void SetRotation(const Vec3f& axis, GLfloat angle)

Sets this quaternion to represent the given rotation. The angle should be given in radians, and the axis should be normalized.

void GetRotation(Vec3f& axis, GLfloat& angle) const

Returns the rotation represented by this quaternion. The angle is returned in radians. For best results, make sure the quaternion is sufficiently normalized before calling this method.

Vec3f GetAxis(void) const

Returns the axis of the rotation represented by this quaternion. For best results, make sure the quaternion is sufficiently normalized before calling this method.

GLfloat GetAngle(void) const

Returns the angle of the rotation represented by this quaternion, in radians. For best results, make sure the quaternion is sufficiently normalized before calling this method.

void ScaleRotation(GLfloat factor)

Scales the angle of the rotation represented by this quaternion. For best results, make sure the quaternion is sufficiently normalized before calling this method.

Special operations

const Quatf Conjugate(void) const

Returns the conjugate of the quaternion.

void Negate(void)

Negates the quaternion.

GLfloat Norm(void) const

Returns the norm of the quaternion.

GLfloat NormSquared(void) const

Returns the square of the norm of the quaternion. This is faster than Norm()*Norm().

GLfloat Normalize(void)

Normalizes the quaternion in place.

Vec3f Normalized(void) const

Returns a normalized version of the quaternion, but leaves the original untouched.

Arithmetic operations
Quatf provides a full set of arithmetic operations on quaternions.

Quatf == Quatf ---> bool
quaternion equality
Quatf != Quatf ---> bool
quaternion inequality

- Quatf ---> Quatf
quaternion negation

Quatf * GLfloat ---> Quatf
scalar multiplication
GLfloat * Quatf ---> Quatf
scalar multiplication
Quatf / GLfloat ---> Quatf
scalar division
Quatf *= GLfloat
in-place scalar multiplication
Quatf /= GLfloat
in-place scalar division

Quatf + Quatf ---> Quatf
quaternion addition
Quatf - Quatf ---> Quatf
quaternion subtraction
Quatf * Quatf ---> GLfloat
dot product
Quatf % Quatf ---> Quatf
cross product (quaternion product)
Quatf += Quatf
in-place quaternion addition
Quatf -= Quatf
in-place quaternion subtraction
Quatf %= Quatf
in-place cross product

Quatf * Vec3f ---> Vec3f
application of quaternion to vector


Back to
Table of contents


The GLOW Toolkit