Banjo API 0.0.1
Multi-purpose C99 API
Loading...
Searching...
No Matches
Math

Linear math function. More...

Collaboration diagram for Math:

Detailed Description

The Math group provides usual facilities for linear math, including

The scalar type is float by is aliased as bj_real_t using a typedef.

This library is a direct conversion of linmath.h by Wolfgang Draxinger.

Macros

#define bj_real_t   float
 Alias for float type.
 
#define bj_quat_add   bj_vec4_add
 Alias for bj_vec4_add, adds two quaternions.
 
#define bj_quat_sub   bj_vec4_sub
 Alias for bj_vec4_sub, subtracts two quaternions.
 
#define bj_quat_norm   bj_vec4_normalize
 Alias for bj_vec4_normalize, normalizes a quaternion.
 
#define bj_quat_scale   bj_vec4_scale
 Alias for bj_vec4_scale, scales a quaternion by a scalar.
 
#define bj_quat_dot   bj_vec4_dot
 Alias for bj_vec4_dot, computes the dot product of two quaternions.
 

Typedefs

typedef bj_real_t bj_vec2[2]
 Defines a 2D vector type.
 
typedef bj_real_t bj_vec3[3]
 Defines a 3D vector type.
 
typedef bj_real_t bj_vec4[4]
 Defines a 4D vector type.
 
typedef bj_vec4 bj_mat4[4]
 Defines a 4x4 matrix type.
 
typedef bj_real_t bj_quat[4]
 Defines a quaternion type.
 

Functions

BJ_INLINE void bj_vec2_set (bj_vec2 res, bj_real_t a, bj_real_t b)
 Directly set the scalar values of a bj_vec2 object.
 
BJ_INLINE void bj_vec2_apply (bj_vec2 res, const bj_vec2 a, bj_real_t(*f)(bj_real_t))
 Invoke the given function to each scalar of the bj_vec2.
 
BJ_INLINE void bj_vec2_add (bj_vec2 res, const bj_vec2 lhs, const bj_vec2 rhs)
 Set res to the result of lhs+rhs.
 
BJ_INLINE void bj_vec2_sub (bj_vec2 res, const bj_vec2 lhs, const bj_vec2 rhs)
 Set res to the result of lhs-rhs.
 
BJ_INLINE void bj_vec2_scale (bj_vec2 res, const bj_vec2 v, bj_real_t s)
 Set res to the result of multiplying v by s.
 
BJ_INLINE void bj_vec2_scale_each (bj_vec2 res, const bj_vec2 v, const bj_vec2 s)
 Multiply each scalar of v by the respecting scalar in s.
 
BJ_INLINE bj_real_t bj_vec2_dot (const bj_vec2 a, const bj_vec2 b)
 Computes the dot product of a abnd b
 
BJ_INLINE bj_real_t bj_vec2_len (const bj_vec2 v)
 Computes the length of the vec2.
 
BJ_INLINE void bj_vec2_normalize (bj_vec2 res, const bj_vec2 v)
 Normalizes the provided vec2.
 
BJ_INLINE void bj_vec2_min (bj_vec2 res, const bj_vec2 a, const bj_vec2 b)
 Computes the component-wise minimum of two 2D vectors.
 
BJ_INLINE void bj_vec2_max (bj_vec2 res, const bj_vec2 a, const bj_vec2 b)
 Computes the component-wise maximum of two 2D vectors.
 
BJ_INLINE void bj_vec2_copy (bj_vec2 res, const bj_vec2 src)
 Copies the contents of one 2D vector to another.
 
BJ_INLINE void bj_vec3_set (bj_vec2 res, bj_real_t a, bj_real_t b, bj_real_t c)
 Directly set the scalar values of a bj_vec3 object.
 
BJ_INLINE void bj_vec3_apply (bj_vec3 res, const bj_vec3 a, bj_real_t(*f)(bj_real_t))
 Invoke the given function to each scalar of the bj_vec3.
 
BJ_INLINE void bj_vec3_add (bj_vec3 res, const bj_vec3 lhs, const bj_vec3 rhs)
 Set res to the result of lhs+rhs.
 
BJ_INLINE void bj_vec3_sub (bj_vec3 res, const bj_vec3 lhs, const bj_vec3 rhs)
 Set res to the result of lhs-rhs.
 
BJ_INLINE void bj_vec3_scale (bj_vec3 res, const bj_vec3 v, bj_real_t s)
 Set res to the result of multiplying v by s.
 
BJ_INLINE bj_real_t bj_vec3_dot (const bj_vec3 a, const bj_vec3 b)
 Computes the dot product of a abnd b
 
BJ_INLINE bj_real_t bj_vec3_len (const bj_vec3 v)
 Computes the length of the vec3.
 
BJ_INLINE void bj_vec3_normalize (bj_vec3 res, const bj_vec3 v)
 Normalizes the provided vec3.
 
