quaternion_ptr.c file
Functions
- void quat_identity_ptr(quaternion* res)
- Sets the quaternion to the identity quaternion (x=0, y=0, z=0, w=1).
-
auto quat_mul_ptr_scalar(quaternion* res,
const quaternion* a,
const quaternion* b) -> VECMAT_
SCALAR_ API void - Multiplies two quaternions using Hamilton product (a * b) and stores the result in res.
- void quat_mul_ptr(quaternion* res, const quaternion* a, const quaternion* b)
- Hamilton product
a * b(dispatched). -
auto quat_normalize_ptr_scalar(quaternion* res,
const quaternion* q) -> VECMAT_
SCALAR_ API void - Normalizes the input quaternion and stores the result in res.
- void quat_normalize_ptr(quaternion* res, const quaternion* q)
- Normalizes a quaternion (dispatched).
- void quat_from_euler_ptr(quaternion* res, const vector3* euler)
- Converts Euler angles (in radians) to a normalized quaternion.
- void quat_from_euler_deg_ptr(quaternion* res, const vector3* euler_deg)
- Converts Euler angles in degrees to a quaternion.
- void quat_to_mat4_ptr(matrix4* res, const quaternion* q)
- Converts a unit quaternion to a 4x4 rotation matrix and stores in res.
- void quat_conjugate_ptr(quaternion* res, const quaternion* q)
- Writes the conjugate of a quaternion.
- void quat_inverse_ptr(quaternion* res, const quaternion* q)
- Writes the inverse of a quaternion.
-
void quat_from_axis_angle_ptr(quaternion* res,
const vector3* axis,
const vm_
float_ t radians) - Converts an axis-angle rotation to a quaternion.
-
void quat_from_axis_angle_deg_ptr(quaternion* res,
const vector3* axis,
const vm_
float_ t degrees) - Converts an axis-angle rotation (in degrees) to a quaternion.
- void quat_from_mat3_ptr(quaternion* res, const matrix3* m)
- Builds a quaternion from a 3x3 rotation matrix.
- void quat_from_mat4_ptr(quaternion* res, const matrix4* m)
- Builds a quaternion from the rotation of a 4x4 matrix.
-
void quat_nlerp_ptr(quaternion* res,
const quaternion* a,
const quaternion* b,
const vm_
float_ t t) - Normalized-linearly interpolates from a to b by t.
-
void quat_slerp_ptr(quaternion* res,
const quaternion* a,
const quaternion* b,
const vm_
float_ t t) - Spherical-linearly interpolates from a to b by t.
- void quat_rotate_vec3_ptr(vector3* res, const quaternion* q, const vector3* v)
- Rotates a vector3 by a quaternion.
- void quat_to_euler_ptr(vector3* res, const quaternion* q)
- Converts a quaternion to Euler angles in degrees (XYZ).
- void quat_to_euler_deg_ptr(vector3* res, const quaternion* q)
- Converts a quaternion to XYZ Euler angles in degrees.
-
void quat_to_axis_angle_ptr(vector3* axis,
vm_
float_ t* radians, const quaternion* q) - Converts a quaternion to an axis-angle representation.
-
void quat_to_axis_angle_deg_ptr(vector3* axis,
vm_
float_ t* degrees, const quaternion* q) - Converts a quaternion to an axis-angle representation, with the angle in degrees.
- void quat_to_mat3_ptr(matrix3* res, const quaternion* q)
- Converts a quaternion to a 3x3 rotation matrix.
-
void quat_integrate_ptr(quaternion* res,
const quaternion* q,
const vector3* omega,
const vm_
float_ t dt) - Integrates angular velocity over a time step and applies the resulting rotation to the input quaternion.
- static void quat_look_basis(matrix3* r, const vector3* direction, const vector3* up, const int left_handed)
- Orthonormal basis that aims along
direction. - void quat_look_ptr(quaternion* res, const vector3* direction, const vector3* up)
- Orientation that aims local -Z along
direction(RH / FPS camera). -
void quat_look_clip_ptr(quaternion* res,
const vector3* direction,
const vector3* up,
const vm_
clip_ t clip) - Orientation that aims along
direction. - void quat_from_to_ptr(quaternion* res, const vector3* from, const vector3* to)
- Shortest rotation taking
fromontoto.
Function documentation
void quat_identity_ptr(quaternion* res)
Sets the quaternion to the identity quaternion (x=0, y=0, z=0, w=1).
| Parameters | |
|---|---|
| res | Pointer to the quaternion to initialize. |
VECMAT_ SCALAR_ API void quat_mul_ptr_scalar(quaternion* res,
const quaternion* a,
const quaternion* b)
Multiplies two quaternions using Hamilton product (a * b) and stores the result in res.
| Parameters | |
|---|---|
| res | Pointer to the output quaternion. |
| a | Pointer to the first quaternion. |
| b | Pointer to the second quaternion. |
void quat_mul_ptr(quaternion* res, const quaternion* a, const quaternion* b)
Hamilton product a * b (dispatched).
| Parameters | |
|---|---|
| res | Result quaternion. |
| a | Left quaternion. |
| b | Right quaternion. |
VECMAT_ SCALAR_ API void quat_normalize_ptr_scalar(quaternion* res,
const quaternion* q)
Normalizes the input quaternion and stores the result in res.
| Parameters | |
|---|---|
| res | Pointer to the output quaternion. |
| q | Pointer to the input quaternion. |
If the quaternion length is zero, copies the input unchanged.
void quat_normalize_ptr(quaternion* res, const quaternion* q)
Normalizes a quaternion (dispatched).
| Parameters | |
|---|---|
| res | Result quaternion. |
| q | Input quaternion. |
void quat_from_euler_ptr(quaternion* res, const vector3* euler)
Converts Euler angles (in radians) to a normalized quaternion.
| Parameters | |
|---|---|
| res | Pointer to the quaternion that will receive the result. |
| euler | Pointer to a vector3 containing the Euler angles in radians (x, y, z). |
Computes a quaternion from the given Euler rotation vector using the XYZ (Tait-Bryan) convention. The resulting quaternion is guaranteed to be normalized.
void quat_from_euler_deg_ptr(quaternion* res, const vector3* euler_deg)
Converts Euler angles in degrees to a quaternion.
| Parameters | |
|---|---|
| res | Pointer to the quaternion to store the result. |
| euler_deg | Pointer to the vector containing Euler angles in degrees. |
void quat_to_mat4_ptr(matrix4* res, const quaternion* q)
Converts a unit quaternion to a 4x4 rotation matrix and stores in res.
| Parameters | |
|---|---|
| res | Pointer to the output matrix4. |
| q | Pointer to the input quaternion (should be normalized). |
Starts with the identity matrix and applies rotation components.
void quat_conjugate_ptr(quaternion* res, const quaternion* q)
Writes the conjugate of a quaternion.
| Parameters | |
|---|---|
| res | Output value. |
| q | Input quaternion. |
void quat_inverse_ptr(quaternion* res, const quaternion* q)
Writes the inverse of a quaternion.
| Parameters | |
|---|---|
| res | Output value. |
| q | Input quaternion. |
void quat_from_axis_angle_ptr(quaternion* res,
const vector3* axis,
const vm_ float_ t radians)
Converts an axis-angle rotation to a quaternion.
| Parameters | |
|---|---|
| res | Pointer to the quaternion that will receive the result. |
| axis | Pointer to the rotation axis vector. |
| radians | Rotation angle around the axis in radians. |
The axis vector is normalized internally. The angle is given in radians.
void quat_from_axis_angle_deg_ptr(quaternion* res,
const vector3* axis,
const vm_ float_ t degrees)
Converts an axis-angle rotation (in degrees) to a quaternion.
| Parameters | |
|---|---|
| res | Pointer to the quaternion that will receive the result. |
| axis | Pointer to the rotation axis vector. |
| degrees | Rotation angle around the axis in degrees. |
void quat_from_mat3_ptr(quaternion* res, const matrix3* m)
Builds a quaternion from a 3x3 rotation matrix.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
void quat_from_mat4_ptr(quaternion* res, const matrix4* m)
Builds a quaternion from the rotation of a 4x4 matrix.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
void quat_nlerp_ptr(quaternion* res,
const quaternion* a,
const quaternion* b,
const vm_ float_ t t)
Normalized-linearly interpolates from a to b by t.
| Parameters | |
|---|---|
| res | Output value. |
| a | First input quaternion. |
| b | Second input quaternion. |
| t | Interpolation factor. |
void quat_slerp_ptr(quaternion* res,
const quaternion* a,
const quaternion* b,
const vm_ float_ t t)
Spherical-linearly interpolates from a to b by t.
| Parameters | |
|---|---|
| res | Output value. |
| a | First input quaternion. |
| b | Second input quaternion. |
| t | Interpolation factor. |
void quat_rotate_vec3_ptr(vector3* res, const quaternion* q, const vector3* v)
Rotates a vector3 by a quaternion.
| Parameters | |
|---|---|
| res | Output value. |
| q | Input quaternion. |
| v | Input vector. |
void quat_to_euler_ptr(vector3* res, const quaternion* q)
Converts a quaternion to Euler angles in degrees (XYZ).
| Parameters | |
|---|---|
| res | Output value. |
| q | Input quaternion. |
void quat_to_euler_deg_ptr(vector3* res, const quaternion* q)
Converts a quaternion to XYZ Euler angles in degrees.
| Parameters | |
|---|---|
| res | Euler angles in degrees (x, y, z). |
| q | Input quaternion. |
void quat_to_axis_angle_ptr(vector3* axis,
vm_ float_ t* radians,
const quaternion* q)
Converts a quaternion to an axis-angle representation.
| Parameters | |
|---|---|
| axis | Pointer to the vector3 that will receive the rotation axis. |
| radians | Pointer to a float that will receive the rotation angle in radians, or NULL. |
| q | Pointer to the input quaternion. |
The quaternion is first normalized. The axis is stored in the provided vector3 pointer. The rotation angle in radians is optionally written to the radians pointer if it is not NULL. When the axis cannot be uniquely determined (near zero rotation) the axis is set to (1, 0, 0).
void quat_to_axis_angle_deg_ptr(vector3* axis,
vm_ float_ t* degrees,
const quaternion* q)
Converts a quaternion to an axis-angle representation, with the angle in degrees.
| Parameters | |
|---|---|
| axis | Pointer to the vector3 that will receive the normalized rotation axis. |
| degrees | Pointer to a float that will receive the rotation angle in degrees (may be NULL). |
| q | Pointer to the source quaternion. |
Extracts the rotation axis and rotation angle (in degrees) equivalent to the given quaternion. The quaternion is first normalized internally. If the quaternion represents no rotation, the axis is set to (1, 0, 0).
void quat_to_mat3_ptr(matrix3* res, const quaternion* q)
Converts a quaternion to a 3x3 rotation matrix.
| Parameters | |
|---|---|
| res | Output value. |
| q | Input quaternion. |
void quat_integrate_ptr(quaternion* res,
const quaternion* q,
const vector3* omega,
const vm_ float_ t dt)
Integrates angular velocity over a time step and applies the resulting rotation to the input quaternion.
| Parameters | |
|---|---|
| res | Pointer to the quaternion where the integrated result is stored. |
| q | Pointer to the source quaternion. |
| omega | Pointer to the angular velocity vector (in radians per second). |
| dt | Time step (in seconds). |
Computes a delta quaternion from the angular velocity and timestep, multiplies it with the source quaternion and normalizes the result.
static void quat_look_basis(matrix3* r, const vector3* direction, const vector3* up, const int left_handed)
Orthonormal basis that aims along direction.
| Parameters | |
|---|---|
| r | Output rotation (columns: right, up, +/-forward). |
| direction | Look direction. |
| up | World up hint. |
| left_handed | Non-zero for a left-handed basis. |
void quat_look_ptr(quaternion* res, const vector3* direction, const vector3* up)
Orientation that aims local -Z along direction (RH / FPS camera).
| Parameters | |
|---|---|
| res | Result quaternion. |
| direction | Look direction. |
| up | World up hint. |
Matches the rotation part of mat4_ inverted (view-to-world).
void quat_look_clip_ptr(quaternion* res,
const vector3* direction,
const vector3* up,
const vm_ clip_ t clip)
Orientation that aims along direction.
| Parameters | |
|---|---|
| res | Result quaternion. |
| direction | Look direction. |
| up | World up hint. |
| clip | Clip-space convention selecting handedness. |
RH: local -Z maps to direction. LH: local +Z maps to direction.
void quat_from_to_ptr(quaternion* res, const vector3* from, const vector3* to)
Shortest rotation taking from onto to.
| Parameters | |
|---|---|
| res | Result quaternion. |
| from | Source direction. |
| to | Target direction. |
Opposite vectors pick a stable orthogonal axis (180 deg). Near-parallel vectors return identity.