Skip to content

rtm/vqmd.h

#include "rtm/vqmd.h"

vqm_cast

vqmd vqm_cast(const vqmf& input)

Casts a VQM transform float32 variant to a float64 variant.

vqm_set

vqmd vqm_set(quatd rotation, vector4d translation, matrix3x3d scale_shear)

Creates a VQM transform from a rotation quaternion, a translation, and a 3x3 scale/shear matrix. The scale/shear matrix applies before the rotation: p' = p * M * R + t.

vqmd vqm_set(quatd rotation, vector4d translation, vector4d scale)

Creates a VQM transform from a rotation quaternion, a translation, and a 3D scale.

vqm_get_scale_shear

matrix3x3d vqm_get_scale_shear(vqmd input)

Returns the scale/shear part of a VQM transform as a 3x3 matrix. The matrix applies before the rotation: p' = p * M * R + t.

vqm_from_matrix

vqmd vqm_from_matrix(matrix3x3d input)

Converts a 3x3 matrix into a VQM transform. The matrix can contain rotation, scale, shear, and reflection. The translation is zero. The rotation part is a pure rotation. If the matrix contains a reflection, the scale/shear part contains it. More than one VQM transform gives the same matrix. The function returns one of them.

vqmd vqm_from_matrix(matrix3x4d input)

Converts a 3x4 affine matrix into a VQM transform. See vqm_from_matrix(matrix3x3d) for the rotation and the scale/shear parts.

vqm_get_rotation

quatd vqm_get_rotation(vqmd input)

Returns the rotation part of a VQM transform.

vqm_set_rotation

vqmd vqm_set_rotation(vqmd input, quatd rotation)

Sets the rotation part of a VQM and returns the new value.

vqm_get_translation

vector4d vqm_get_translation(vqmd input)

Returns the translation part of a VQM transform. The [w] component is undefined.

vqm_set_translation

vqmd vqm_set_translation(vqmd input, vector4d translation)

Sets the translation part of a VQM and returns the new value.

vqm_get_scale

vector4d vqm_get_scale(vqmd input)

Returns the scale part of a VQM transform: the diagonal of the scale/shear matrix [m00, m11, m22]. The rows of the scale/shear matrix are the x, y, and z axes. When the matrix contains shear, the scale is not the length of a row. Use vqm_get_scale_shear to get the full matrix.

vqm_set_scale

vqmd vqm_set_scale(vqmd input, vector4d scale)

Sets the scale part of a VQM and returns the new value. The function sets the diagonal of the scale/shear matrix and keeps the other entries (the shear).

vqm_set_scale_shear

vqmd vqm_set_scale_shear(vqmd input, matrix3x3d scale_shear)

Sets the scale/shear part of a VQM and returns the new value. The matrix applies before the rotation: p' = p * M * R + t.

vqm_add

vqmd vqm_add(vqmd lhs, vqmd rhs)

Adds two VQM transforms.

vqm_mul

vqmd vqm_mul(vqmd lhs, vqmd rhs)

Multiplies two VQM transforms. Multiplication order is as follow: local_to_world = vqm_mul(local_to_object, object_to_world)

vqmd vqm_mul(vqmd vqm, double scalar)

Multiplies a VQM transform with a scalar.

vqm_mul_point3

vector4d vqm_mul_point3(vector4d point, vqmd vqm)

Multiplies a VQM transform and a 3D point. Multiplication order is as follow: world_position = vqm_mul_point3(local_position, local_to_world)

vqm_mul_vector3

vector4d vqm_mul_vector3(vector4d vec3, vqmd vqm)

Multiplies a VQM transform and a 3D vector. The translation does not apply. Multiplication order is as follow: world_direction = vqm_mul_vector3(local_direction, local_to_world)

vqm_inverse

vqmd vqm_inverse(vqmd input)

Returns the inverse of the input VQM transform. If the scale/shear part has a zero determinant (e.g. zero scale), the result is undefined. For a safe alternative, supply a fallback scale value and a threshold.

vqmd vqm_inverse(vqmd input, vector4d fallback_scale, double threshold=1.0E-8)

Returns the inverse of the input VQM transform. If the scale/shear part has a determinant whose absolute value is below the supplied threshold, the function uses the fallback scale in place of the scale/shear part. The fallback scale part has no shear. It must not contain a zero scale.

matrix_from_vqm

matrix3x4d matrix_from_vqm(vqmd input)

Converts a VQM transform into a 3x4 affine matrix.

vqm_normalize

vqmd vqm_normalize(vqmd input)

Returns a VQM transform with the rotation part normalized.

vqm_lerp

vqmd vqm_lerp(vqmd start, vqmd end, double alpha)

Per component linear interpolation of the two inputs at the specified alpha. The function interpolates the rotation with quat_lerp(..). It interpolates the translation and each axis of the scale/shear part with vector_lerp(..). The formula used is: ((1.0 - alpha) * start) + (alpha * end).

vqm_slerp

vqmd vqm_slerp(vqmd start, vqmd end, double alpha)

Spherical interpolation of the two inputs at the specified alpha. The function interpolates the rotation with quat_slerp(..) and the translation with vector_lerp(..). The scale is the diagonal of the scale/shear part. The function interpolates the scale with vector_eerp(..) and the remaining shear with vector_lerp(..). If the two values of a scale have a different sign or if one value is zero, the function interpolates that lane of the rows of the scale/shear part with vector_lerp(..).

vqm_is_finite

bool vqm_is_finite(vqmd input)

Returns true if the input VQM does not contain any NaN or Inf, otherwise false.

vqm_identity

vqmd vqm_identity()

Returns the identity VQM transform.

The return value also converts to vqmf.