BJ_INLINE void bj_vec3_min (bj_vec3 res, const bj_vec3 a, const bj_vec3 b)
 Computes the component-wise minimum of two 3D vectors.
 
BJ_INLINE void bj_vec3_max (bj_vec3 res, const bj_vec3 a, const bj_vec3 b)
 Computes the component-wise maximum of two 3D vectors.
 
BJ_INLINE void bj_vec3_copy (bj_vec3 res, const bj_vec3 src)
 Copies the contents of one 3D vector to another.
 
BJ_INLINE void bj_vec3_cross (bj_vec3 res, const bj_vec3 l, const bj_vec3 r)
 Computes the 3D cross product of two 3D vectors.
 
BJ_INLINE void bj_vec3_reflect (bj_vec3 res, const bj_vec3 v, const bj_vec3 n)
 Reflects a 3D vector around a given normal.
 
BJ_INLINE void bj_vec4_set (bj_vec2 res, bj_real_t a, bj_real_t b, bj_real_t c, bj_real_t d)
 Directly set the scalar values of a bj_vec4 object.
 
BJ_INLINE void bj_vec4_apply (bj_vec4 res, const bj_vec4 a, bj_real_t(*f)(bj_real_t))
 Invoke the given function to each scalar of the bj_vec4.
 
BJ_INLINE void bj_vec4_add (bj_vec4 res, const bj_vec4 lhs, const bj_vec4 rhs)
 Set res to the result of lhs+rhs.
 
BJ_INLINE void bj_vec4_sub (bj_vec4 res, const bj_vec4 lhs, const bj_vec4 rhs)
 Set res to the result of lhs-rhs.
 
BJ_INLINE void bj_vec4_scale (bj_vec4 res, const bj_vec4 v, bj_real_t s)
 Set res to the result of multiplying v by s.
 
BJ_INLINE bj_real_t bj_vec4_dot (const bj_vec4 a, const bj_vec4 b)
 Computes the dot product of a abnd b
 
BJ_INLINE bj_real_t bj_vec4_len (const bj_vec4 v)
 Computes the length of the vec4.
 
BJ_INLINE void bj_vec4_normalize (bj_vec4 res, const bj_vec4 v)
 Normalizes the provided vec4.
 
BJ_INLINE void bj_vec4_min (bj_vec4 res, const bj_vec4 a, const bj_vec4 b)
 Computes the component-wise minimum of two 4D vectors.
 
BJ_INLINE void bj_vec4_max (bj_vec4 res, const bj_vec4 a, const bj_vec4 b)
 Computes the component-wise maximum of two 4D vectors.
 
BJ_INLINE void bj_vec4_copy (bj_vec4 res, const bj_vec4 src)
 Copies the contents of one 4D vector to another.
 
BJ_INLINE void bj_vec4_cross (bj_vec4 res, const bj_vec4 l, const bj_vec4 r)
 Computes the 3D cross product of two 4D vectors, assuming w = 1.0.
 
BJ_INLINE void bj_vec4_reflect (bj_vec4 res, const bj_vec4 v, const bj_vec4 n)
 Reflects a 4D vector around a given normal.
 
BJ_INLINE void bj_mat4_identity (bj_mat4 mat)
 Initializes a 4x4 matrix to the identity matrix.
 
BJ_INLINE void bj_mat4_copy (bj_mat4 to, const bj_mat4 from)
 Copies a 4x4 matrix from one to another.
 
BJ_INLINE void bj_mat4_row (bj_vec4 res, const bj_mat4 mat, int r)
 Retrieves a specific row from a 4x4 matrix.
 
BJ_INLINE void bj_mat4_col (bj_vec4 res, const bj_mat4 mat, int c)
 Retrieves a specific column from a 4x4 matrix.
 
BJ_INLINE void bj_mat4_transpose (bj_mat4 res, const bj_mat4 mat)
 Transposes a 4x4 matrix.
 
BJ_INLINE void bj_mat4_add (bj_mat4 res, const bj_mat4 lhs, const bj_mat4 rhs)
 Adds two 4x4 matrices.
 
BJ_INLINE void bj_mat4_sub (bj_mat4 res, const bj_mat4 lhs, const bj_mat4 rhs)
 Subtracts one 4x4 matrix from another.
 
BJ_INLINE void bj_mat4_scale (bj_mat4 res, const bj_mat4 lhs, bj_real_t k)
 Scales a 4x4 matrix by a scalar.
 
BJ_INLINE void bj_mat4_scale_xyz (bj_mat4 res, const bj_mat4 mat, bj_real_t x, bj_real_t y, bj_real_t z)
 Scales the X, Y, and Z components of a 4x4 matrix.
 
BJ_INLINE void bj_mat4_mul (bj_mat4 res, const bj_mat4 lhs, const bj_mat4 rhs)
 Multiplies two 4x4 matrices.
 
