Quaternion

#include <graphics/quat.h>
struct quat

Two component quaternion structure.

float quat.x

X component

float quat.y

Y component

float quat.z

Z component

float quat.w

W component

float quat.ptr[4]

Unioned array of all components


void quat_identity(struct quat *dst)

Sets a quaternion to {0.0f, 0.0f, 0.0f, 1.0f}.

Parameters:
  • dst – Destination


void quat_set(struct quat *dst, float x, float y)

Sets the individual components of a quaternion.

Parameters:
  • dst – Destination

  • x – X component

  • y – Y component

  • y – Z component

  • w – W component


void quat_copy(struct quat *dst, const struct quat *v)

Copies a quaternion

Parameters:
  • dst – Destination

  • v – Quaternion to copy


void quat_add(struct quat *dst, const struct quat *v1, const struct quat *v2)

Adds two quaternions

Parameters:
  • dst – Destination

  • v1 – Quaternion 1

  • v2 – Quaternion 2


void quat_sub(struct quat *dst, const struct quat *v1, const struct quat *v2)

Subtracts two quaternions

Parameters:
  • dst – Destination

  • v1 – Quaternion being subtracted from

  • v2 – Quaternion being subtracted


void quat_mul(struct quat *dst, const struct quat *v1, const struct quat *v2)

Multiplies two quaternions

Parameters:
  • dst – Destination

  • v1 – Quaternion 1

  • v2 – Quaternion 2


void quat_addf(struct quat *dst, const struct quat *v, float f)

Adds a floating point to all components

Parameters:
  • dst – Destination

  • dst – Quaternion

  • f – Floating point


void quat_subf(struct quat *dst, const struct quat *v, float f)

Subtracts a floating point from all components

Parameters:
  • dst – Destination

  • v – Quaternion being subtracted from

  • f – Floating point being subtracted


void quat_mulf(struct quat *dst, const struct quat *v, float f)

Multiplies a floating point with all components

Parameters:
  • dst – Destination

  • dst – Quaternion

  • f – Floating point


void quat_inv(struct quat *dst, const struct quat *v)

Inverts a quaternion

Parameters:
  • dst – Destination

  • v – Quaternion to invert


float quat_dot(const struct quat *v1, const struct quat *v2)

Performs a dot product between two quaternions

Parameters:
  • v1 – Quaternion 1

  • v2 – Quaternion 2

Returns:

Result of the dot product


float quat_len(const struct quat *v)

Gets the length of a quaternion

Parameters:
  • v – Quaternion

Returns:

The quaternion’s length


float quat_dist(const struct quat *v1, const struct quat *v2)

Gets the distance between two quaternions

Parameters:
  • v1 – Quaternion 1

  • v2 – Quaternion 2

Returns:

Distance between the two quaternions


void quat_from_axisang(struct quat *dst, const struct axisang *aa)

Converts an axis angle to a quaternion

Parameters:
  • dst – Destination quaternion

  • aa – Axis angle


void quat_from_matrix4(struct quat *dst, const struct matrix4 *m)

Converts the rotational properties of a matrix to a quaternion

Parameters:
  • dst – Destination quaternion

  • m – Matrix to convert


void quat_get_dir(struct vec3 *dst, const struct quat *q)

Converts a quaternion to a directional vector

Parameters:
  • dst – Destination 3-component vector

  • q – Quaternion


void quat_set_look_dir(struct quat *dst, const struct vec3 *dir)

Creates a quaternion from a specific “look” direction

Parameters:
  • dst – Destination quaternion

  • dir – 3-component vector representing the look direction


void quat_interpolate(struct quat *dst, const struct quat *q1, const struct quat *q2, float t)

Linearly interpolates two quaternions

Parameters:
  • dst – Destination quaternion

  • q1 – Quaternion 1

  • q2 – Quaternion 2

  • t – Time value (0.0f..1.0f)


void quat_get_tangent(struct quat *dst, const struct quat *prev, const struct quat *q, const struct quat *next)

Gets a tangent value for the center of three rotational values

Parameters:
  • dst – Destination quaternion

  • prev – Previous rotation

  • q – Rotation to get tangent for

  • next – Next rotation


void quat_interpolate_cubic(struct quat *dst, const struct quat *q1, const struct quat *q2, const struct quat *m1, const struct quat *m2, float t)

Performs cubic interpolation between two quaternions

Parameters:
  • dst – Destination quaternion

  • q1 – Quaternion 1

  • q2 – Quaternion 2

  • m1 – Tangent 1

  • m2 – Tangent 2

  • t – Time value (0.0f..1.0f)