rtm/quatf.h¶
#include "rtm/quatf.h"
quat_set¶
quatf quat_set(float x, float y, float z, float w)
Creates a quaternion from all 4 components.
quat_identity¶
quatf quat_identity()
Returns the identity quaternion.
The return value also converts to quatd.
Setters, getters, and casts¶
quat_load¶
quatf quat_load(const float* input)
Loads an unaligned quaternion from memory.
quatf quat_load(const float4f* input)
Loads an unaligned quat from memory.
vector_to_quat¶
quatf vector_to_quat(vector4f input)
Casts a vector4 to a quaternion.
quat_cast¶
quatf quat_cast(quatd input)
Casts a quaternion float64 variant to a float32 variant.
quat_get_x¶
float quat_get_x(quatf input)
Returns the quaternion [x] component (real part).
quat_get_x_as_scalar¶
scalarf quat_get_x_as_scalar(quatf input)
Returns the quaternion [x] component (real part).
quat_get_y¶
float quat_get_y(quatf input)
Returns the quaternion [y] component (real part).
quat_get_y_as_scalar¶
scalarf quat_get_y_as_scalar(quatf input)
Returns the quaternion [y] component (real part).
quat_get_z¶
float quat_get_z(quatf input)
Returns the quaternion [z] component (real part).
quat_get_z_as_scalar¶
scalarf quat_get_z_as_scalar(quatf input)
Returns the quaternion [z] component (real part).
quat_get_w¶
float quat_get_w(quatf input)
Returns the quaternion [w] component (imaginary part).
quat_get_w_as_scalar¶
scalarf quat_get_w_as_scalar(quatf input)
Returns the quaternion [w] component (imaginary part).
quat_set_x¶
quatf quat_set_x(quatf input, float lane_value)
Sets the quaternion [x] component (real part) and returns the new value.
quat_set_y¶
quatf quat_set_y(quatf input, float lane_value)
Sets the quaternion [y] component (real part) and returns the new value.
quat_set_z¶
quatf quat_set_z(quatf input, float lane_value)
Sets the quaternion [z] component (real part) and returns the new value.
quat_set_w¶
quatf quat_set_w(quatf input, float lane_value)
Sets the quaternion [w] component (imaginary part) and returns the new value.
quat_store¶
void quat_store(quatf input, float* output)
void quat_store(quatf input, float4f* output)
Writes a quaternion to unaligned memory.
Arithmetic¶
quat_conjugate¶
quatf quat_conjugate(quatf input)
Returns the quaternion conjugate.
quat_add¶
quatf quat_add(quatf lhs, quatf rhs)
Adds two quaternions.
quat_mul¶
quatf quat_mul(quatf lhs, quatf rhs)
Multiplies two quaternions. Note that due to floating point rounding, the result might not be perfectly normalized. Multiplication order is as follow: local_to_world = quat_mul(local_to_object, object_to_world)
quatf quat_mul(quatf quat, float scalar)
Multiplies a quaternion with a scalar.
quat_mul_vector3¶
vector4f quat_mul_vector3(vector4f vector, quatf rotation)
Multiplies a quaternion and a 3D vector, rotating it. Multiplication order is as follow: world_position = quat_mul_vector3(local_vector, local_to_world)
quat_dot¶
float quat_dot(quatf lhs, quatf rhs)
Quaternion dot product: lhs . rhs.
quat_dot_as_scalar¶
scalarf quat_dot_as_scalar(quatf lhs, quatf rhs)
Quaternion dot product: lhs . rhs.
quat_length_squared¶
float quat_length_squared(quatf input)
Returns the squared length/norm of the quaternion.
quat_length_squared_as_scalar¶
scalarf quat_length_squared_as_scalar(quatf input)
Returns the squared length/norm of the quaternion.
quat_length¶
float quat_length(quatf input)
Returns the length/norm of the quaternion.
quat_length_as_scalar¶
scalarf quat_length_as_scalar(quatf input)
Returns the length/norm of the quaternion.
quat_length_reciprocal¶
float quat_length_reciprocal(quatf input)
Returns the reciprocal length/norm of the quaternion.
quat_length_reciprocal_as_scalar¶
scalarf quat_length_reciprocal_as_scalar(quatf input)
Returns the reciprocal length/norm of the quaternion.
quat_normalize¶
quatf quat_normalize(quatf input)
Returns a normalized quaternion. Note that if the input quaternion is invalid (pure zero or with NaN/Inf), the result is undefined.
quat_normalize_deterministic¶
quatf quat_normalize_deterministic(quatf input)
Returns a normalized quaternion using a deterministic algorithm. This ensures that for a given input, the output will be identical on all platforms that implement IEEE-754. This can be slower than quat_normalize. This is only guaranteed if the rounding modes are consistent. Note that if the input quaternion is invalid (pure zero or with NaN/Inf), the result is undefined.
quat_lerp¶
quatf quat_lerp(quatf start, quatf end, float alpha)
Returns the linear interpolation between start and end for a given alpha value. The formula used is: ((1.0 - alpha) * start) + (alpha * end). Interpolation is stable and will return 'start' when 'alpha' is 0.0 and 'end' when it is 1.0. This is the same instruction count when FMA is present but it might be slightly slower due to the extra multiplication compared to: start + (alpha * (end - start)). Note that if 'start' and 'end' are on the opposite ends of the hypersphere, 'end' is negated before we interpolate. As such, when 'alpha' is 1.0, either 'end' or its negated equivalent is returned. Furthermore, if 'start' and 'end' aren't exactly normalized, the result might not match exactly when 'alpha' is 0.0 or 1.0 because we normalize the resulting quaternion.
quat_slerp¶
quatf quat_slerp(quatf start, quatf end, float alpha)
Returns the spherical interpolation between start and end for a given alpha value. If the angle between the two inputs is near zero, the function uses the weights (1.0 - alpha) and alpha. See: https://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/index.htm Perhaps try this someday: http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
quat_neg¶
quatf quat_neg(quatf input)
Returns a component wise negated quaternion.
quat_rotation_log¶
quatf quat_rotation_log(quatf input)
Returns the quaternion logarithm for a 3D rotation.
quat_rotation_exp¶
quatf quat_rotation_exp(quatf input)
Returns the quaternion exponential for a 3D rotation. The result might not be fully normalized if the input is near zero.
Conversion to/from axis/angle/euler¶
quat_to_axis_angle¶
void quat_to_axis_angle(quatf input, vector4f& out_axis, float& out_angle)
Returns the rotation axis and rotation angle that make up the input quaternion.
quat_get_axis¶
vector4f quat_get_axis(quatf input)
Returns the rotation axis part of the input quaternion.
quat_get_angle¶
float quat_get_angle(quatf input)
Returns the rotation angle part of the input quaternion.
quat_from_axis_angle¶
quatf quat_from_axis_angle(vector4f axis, float angle)
Creates a quaternion from a rotation axis and a rotation angle.
quat_from_euler¶
quatf quat_from_euler(float pitch, float yaw, float roll)
Creates a quaternion from Euler Pitch/Yaw/Roll angles. Pitch is around the Y axis (right) Yaw is around the Z axis (up) Roll is around the X axis (forward)
Comparisons and masking¶
quat_is_finite¶
bool quat_is_finite(quatf input)
Returns true if the input quaternion does not contain any NaN or Inf, otherwise false.
quat_is_normalized¶
bool quat_is_normalized(quatf input, float threshold=0.00001F)
Returns true if the input quaternion is normalized, otherwise false.
quat_are_equal¶
bool quat_are_equal(quatf lhs, quatf rhs)
Returns true if the two quaternions are equal component wise, otherwise false.
quat_near_equal¶
bool quat_near_equal(quatf lhs, quatf rhs, float threshold=0.00001F)
Returns true if the two quaternions are nearly equal component wise, otherwise false.
quat_near_identity¶
bool quat_near_identity(quatf input, float threshold_angle=0.00284714461F)
Returns true if the input quaternion is nearly equal to the identity quaternion by comparing its rotation angle.
quat_select¶
quatf quat_select(mask4f mask, quatf if_true, quatf if_false)
Per component selection depending on the mask: mask != 0 ? if_true : if_false Note that if the mask lanes are not all identical, the resulting quaternion may not be normalized.