BJ_INLINE void bj_mat4_mul_vec4 (bj_vec4 res, const bj_mat4 mat, const bj_vec4 v)
 Multiplies a 4x4 matrix by a 4D vector.
 
BJ_INLINE void bj_mat4_translation (bj_mat4 res, bj_real_t x, bj_real_t y, bj_real_t z)
 Creates a 4x4 translation matrix.
 
BJ_INLINE void bj_mat4_translation_inplace (bj_mat4 M, bj_real_t x, bj_real_t y, bj_real_t z)
 Applies a translation transformation to a 4x4 matrix in-place.
 
BJ_INLINE void bj_mat4_mul_outer (bj_mat4 res, const bj_vec3 a, const bj_vec3 b)
 Computes the outer product of two 3D vectors and stores the result in a 4x4 matrix.
 
BJ_INLINE void bj_mat4_rotate (bj_mat4 res, const bj_mat4 mat, bj_real_t x, bj_real_t y, bj_real_t z, bj_real_t angle)
 Rotates a 4x4 matrix by a given axis and angle.
 
BJ_INLINE void bj_ma4_rotate_x (bj_mat4 res, const bj_mat4 mat, bj_real_t angle)
 Rotates a 4x4 matrix around the X axis by a given angle.
 
BJ_INLINE void bj_ma4_rotate_y (bj_mat4 res, const bj_mat4 mat, bj_real_t angle)
 Rotates a 4x4 matrix around the Y axis by a given angle.
 
BJ_INLINE void bj_ma4_rotate_z (bj_mat4 res, const bj_mat4 mat, bj_real_t angle)
 Rotates a 4x4 matrix around the Z-axis by a given angle.
 
BJ_INLINE void bj_mat4_rotate_arcball (bj_mat4 R, const bj_mat4 M, bj_vec2 const _a, bj_vec2 const _b, bj_real_t s)
 Rotates a matrix based on arcball-style rotation from two 2D vectors.
 
BJ_INLINE void bj_mat4_inverse (bj_mat4 res, const bj_mat4 mat)
 Inverts a 4x4 matrix.
 
BJ_INLINE void bj_mat4_orthonormalize (bj_mat4 res, const bj_mat4 mat)
 Orthonormalizes the rows of a 4x4 matrix.
 
BJ_INLINE void bj_mat4_frustum (bj_mat4 fmat, bj_real_t l, bj_real_t r, bj_real_t b, bj_real_t t, bj_real_t n, bj_real_t f)
 Generates a perspective projection matrix for a frustum.
 
BJ_INLINE void bj_mat4_ortho (bj_mat4 omat, bj_real_t l, bj_real_t r, bj_real_t b, bj_real_t t, bj_real_t n, bj_real_t f)
 Generates an orthographic projection matrix.
 
BJ_INLINE void bj_mat4_perspective (bj_mat4 pmat, bj_real_t y_fov, bj_real_t aspect, bj_real_t n, bj_real_t f)
 Generates a perspective projection matrix based on field of view.
 
BJ_INLINE void bj_mat4_lookat (bj_mat4 m, const bj_vec3 eye, const bj_vec3 center, const bj_vec3 up)
 Generates a look-at matrix.
 
BJ_INLINE void bj_quat_identity (bj_quat q)
 Sets a quaternion to the identity quaternion.
 
BJ_INLINE void bj_quat_mul (bj_quat res, const bj_quat p, const bj_quat q)
 Multiplies two quaternions.
 
BJ_INLINE void bj_quat_conjugate (bj_quat res, const bj_quat q)
 Computes the conjugate of a quaternion.
 
BJ_INLINE void bj_quat_rotation (bj_quat res, bj_real_t angle, const bj_vec3 axis)
 Creates a rotation quaternion based on an angle and axis.
 
BJ_INLINE void bj_quat_mul_vec3 (bj_vec3 res, const bj_quat q, const bj_vec3 v)
 Applies a quaternion rotation to a 3D vector.
 
BJ_INLINE void bj_mat4_from_quat (bj_mat4 res, const bj_quat q)
 Converts a quaternion to a 4x4 rotation matrix.
 
BJ_INLINE void bj_mat4_rotate_from_quat (bj_mat4 R, const bj_mat4 M, const bj_quat q)
 Applies a quaternion rotation to each column of a matrix.
 
BJ_INLINE void bj_quat_from_mat4 (bj_quat q, const bj_mat4 M)
 Converts a 4x4 rotation matrix to a quaternion.
 

Typedef Documentation

◆ bj_mat4

typedef bj_vec4 bj_mat4[4]

This type represents a 4x4 matrix, where each row is a bj_vec4 vector. It is commonly used for transformations such as rotations, scaling, and translations.

Note
The matrix is represented as an array of four bj_vec4 values.
See also
bj_vec4

◆ bj_quat

typedef bj_real_t bj_quat[4]

