matrix/mat4f
4x4 matrices of floats
Types
Values
pub fn add(
a: vec4.Vec4(vec4.Vec4(Float)),
b: vec4.Vec4(vec4.Vec4(Float)),
) -> vec4.Vec4(vec4.Vec4(Float))
Adds two Mat4fs together
pub fn diagonal(
mat: vec4.Vec4(vec4.Vec4(Float)),
) -> vec4.Vec4(Float)
Extracts the diagonal of the Mat4f.
pub fn from_axis_angle(
axis: vec3.Vec3(Float),
angle: Float,
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix containing a 3D rotation around a normalized
rotation axis of angle (in radians).
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_cols(
a: vec4.Vec4(Float),
b: vec4.Vec4(Float),
c: vec4.Vec4(Float),
d: vec4.Vec4(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Constructs a Mat4f from its four columns.
| a.x b.x c.x d.x |
| a.y b.y c.y d.y |
| a.z b.z c.z d.z |
| a.w b.w c.w d.w |
pub fn from_diagonal(
diagonal: vec4.Vec4(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates a 4x4 matrix with its diagonal set to diagonal and all other entries are 0.
pub fn from_mat3(
m: vec3.Vec3(vec3.Vec3(Float)),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix from the given 3x3 linear transformation matrix.
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_mat3_translation(
mat3: vec3.Vec3(vec3.Vec3(Float)),
translation: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrics from a 3x3 matrix (expressing scale, shear and rotation) and a translation vector.
Equivalent to multiply(from_translation(translation), from_mat3(mat3))
pub fn from_quaternion(
q: vec4.Vec4(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix from the given rotation quaternion.
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_rotation_translation(
rotation: vec4.Vec4(Float),
translation: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix from the given 3D translation.
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_rotation_x(
angle: Float,
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix containing a 3D rotation around the x axis of
angle (in radians).
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_rotation_y(
angle: Float,
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix containing a 3D rotation around the y axis of
angle (in radians).
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_rotation_z(
angle: Float,
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix containing a 3D rotation around the z axis of
angle (in radians).
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_scale(
scale: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix containing the given 3D non-uniform scale.
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_scale_rotation_translation(
scale: vec3.Vec3(Float),
rotation: vec4.Vec4(Float),
translation: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix from the given 3D scale, rotation and
translation.
The resulting matrix can be used to transform 3D points and vectors.
pub fn from_translation(
translation: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates an affine transformation matrix from the given 3D translation.
The resulting matrix can be used to transform 3D points and vectors.
pub fn inverse(
mat: vec4.Vec4(vec4.Vec4(Float)),
) -> Result(vec4.Vec4(vec4.Vec4(Float)), Nil)
Inverts the Mat4f, returning an error if the matrix is not invertible.
pub fn look_at_lh(
eye: vec3.Vec3(Float),
center: vec3.Vec3(Float),
up: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates a left-handed view matrix using a camera position, a focal points and an up direction.
For a view coordinate system with +X=right, +Y=up and +Z=forward.
pub fn look_at_rh(
eye: vec3.Vec3(Float),
center: vec3.Vec3(Float),
up: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates a right-handed view matrix using a camera position, a focal point, and an up direction.
For a view coordinate system with +X=right, +Y=up and +Z=back.
pub fn look_to_lh(
eye: vec3.Vec3(Float),
dir: vec3.Vec3(Float),
up: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates a left-handed view matrix using a camera position, a facing direction and an up direction
For a view coordinate system with +X=right, +Y=up and +Z=forward.
pub fn look_to_rh(
eye: vec3.Vec3(Float),
dir: vec3.Vec3(Float),
up: vec3.Vec3(Float),
) -> vec4.Vec4(vec4.Vec4(Float))
Creates a right-handed view matrix using a camera position, a facing direction, and an up direction.
For a view coordinate system with +X=right, +Y=up and +Z=back.
pub fn mul_transpose_vec4(
mat: vec4.Vec4(vec4.Vec4(Float)),
rhs: vec4.Vec4(Float),
) -> vec4.Vec4(Float)
Transforms a 4D vector by the transpose of the Mat4f.
Equivalent to matrix multiplication where the vector is on the left.
pub fn mul_vec4(
mat: vec4.Vec4(vec4.Vec4(Float)),
rhs: vec4.Vec4(Float),
) -> vec4.Vec4(Float)
Transforms a 4D vector by this Mat4f.
pub fn new(
ax: Float,
ay: Float,
az: Float,
aw: Float,
bx: Float,
by: Float,
bz: Float,
bw: Float,
cx: Float,
cy: Float,
cz: Float,
cw: Float,
dx: Float,
dy: Float,
dz: Float,
dw: Float,
) -> vec4.Vec4(vec4.Vec4(Float))
Constructs a Mat4f from its components.
| ax bx cx dx |
| ay by cy dy |
| az bz cz dz |
| aw bw cw dw |
pub fn scale(
mat: vec4.Vec4(vec4.Vec4(Float)),
scale: Float,
) -> vec4.Vec4(vec4.Vec4(Float))
Scales the Mat4f by a Float.
pub fn subtract(
a: vec4.Vec4(vec4.Vec4(Float)),
b: vec4.Vec4(vec4.Vec4(Float)),
) -> vec4.Vec4(vec4.Vec4(Float))
Subtracts Mat4f b from a
pub fn to_scale_rotation_translation(
mat: vec4.Vec4(vec4.Vec4(Float)),
) -> Result(
#(vec3.Vec3(Float), vec4.Vec4(Float), vec3.Vec3(Float)),
Nil,
)
Extracts scale, rotation and translation from mat. The input matrix is
expected to be a 3D affine transformation matrix otherwise the output will be invalid.
Will return Error(Nil) if the determinant of mat is zero or if the resulting scale vector
contains any zero elements.
pub fn transform_point3(
mat: vec4.Vec4(vec4.Vec4(Float)),
rhs: vec3.Vec3(Float),
) -> vec3.Vec3(Float)
Transforms the given 3D vector as a point.
This is the equivalent of multiplying the 3D vector as a 4D vector where w is
1.0.
This function assumes that mat contains a valid affine transform.
pub fn transform_vector3(
mat: vec4.Vec4(vec4.Vec4(Float)),
rhs: vec3.Vec3(Float),
) -> vec3.Vec3(Float)
Transforms the given 3D vector as a direction.
This is the equivalent of multiplying the 3D vector as a 4D vector where w is
0.0.
This method assumes that mat contains a valid affine transform.