This type represents a quaternion with four components, each of type bj_real_t. Quaternions are used for representing rotations in 3D space.

Note
The quaternion is represented as an array of four bj_real_t values.
See also
bj_real_t

◆ bj_vec2

typedef bj_real_t bj_vec2[2]

This type represents a 2D vector with two components, each of type bj_real_t. It is commonly used for storing 2D coordinates, directions, or other 2D data.

Note
The vector is represented as an array of two bj_real_t values.
See also
bj_real_t

◆ bj_vec3

typedef bj_real_t bj_vec3[3]

This type represents a 3D vector with three components, each of type bj_real_t. It is commonly used for storing 3D coordinates, directions, or other 3D data.

Note
The vector is represented as an array of three bj_real_t values.
See also
bj_real_t

◆ bj_vec4

typedef bj_real_t bj_vec4[4]

This type represents a 4D vector with four components, each of type bj_real_t. It is commonly used for storing 4D homogeneous coordinates or other 4D data.

Note
The vector is represented as an array of four bj_real_t values.
See also
bj_real_t

Function Documentation

◆ bj_ma4_rotate_x()

BJ_INLINE void bj_ma4_rotate_x ( bj_mat4 res,
const bj_mat4 mat,
bj_real_t angle )

This function performs a rotation of matrix mat around the X axis by angle (in radians), and stores the resulting matrix in res.

Parameters
resThe resulting rotated matrix.
matThe matrix to rotate.
angleThe angle to rotate by (in radians).

◆ bj_ma4_rotate_y()

BJ_INLINE void bj_ma4_rotate_y ( bj_mat4 res,
const bj_mat4 mat,
bj_real_t angle )

This function performs a rotation of matrix mat around the Y axis by angle (in radians), and stores the resulting matrix in res.

Parameters
resThe resulting rotated matrix.
matThe matrix to rotate.
angleThe angle to rotate by (in radians).

◆ bj_ma4_rotate_z()

BJ_INLINE void bj_ma4_rotate_z ( bj_mat4 res,
const bj_mat4 mat,
bj_real_t angle )

This function applies a rotation to the input matrix around the Z-axis by a specified angle and stores the result in the output matrix.

Parameters
matThe 4x4 matrix to rotate.
angleThe angle (in radians) to rotate the matrix around the Z-axis.
resThe resulting rotated matrix.

◆ bj_mat4_add()

BJ_INLINE void bj_mat4_add ( bj_mat4 res,
const bj_mat4 lhs,
const bj_mat4 rhs )

Computes the element-wise addition of two matrices lhs and rhs and stores the result in res.

Parameters
resThe resulting matrix after addition.
lhsThe left-hand matrix to add.
rhsThe right-hand matrix to add.

◆ bj_mat4_col()

BJ_INLINE void bj_mat4_col ( bj_vec4 res,
const bj_mat4 mat,
int c )

Extracts the column at index c from matrix mat and stores it in res.

Parameters
resThe resulting column vector.
matThe matrix from which to extract the column.
cThe column index (0-based) to extract.

◆ bj_mat4_copy()

BJ_INLINE void bj_mat4_copy ( bj_mat4 to,
const bj_mat4 from )

Copies the entire contents of the matrix from to the matrix to.

Parameters
toThe destination matrix.
fromThe source matrix to copy from.

◆ bj_mat4_from_quat()

BJ_INLINE void bj_mat4_from_quat ( bj_mat4 res,
const bj_quat q )

This function converts the given quaternion into a 4x4 rotation matrix.

Parameters
resThe resulting 4x4 rotation matrix.
qThe quaternion to convert.

◆ bj_mat4_frustum()

BJ_INLINE void bj_mat4_frustum ( bj_mat4 fmat,
bj_real_t l,
bj_real_t r,
bj_real_t b,
bj_real_t t,
bj_real_t n,
bj_real_t f )

This function generates a perspective projection matrix based on a frustum defined by the left, right, bottom, top, near, and far clipping planes.

Parameters
lThe left plane of the frustum.
rThe right plane of the frustum.
bThe bottom plane of the frustum.
tThe top plane of the frustum.
nThe near plane of the frustum.
fThe far plane of the frustum.
fmatThe resulting perspective projection matrix.

◆ bj_mat4_identity()

BJ_INLINE void bj_mat4_identity ( bj_mat4 mat)

Sets all diagonal elements of the matrix to 1.0 and all off-diagonal elements to 0.0.

Parameters
matThe matrix to be initialized as the identity matrix.

◆ bj_mat4_inverse()

BJ_INLINE void bj_mat4_inverse ( bj_mat4 res,
const bj_mat4 mat )

This function calculates the inverse of the given 4x4 matrix and stores it in the result matrix. It uses a standard matrix inversion method for 4x4 matrices.

Parameters
matThe matrix to invert.
resThe resulting inverted matrix.

◆ bj_mat4_lookat()

BJ_INLINE void bj_mat4_lookat ( bj_mat4 m,
const bj_vec3 eye,
const bj_vec3 center,
const bj_vec3 up )

This function generates a view matrix that transforms coordinates from world space to camera space based on the eye position, center (target) position, and up vector.

Parameters
eyeThe position of the camera.
centerThe target position the camera is looking at.
upThe up vector of the camera.
mThe resulting look-at matrix.

◆ bj_mat4_mul()

BJ_INLINE void bj_mat4_mul ( bj_mat4 res,
const bj_mat4 lhs,
const bj_mat4 rhs )

Computes the matrix product of lhs and rhs and stores the result in res.

Parameters
resThe resulting matrix after multiplication.
lhsThe left-hand matrix.
rhsThe right-hand matrix.

◆ bj_mat4_mul_outer()

BJ_INLINE void bj_mat4_mul_outer ( bj_mat4 res,
const bj_vec3 a,
const bj_vec3 b )

Computes the outer product of vectors a and b and stores the result in matrix res. The result is a matrix where elements are the products of corresponding components of the vectors.

Parameters
resThe resulting 4x4 matrix from the outer product.
aThe first 3D vector.
bThe second 3D vector.

◆ bj_mat4_mul_vec4()

BJ_INLINE void bj_mat4_mul_vec4 ( bj_vec4 res,
const bj_mat4 mat,
const bj_vec4 v )

Computes the matrix-vector product of matrix mat and vector v and stores the result in res.

Parameters
resThe resulting vector after multiplication.
matThe matrix to multiply.
vThe vector to multiply.

◆ bj_mat4_ortho()

BJ_INLINE void bj_mat4_ortho ( bj_mat4 omat,
bj_real_t l,
bj_real_t r,
bj_real_t b,
bj_real_t t,
bj_real_t n,
bj_real_t f )

This function generates an orthographic projection matrix for the specified left, right, bottom, top, near, and far clipping planes.

Parameters
lThe left plane of the orthographic projection.
rThe right plane of the orthographic projection.
bThe bottom plane of the orthographic projection.
tThe top plane of the orthographic projection.
nThe near plane of the orthographic projection.
fThe far plane of the orthographic projection.
omatThe resulting orthographic projection matrix.

◆ bj_mat4_orthonormalize()

BJ_INLINE void bj_mat4_orthonormalize ( bj_mat4 res,
const bj_mat4 mat )

This function orthonormalizes the rows of the matrix, ensuring that the matrix rows are orthogonal and normalized.

Parameters
matThe 4x4 matrix to orthonormalize.
resThe resulting orthonormalized 4x4 matrix.

◆ bj_mat4_perspective()

BJ_INLINE void bj_mat4_perspective ( bj_mat4 pmat,
bj_real_t y_fov,
bj_real_t aspect,
bj_real_t n,
bj_real_t f )

This function generates a perspective projection matrix based on the field of view (y_fov), aspect ratio, and near and far clipping planes.

Parameters
y_fovThe vertical field of view in radians.
aspectThe aspect ratio (width / height).
nThe near clipping plane.
fThe far clipping plane.
pmatThe resulting perspective projection matrix.

◆ bj_mat4_rotate()

BJ_INLINE void bj_mat4_rotate ( bj_mat4 res,
const bj_mat4 mat,
bj_real_t x,
bj_real_t y,
bj_real_t z,
bj_real_t angle )

This function performs a 3D rotation on matrix mat around an arbitrary axis (x, y, z) by angle (in radians), and stores the resulting matrix in res. The axis vector is normalized before the rotation.

Parameters
resThe resulting rotated matrix.
matThe matrix to rotate.
xThe X component of the axis of rotation.
yThe Y component of the axis of rotation.
zThe Z component of the axis of rotation.
angleThe angle to rotate by (in radians).

◆ bj_mat4_rotate_arcball()

BJ_INLINE void bj_mat4_rotate_arcball ( bj_mat4 R,
const bj_mat4 M,
bj_vec2 const _a,
bj_vec2 const _b,
bj_real_t s )

This function computes the rotation matrix that represents the arcball rotation based on two 2D input vectors (a, b), the input matrix, and a scaling factor. It normalizes the vectors and calculates the rotation axis and angle, applying the rotation to the matrix.

Parameters
MThe input matrix to rotate.
_aThe first 2D vector for the arcball rotation.
_bThe second 2D vector for the arcball rotation.
sA scaling factor for the rotation angle.
RThe resulting rotation matrix.

◆ bj_mat4_rotate_from_quat()

BJ_INLINE void bj_mat4_rotate_from_quat ( bj_mat4 R,
const bj_mat4 M,
const bj_quat q )

This function applies the rotation represented by the given quaternion to each column of the given matrix, transforming it into the rotated matrix.

Parameters
RThe resulting rotated matrix.
MThe matrix to rotate.
qThe quaternion representing the rotation.

◆ bj_mat4_row()

BJ_INLINE void bj_mat4_row ( bj_vec4 res,
const bj_mat4 mat,
int r )

Extracts the row at index r from matrix mat and stores it in res.

Parameters
resThe resulting row vector.
matThe matrix from which to extract the row.
rThe row index (0-based) to extract.

◆ bj_mat4_scale()

BJ_INLINE void bj_mat4_scale ( bj_mat4 res,
const bj_mat4 lhs,
bj_real_t k )

Multiplies each element of the matrix lhs by the scalar k and stores the result in res.

Parameters
resThe resulting scaled matrix.
lhsThe matrix to scale.
kThe scalar by which to scale the matrix.

◆ bj_mat4_scale_xyz()

BJ_INLINE void bj_mat4_scale_xyz ( bj_mat4 res,
const bj_mat4 mat,
bj_real_t x,
bj_real_t y,
bj_real_t z )

Scales the X, Y, and Z components of the matrix mat by x, y, and z respectively. The W component is left unchanged and copied directly from mat.

Parameters
resThe resulting scaled matrix.
matThe matrix to scale.
xThe scaling factor for the X component.
yThe scaling factor for the Y component.
zThe scaling factor for the Z component.

◆ bj_mat4_sub()

BJ_INLINE void bj_mat4_sub ( bj_mat4 res,
const bj_mat4 lhs,
const bj_mat4 rhs )

Computes the element-wise subtraction of two matrices lhs and rhs and stores the result in res.

Parameters
resThe resulting matrix after subtraction.
lhsThe matrix to subtract from.
rhsThe matrix to subtract.

◆ bj_mat4_translation()

BJ_INLINE void bj_mat4_translation ( bj_mat4 res,
bj_real_t x,
bj_real_t y,
bj_real_t z )

Creates a translation matrix that translates a point by x, y, and z in 3D space.

Parameters
resThe resulting translation matrix.
xThe translation distance along the X axis.
yThe translation distance along the Y axis.
zThe translation distance along the Z axis.

◆ bj_mat4_translation_inplace()

BJ_INLINE void bj_mat4_translation_inplace ( bj_mat4 M,
bj_real_t x,
bj_real_t y,
bj_real_t z )

This function adds a translation by x, y, and z to the matrix M in-place. The translation vector is applied by modifying the last column of the matrix.

Parameters
[in,out]MThe matrix to apply the translation to (modified in-place).
xThe translation distance along the X axis.
yThe translation distance along the Y axis.
zThe translation distance along the Z axis.

◆ bj_mat4_transpose()

BJ_INLINE void bj_mat4_transpose ( bj_mat4 res,
const bj_mat4 mat )

Computes the transpose of matrix mat and stores it in res. The rows of mat become the columns of res.

Parameters
resThe transposed matrix.
matThe matrix to transpose.

◆ bj_quat_conjugate()

BJ_INLINE void bj_quat_conjugate ( bj_quat res,
const bj_quat q )

This function computes the conjugate of the given quaternion, which involves negating the vector part (x, y, z) of the quaternion while keeping the scalar part unchanged.

Parameters
resThe resulting conjugated quaternion.
qThe quaternion to conjugate.

◆ bj_quat_from_mat4()

BJ_INLINE void bj_quat_from_mat4 ( bj_quat q,
const bj_mat4 M )

This function converts the given 4x4 rotation matrix into a quaternion.

Parameters
qThe resulting quaternion.
MThe 4x4 rotation matrix to convert.

◆ bj_quat_identity()

BJ_INLINE void bj_quat_identity ( bj_quat q)

This function sets the given quaternion to the identity quaternion (0, 0, 0, 1).

Parameters
qThe quaternion to set as the identity.

◆ bj_quat_mul()

BJ_INLINE void bj_quat_mul ( bj_quat res,
const bj_quat p,
const bj_quat q )

This function computes the product of two quaternions, following the quaternion multiplication rules, and stores the result in the output quaternion.

Parameters
resThe resulting quaternion after multiplication.
pThe first quaternion.
qThe second quaternion.

◆ bj_quat_mul_vec3()

BJ_INLINE void bj_quat_mul_vec3 ( bj_vec3 res,
const bj_quat q,
const bj_vec3 v )

This function rotates a 3D vector using the given quaternion, which represents the rotation.

Parameters
resThe resulting rotated vector.
qThe quaternion representing the rotation.
vThe 3D vector to rotate.

◆ bj_quat_rotation()

BJ_INLINE void bj_quat_rotation ( bj_quat res,
bj_real_t angle,
const bj_vec3 axis )

This function generates a quaternion representing a rotation of the specified angle (in radians) around the given axis.

Parameters
resThe resulting rotation quaternion.
angleThe angle (in radians) of rotation.
axisThe axis around which the rotation occurs.

◆ bj_vec2_add()

BJ_INLINE void bj_vec2_add ( bj_vec2 res,
const bj_vec2 lhs,
const bj_vec2 rhs )
Parameters
resThe destination vec2
lhsThe first source vec2
rhsThe second source vec2

◆ bj_vec2_apply()

BJ_INLINE void bj_vec2_apply ( bj_vec2 res,
const bj_vec2 a,
bj_real_t(* )(bj_real_t) )
Parameters
resA location to the target vec2
aA location to the source vec2
fThe map function
Examples
shaders.c.

◆ bj_vec2_copy()

BJ_INLINE void bj_vec2_copy ( bj_vec2 res,
const bj_vec2 src )
Parameters
resThe destination vector.
srcThe source vector to copy.
Examples
shaders.c.

◆ bj_vec2_dot()

BJ_INLINE bj_real_t bj_vec2_dot ( const bj_vec2 a,
const bj_vec2 b )
Parameters
aThe first vec2
bThe second vec2
Returns
The resulting dot product

◆ bj_vec2_len()

BJ_INLINE bj_real_t bj_vec2_len ( const bj_vec2 v)
Parameters
vThe vec2
Returns
The length
Examples
shaders.c.

◆ bj_vec2_max()

BJ_INLINE void bj_vec2_max ( bj_vec2 res,
const bj_vec2 a,
const bj_vec2 b )
Parameters
resThe result vector, where each component is the maximum of a and b.
aThe first input vector.
bThe second input vector.

◆ bj_vec2_min()

BJ_INLINE void bj_vec2_min ( bj_vec2 res,
const bj_vec2 a,
const bj_vec2 b )
Parameters
resThe result vector, where each component is the minimum of a and b.
aThe first input vector.
bThe second input vector.

◆ bj_vec2_normalize()

BJ_INLINE void bj_vec2_normalize ( bj_vec2 res,
const bj_vec2 v )
Parameters
resThe resulting vec2
vThe vec2

◆ bj_vec2_scale()

BJ_INLINE void bj_vec2_scale ( bj_vec2 res,
const bj_vec2 v,
bj_real_t s )
Parameters
resThe destination vec2
vThe source vec2
sThe factor value
Examples
shaders.c.

◆ bj_vec2_scale_each()

BJ_INLINE void bj_vec2_scale_each ( bj_vec2 res,
const bj_vec2 v,
const bj_vec2 s )
Parameters
resThe destination vec2
vThe source vec2
sThe scalar vec2

◆ bj_vec2_set()

BJ_INLINE void bj_vec2_set ( bj_vec2 res,
bj_real_t a,
bj_real_t b )
Parameters
resA location to the target vec4
aThe first scalar value
bThe second scalar value

◆ bj_vec2_sub()

BJ_INLINE void bj_vec2_sub ( bj_vec2 res,
const bj_vec2 lhs,
const bj_vec2 rhs )
Parameters
resThe destination vec2
lhsThe first source vec2
rhsThe second source vec2
Examples
shaders.c.

◆ bj_vec3_add()

BJ_INLINE void bj_vec3_add ( bj_vec3 res,
const bj_vec3 lhs,
const bj_vec3 rhs )
Parameters
resThe destination vec3
lhsThe first source vec3
rhsThe second source vec3
Examples
shaders.c.

◆ bj_vec3_apply()

BJ_INLINE void bj_vec3_apply ( bj_vec3 res,
const bj_vec3 a,
bj_real_t(* )(bj_real_t) )
Parameters
resA location to the target vec3
aA location to the source vec3
fThe map function

◆ bj_vec3_copy()

BJ_INLINE void bj_vec3_copy ( bj_vec3 res,
const bj_vec3 src )
Parameters
resThe destination vector.
srcThe source vector to copy.
Examples
shaders.c.

◆ bj_vec3_cross()

BJ_INLINE void bj_vec3_cross ( bj_vec3 res,
const bj_vec3 l,
const bj_vec3 r )
Parameters
resThe resulting vector (cross product of l and r).
lThe left-hand input vector.
rThe right-hand input vector.

◆ bj_vec3_dot()

BJ_INLINE bj_real_t bj_vec3_dot ( const bj_vec3 a,
const bj_vec3 b )
Parameters
aThe first vec3
bThe second vec3
Returns
The resulting dot product

◆ bj_vec3_len()

BJ_INLINE bj_real_t bj_vec3_len ( const bj_vec3 v)
Parameters
vThe vec3
Returns
The length

◆ bj_vec3_max()

BJ_INLINE void bj_vec3_max ( bj_vec3 res,
const bj_vec3 a,
const bj_vec3 b )
Parameters
resThe result vector, where each component is the maximum of a and b.
aThe first input vector.
bThe second input vector.

◆ bj_vec3_min()

BJ_INLINE void bj_vec3_min ( bj_vec3 res,
const bj_vec3 a,
const bj_vec3 b )
Parameters
resThe result vector, where each component is the minimum of a and b.
aThe first input vector.
bThe second input vector.

◆ bj_vec3_normalize()

BJ_INLINE void bj_vec3_normalize ( bj_vec3 res,
const bj_vec3 v )
Parameters
resThe resulting vec3
vThe vec3

◆ bj_vec3_reflect()

BJ_INLINE void bj_vec3_reflect ( bj_vec3 res,
const bj_vec3 v,
const bj_vec3 n )

Computes the reflection of vector v across the normal vector n. Assumes both vectors are 3D, and uses all three components.

Parameters
resThe reflected vector.
vThe incident vector.
nThe normal vector (should be normalized).

◆ bj_vec3_scale()

BJ_INLINE void bj_vec3_scale ( bj_vec3 res,
const bj_vec3 v,
bj_real_t s )
Parameters
resThe destination vec3
vThe source vec3
sThe factor value
Examples
shaders.c.

◆ bj_vec3_set()

BJ_INLINE void bj_vec3_set ( bj_vec2 res,
bj_real_t a,
bj_real_t b,
bj_real_t c )
Parameters
resA location to the target vec4
aThe first scalar value
bThe second scalar value
cThe third scalar value

◆ bj_vec3_sub()

BJ_INLINE void bj_vec3_sub ( bj_vec3 res,
const bj_vec3 lhs,
const bj_vec3 rhs )
Parameters
resThe destination vec3
lhsThe first source vec3
rhsThe second source vec3

◆ bj_vec4_add()

BJ_INLINE void bj_vec4_add ( bj_vec4 res,
const bj_vec4 lhs,
const bj_vec4 rhs )
Parameters
resThe destination vec4
lhsThe first source vec4
rhsThe second source vec4

◆ bj_vec4_apply()

BJ_INLINE void bj_vec4_apply ( bj_vec4 res,
const bj_vec4 a,
bj_real_t(* )(bj_real_t) )
Parameters
resA location to the target vec4
aA location to the source vec4
fThe map function

◆ bj_vec4_copy()

BJ_INLINE void bj_vec4_copy ( bj_vec4 res,
const bj_vec4 src )
Parameters
resThe destination vector.
srcThe source vector to copy.

◆ bj_vec4_cross()

BJ_INLINE void bj_vec4_cross ( bj_vec4 res,
const bj_vec4 l,
const bj_vec4 r )

Only the x, y, and z components are used for the cross product. The w component of the result is set to 1.0.

Parameters
resThe resulting vector.
lThe left-hand input vector.
rThe right-hand input vector.

◆ bj_vec4_dot()

BJ_INLINE bj_real_t bj_vec4_dot ( const bj_vec4 a,
const bj_vec4 b )
Parameters
aThe first vec4
bThe second vec4
Returns
The resulting dot product

◆ bj_vec4_len()

BJ_INLINE bj_real_t bj_vec4_len ( const bj_vec4 v)
Parameters
vThe vec4
Returns
The length

◆ bj_vec4_max()

BJ_INLINE void bj_vec4_max ( bj_vec4 res,
const bj_vec4 a,
const bj_vec4 b )
Parameters
resThe result vector, where each component is the maximum of a and b.
aThe first input vector.
bThe second input vector.

◆ bj_vec4_min()

BJ_INLINE void bj_vec4_min ( bj_vec4 res,
const bj_vec4 a,
const bj_vec4 b )
Parameters
resThe result vector, where each component is the minimum of a and b.
aThe first input vector.
bThe second input vector.

◆ bj_vec4_normalize()

BJ_INLINE void bj_vec4_normalize ( bj_vec4 res,
const bj_vec4 v )
Parameters
resThe resulting vec4
vThe vec4

◆ bj_vec4_reflect()

BJ_INLINE void bj_vec4_reflect ( bj_vec4 res,
const bj_vec4 v,
const bj_vec4 n )

Computes the reflection of vector v across the normal vector n. Assumes both vectors are 4D, and uses all four components.

Parameters
resThe reflected vector.
vThe incident vector.
nThe normal vector (should be normalized).

◆ bj_vec4_scale()

BJ_INLINE void bj_vec4_scale ( bj_vec4 res,
const bj_vec4 v,
bj_real_t s )
Parameters
resThe destination vec2
vThe source vec2
sThe factor value

◆ bj_vec4_set()

BJ_INLINE void bj_vec4_set ( bj_vec2 res,
bj_real_t a,
bj_real_t b,
bj_real_t c,
bj_real_t d )
Parameters
resA location to the target vec4
aThe first scalar value
bThe second scalar value
cThe third scalar value
dThe fourth scalar value

◆ bj_vec4_sub()

BJ_INLINE void bj_vec4_sub ( bj_vec4 res,
const bj_vec4 lhs,
const bj_vec4 rhs )
Parameters
resThe destination vec4
lhsThe first source vec4
rhsThe second source vec4