26#define bj_real_t float
28#ifndef BJ_COMPILER_DOXYGEN
29# define real_sqrt bj_sqrtf
30# define real_acos bj_acosf
31# define BJ_INLINE static inline
98 res[0] = a; res[1] = b;
122 res[0] = lhs[0] + rhs[0];
123 res[1] = lhs[1] + rhs[1];
138 res[0] = a[0] + b[0] * s;
139 res[1] = a[1] + b[1] * s;
150 res[0] = lhs[0] - rhs[0];
151 res[1] = lhs[1] - rhs[1];
174 res[0] = v[0] * s[0];
175 res[1] = v[1] * s[1];
186 return a[0] * b[0] + a[1] * b[1];
196 return real_sqrt(v[0] * v[0] + v[1] * v[1]);
206 bj_real_t inv_len = 1.0f / real_sqrt(v[0] * v[0] + v[1] * v[1]);
207 res[0] = v[0] * inv_len;
208 res[1] = v[1] * inv_len;
219 res[0] = a[0] < b[0] ? a[0] : b[0];
220 res[1] = a[1] < b[1] ? a[1] : b[1];
231 res[0] = a[0] > b[0] ? a[0] : b[0];
232 res[1] = a[1] > b[1] ? a[1] : b[1];
256 res[0] = a; res[1] = b; res[2] = c;
282 res[0] = lhs[0] + rhs[0];
283 res[1] = lhs[1] + rhs[1];
284 res[2] = lhs[2] + rhs[2];
298 res[0] = a[0] + b[0] * s;
299 res[1] = a[1] + b[1] * s;
300 res[2] = a[2] + b[2] * s;
312 res[0] = lhs[0] - rhs[0];
313 res[1] = lhs[1] - rhs[1];
314 res[2] = lhs[2] - rhs[2];
338 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
348 return real_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
358 bj_real_t inv_len = 1.0f / real_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
359 res[0] = v[0] * inv_len;
360 res[1] = v[1] * inv_len;
361 res[2] = v[2] * inv_len;
372 res[0] = a[0] < b[0] ? a[0] : b[0];
373 res[1] = a[1] < b[1] ? a[1] : b[1];
374 res[2] = a[2] < b[2] ? a[2] : b[2];
385 res[0] = a[0] > b[0] ? a[0] : b[0];
386 res[1] = a[1] > b[1] ? a[1] : b[1];
387 res[2] = a[2] > b[2] ? a[2] : b[2];
411 res[0] = l[1] * r[2] - l[2] * r[1];
412 res[1] = l[2] * r[0] - l[0] * r[2];
413 res[2] = l[0] * r[1] - l[1] * r[0];
429 for (
int i = 0; i < 3; ++i) {
430 res[i] = v[i] - p * n[i];
446 res[0] = a; res[1] = b; res[2] = c; res[3] = d;
472 res[0] = lhs[0] + rhs[0];
473 res[1] = lhs[1] + rhs[1];
474 res[2] = lhs[2] + rhs[2];
475 res[3] = lhs[3] + rhs[3];
489 res[0] = a[0] + b[0] * s;
490 res[1] = a[1] + b[1] * s;
491 res[2] = a[2] + b[2] * s;
492 res[3] = a[3] + b[3] * s;
503 res[0] = lhs[0] - rhs[0];
504 res[1] = lhs[1] - rhs[1];
505 res[2] = lhs[2] - rhs[2];
506 res[3] = lhs[3] - rhs[3];
531 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
541 return real_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
551 bj_real_t inv_len = 1.0f / real_sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3]);
552 res[0] = v[0] * inv_len;
553 res[1] = v[1] * inv_len;
554 res[2] = v[2] * inv_len;
555 res[3] = v[3] * inv_len;
566 res[0] = a[0] < b[0] ? a[0] : b[0];
567 res[1] = a[1] < b[1] ? a[1] : b[1];
568 res[2] = a[2] < b[2] ? a[2] : b[2];
569 res[3] = a[3] < b[3] ? a[3] : b[3];
580 res[0] = a[0] > b[0] ? a[0] : b[0];
581 res[1] = a[1] > b[1] ? a[1] : b[1];
582 res[2] = a[2] > b[2] ? a[2] : b[2];
583 res[3] = a[3] > b[3] ? a[3] : b[3];
611 res[0] = l[1] * r[2] - l[2] * r[1];
612 res[1] = l[2] * r[0] - l[0] * r[2];
613 res[2] = l[0] * r[1] - l[1] * r[0];
630 for (
int i = 0; i < 4; ++i) {
631 res[i] = v[i] - p * n[i];
644 for (
int i = 0; i < 4; ++i) {
645 for (
int j = 0; j < 4; ++j) {
646 mat[i][j] = i == j ? 1.f : 0.f;
661 for (
int i = 0; i < 4; ++i) {
677 for (
int k = 0; k < 4; ++k) {
693 for (
int k = 0; k < 4; ++k) {
709 for (
int j = 0; j < 4; ++j) {
710 for (
int i = 0; i < 4; ++i) {
711 res[i][j] = mat[j][i];
727 for (
int i = 0; i < 4; ++i) {
743 for (
int i = 0; i < 4; ++i) {
759 for (
int i = 0; i < 4; ++i) {
796 for (
int c = 0; c < 4; ++c) {
797 for (
int r = 0; r < 4; ++r) {
799 for (
int k = 0; k < 4; ++k)
800 temp[c][r] += lhs[k][r] * rhs[c][k];
817 for (
int j = 0; j < 4; ++j) {
819 for (
int i = 0; i < 4; ++i) {
820 res[j] += mat[i][j] * v[i];
858 for (
int i = 0; i < 4; ++i) {
876 for (
int i = 0; i < 4; ++i) {
877 for (
int j = 0; j < 4; ++j) {
878 res[i][j] = i < 3 && j < 3 ? a[i] * b[j] : 0.f;
908 { 0, u[2], -u[1], 0},
910 { u[1], -u[0], 0, 0},
946 {1.f, 0.f, 0.f, 0.f},
970 { 0.f, 1.f, 0.f, 0.f},
972 { 0.f, 0.f, 0.f, 1.f}
994 { 0.f, 0.f, 1.f, 0.f},
995 { 0.f, 0.f, 0.f, 1.f}
1018 bj_vec2 b = { _b[0], _b[1] };;
1037 bj_vec3 a_ = { a[0], a[1], z_a };
1038 bj_vec3 b_ = { b[0], b[1], z_b };
1059 s[0] = mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1];
1060 s[1] = mat[0][0] * mat[1][2] - mat[1][0] * mat[0][2];
1061 s[2] = mat[0][0] * mat[1][3] - mat[1][0] * mat[0][3];
1062 s[3] = mat[0][1] * mat[1][2] - mat[1][1] * mat[0][2];
1063 s[4] = mat[0][1] * mat[1][3] - mat[1][1] * mat[0][3];
1064 s[5] = mat[0][2] * mat[1][3] - mat[1][2] * mat[0][3];
1066 c[0] = mat[2][0] * mat[3][1] - mat[3][0] * mat[2][1];
1067 c[1] = mat[2][0] * mat[3][2] - mat[3][0] * mat[2][2];
1068 c[2] = mat[2][0] * mat[3][3] - mat[3][0] * mat[2][3];
1069 c[3] = mat[2][1] * mat[3][2] - mat[3][1] * mat[2][2];
1070 c[4] = mat[2][1] * mat[3][3] - mat[3][1] * mat[2][3];
1071 c[5] = mat[2][2] * mat[3][3] - mat[3][2] * mat[2][3];
1073 bj_real_t idet = 1.0f / (s[0] * c[5] - s[1] * c[4] + s[2] * c[3] + s[3] * c[2] - s[4] * c[1] + s[5] * c[0]);
1075 res[0][0] = (mat[1][1] * c[5] - mat[1][2] * c[4] + mat[1][3] * c[3]) * idet;
1076 res[0][1] = (-mat[0][1] * c[5] + mat[0][2] * c[4] - mat[0][3] * c[3]) * idet;
1077 res[0][2] = (mat[3][1] * s[5] - mat[3][2] * s[4] + mat[3][3] * s[3]) * idet;
1078 res[0][3] = (-mat[2][1] * s[5] + mat[2][2] * s[4] - mat[2][3] * s[3]) * idet;
1080 res[1][0] = (-mat[1][0] * c[5] + mat[1][2] * c[2] - mat[1][3] * c[1]) * idet;
1081 res[1][1] = (mat[0][0] * c[5] - mat[0][2] * c[2] + mat[0][3] * c[1]) * idet;
1082 res[1][2] = (-mat[3][0] * s[5] + mat[3][2] * s[2] - mat[3][3] * s[1]) * idet;
1083 res[1][3] = (mat[2][0] * s[5] - mat[2][2] * s[2] + mat[2][3] * s[1]) * idet;
1085 res[2][0] = (mat[1][0] * c[4] - mat[1][1] * c[2] + mat[1][3] * c[0]) * idet;
1086 res[2][1] = (-mat[0][0] * c[4] + mat[0][1] * c[2] - mat[0][3] * c[0]) * idet;
1087 res[2][2] = (mat[3][0] * s[4] - mat[3][1] * s[2] + mat[3][3] * s[0]) * idet;
1088 res[2][3] = (-mat[2][0] * s[4] + mat[2][1] * s[2] - mat[2][3] * s[0]) * idet;
1090 res[3][0] = (-mat[1][0] * c[3] + mat[1][1] * c[1] - mat[1][2] * c[0]) * idet;
1091 res[3][1] = (mat[0][0] * c[3] - mat[0][1] * c[1] + mat[0][2] * c[0]) * idet;
1092 res[3][2] = (-mat[3][0] * s[3] + mat[3][1] * s[1] - mat[3][2] * s[0]) * idet;
1093 res[3][3] = (mat[2][0] * s[3] - mat[2][1] * s[1] + mat[2][2] * s[0]) * idet;
1142 fmat[0][0] = 2.f * n / (r - l);
1143 fmat[0][1] = fmat[0][2] = fmat[0][3] = 0.f;
1144 fmat[1][1] = 2.f * n / (t - b);
1145 fmat[1][0] = fmat[1][2] = fmat[1][3] = 0.f;
1146 fmat[2][0] = (r + l) / (r - l);
1147 fmat[2][1] = (t + b) / (t - b);
1148 fmat[2][2] = -(f + n) / (f - n);
1150 fmat[3][2] = -2.f * (f * n) / (f - n);
1151 fmat[3][0] = fmat[3][1] = fmat[3][3] = 0.f;
1169 omat[0][0] = 2.f / (r - l);
1170 omat[0][1] = omat[0][2] = omat[0][3] = 0.f;
1171 omat[1][1] = 2.f / (t - b);
1172 omat[1][0] = omat[1][2] = omat[1][3] = 0.f;
1173 omat[2][2] = -2.f / (f - n);
1174 omat[2][0] = omat[2][1] = omat[2][3] = 0.f;
1175 omat[3][0] = -(r + l) / (r - l);
1176 omat[3][1] = -(t + b) / (t - b);
1177 omat[3][2] = -(f + n) / (f - n);
1195 pmat[0][0] = a / aspect;
1205 pmat[2][2] = -((f + n) / (f - n));
1209 pmat[3][2] = -((2.f * f * n) / (f - n));
1262#define bj_quat_add bj_vec4_add
1266#define bj_quat_sub bj_vec4_sub
1270#define bj_quat_norm bj_vec4_normalize
1274#define bj_quat_scale bj_vec4_scale
1278#define bj_quat_dot bj_vec4_dot
1289 q[0] = q[1] = q[2] = 0.f;
1329 for (
int i = 0; i < 3; ++i) {
1366 bj_vec3 q_xyz = { q[0], q[1], q[2] };
1367 bj_vec3 u = { q[0], q[1], q[2] };
1397 res[0][0] = a2 + b2 - c2 - d2;
1398 res[0][1] = 2.f * (b * c + a * d);
1399 res[0][2] = 2.f * (b * d - a * c);
1402 res[1][0] = 2 * (b * c - a * d);
1403 res[1][1] = a2 - b2 + c2 - d2;
1404 res[1][2] = 2.f * (c * d + a * b);
1407 res[2][0] = 2.f * (b * d + a * c);
1408 res[2][1] = 2.f * (c * d - a * b);
1409 res[2][2] = a2 - b2 - c2 + d2;
1412 res[3][0] = res[3][1] = res[3][2] = 0.f;
1431 R[3][0] = R[3][1] = R[3][2] = 0.f;
1450 int perm[] = { 0, 1, 2, 0, 1 };
1453 for (i = 0; i < 3; i++) {
1465 r = real_sqrt(1.f + M[i][i] - M[j][j] - M[k][k]);
1478 q[j] = (M[i][j] + M[j][i]) * inv;
1479 q[k] = (M[k][i] + M[i][k]) * inv;
1480 q[3] = (M[k][j] - M[j][k]) * inv;
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.
Definition linmath.h:1225
BJ_INLINE bj_real_t bj_vec4_len(const bj_vec4 v)
Computes the length of the vec4.
Definition linmath.h:540
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.
Definition linmath.h:218
BJ_INLINE bj_real_t bj_vec2_len(const bj_vec2 v)
Computes the length of the vec2.
Definition linmath.h:195
bj_real_t bj_vec4[4]
Defines a 4D vector type.
Definition linmath.h:65
BJ_INLINE void bj_vec2_copy(bj_vec2 res, const bj_vec2 src)
Copies the contents of one 2D vector to another.
Definition linmath.h:241
BJ_INLINE void bj_mat4_col(bj_vec4 res, const bj_mat4 mat, int c)
Retrieves a specific column from a 4x4 matrix.
Definition linmath.h:691
#define bj_sinf
Wrapper for the standard sinf() function.
Definition math.h:137
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.
Definition linmath.h:1141
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.
Definition linmath.h:1193
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.
Definition linmath.h:281
BJ_INLINE bj_real_t bj_vec2_dot(const bj_vec2 a, const bj_vec2 b)
Computes the dot product of a abnd b
Definition linmath.h:185
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.
Definition linmath.h:457
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.
Definition linmath.h:1426
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.
Definition linmath.h:1015
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.
Definition linmath.h:565
BJ_INLINE void bj_mat4_sub(bj_mat4 res, const bj_mat4 lhs, const bj_mat4 rhs)
Subtracts one 4x4 matrix from another.
Definition linmath.h:741
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.
Definition linmath.h:173
BJ_INLINE void bj_quat_from_mat4(bj_quat q, const bj_mat4 M)
Converts a 4x4 rotation matrix to a quaternion.
Definition linmath.h:1446
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.
Definition linmath.h:874
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.
Definition linmath.h:149
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.
Definition linmath.h:964
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.
Definition linmath.h:627
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.
Definition linmath.h:815
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.
Definition linmath.h:267
BJ_INLINE void bj_vec2_add_scaled(bj_vec2 res, const bj_vec2 a, const bj_vec2 b, bj_real_t s)
Computes res = a + b * s for 2D vectors.
Definition linmath.h:136
BJ_INLINE void bj_mat4_add(bj_mat4 res, const bj_mat4 lhs, const bj_mat4 rhs)
Adds two 4x4 matrices.
Definition linmath.h:725
BJ_INLINE void bj_vec3_set(bj_vec3 res, bj_real_t a, bj_real_t b, bj_real_t c)
Directly set the scalar values of a bj_vec3 object.
Definition linmath.h:255
#define bj_real_t
Alias for float type.
Definition linmath.h:26
bj_real_t bj_quat[4]
Defines a quaternion type.
Definition linmath.h:87
BJ_INLINE bj_real_t bj_vec4_dot(const bj_vec4 a, const bj_vec4 b)
Computes the dot product of a abnd b
Definition linmath.h:530
#define bj_cosf
Wrapper for the standard cosf() function.
Definition math.h:41
BJ_INLINE void bj_mat4_transpose(bj_mat4 res, const bj_mat4 mat)
Transposes a 4x4 matrix.
Definition linmath.h:707
BJ_INLINE void bj_vec4_add_scaled(bj_vec4 res, const bj_vec4 a, const bj_vec4 b, bj_real_t s)
Computes res = a + b * s for 4D vectors.
Definition linmath.h:488
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.
Definition linmath.h:471
BJ_INLINE void bj_quat_identity(bj_quat q)
Sets a quaternion to the identity quaternion.
Definition linmath.h:1287
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.
Definition linmath.h:311
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.
Definition linmath.h:230
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.
Definition linmath.h:987
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.
Definition linmath.h:579
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.
Definition linmath.h:445
#define bj_tanf
Wrapper for the standard tanf() function.
Definition math.h:153
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.
Definition linmath.h:371
BJ_INLINE void bj_mat4_from_quat(bj_mat4 res, const bj_quat q)
Converts a quaternion to a 4x4 rotation matrix.
Definition linmath.h:1387
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.
Definition linmath.h:776
bj_vec4 bj_mat4[4]
Defines a 4x4 matrix type.
Definition linmath.h:76
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.
Definition linmath.h:1168
BJ_INLINE void bj_quat_mul(bj_quat res, const bj_quat p, const bj_quat q)
Multiplies two quaternions.
Definition linmath.h:1303
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.
Definition linmath.h:854
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.
Definition linmath.h:896
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.
Definition linmath.h:502
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.
Definition linmath.h:97
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.
Definition linmath.h:426
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.
Definition linmath.h:161
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.
Definition linmath.h:409
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.
Definition linmath.h:1345
BJ_INLINE void bj_mat4_row(bj_vec4 res, const bj_mat4 mat, int r)
Retrieves a specific row from a 4x4 matrix.
Definition linmath.h:675
BJ_INLINE bj_real_t bj_vec3_len(const bj_vec3 v)
Computes the length of the vec3.
Definition linmath.h:347
BJ_INLINE bj_real_t bj_vec3_dot(const bj_vec3 a, const bj_vec3 b)
Computes the dot product of a abnd b
Definition linmath.h:337
BJ_INLINE void bj_mat4_identity(bj_mat4 mat)
Initializes a 4x4 matrix to the identity matrix.
Definition linmath.h:642
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.
Definition linmath.h:121
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.
Definition linmath.h:109
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.
Definition linmath.h:324
BJ_INLINE void bj_vec3_copy(bj_vec3 res, const bj_vec3 src)
Copies the contents of one 3D vector to another.
Definition linmath.h:396
BJ_INLINE void bj_vec2_normalize(bj_vec2 res, const bj_vec2 v)
Normalizes the provided vec2.
Definition linmath.h:205
BJ_INLINE void bj_vec3_normalize(bj_vec3 res, const bj_vec3 v)
Normalizes the provided vec3.
Definition linmath.h:357
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.
Definition linmath.h:941
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.
Definition linmath.h:609
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.
Definition linmath.h:384
BJ_INLINE void bj_quat_conjugate(bj_quat res, const bj_quat q)
Computes the conjugate of a quaternion.
Definition linmath.h:1327
BJ_INLINE void bj_mat4_inverse(bj_mat4 res, const bj_mat4 mat)
Inverts a 4x4 matrix.
Definition linmath.h:1056
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.
Definition linmath.h:516
BJ_INLINE void bj_mat4_copy(bj_mat4 to, const bj_mat4 from)
Copies a 4x4 matrix from one to another.
Definition linmath.h:659
BJ_INLINE void bj_mat4_scale(bj_mat4 res, const bj_mat4 lhs, bj_real_t k)
Scales a 4x4 matrix by a scalar.
Definition linmath.h:757
BJ_INLINE void bj_vec3_add_scaled(bj_vec3 res, const bj_vec3 a, const bj_vec3 b, bj_real_t s)
Computes res = a + b * s for 3D vectors.
Definition linmath.h:297
BJ_INLINE void bj_vec4_normalize(bj_vec4 res, const bj_vec4 v)
Normalizes the provided vec4.
Definition linmath.h:550
BJ_INLINE void bj_vec4_copy(bj_vec4 res, const bj_vec4 src)
Copies the contents of one 4D vector to another.
Definition linmath.h:592
BJ_INLINE void bj_mat4_orthonormalize(bj_mat4 res, const bj_mat4 mat)
Orthonormalizes the rows of a 4x4 matrix.
Definition linmath.h:1105
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.
Definition linmath.h:835
bj_real_t bj_vec3[3]
Defines a 3D vector type.
Definition linmath.h:54
BJ_INLINE void bj_mat4_mul(bj_mat4 res, const bj_mat4 lhs, const bj_mat4 rhs)
Multiplies two 4x4 matrices.
Definition linmath.h:793
bj_real_t bj_vec2[2]
Defines a 2D vector type.
Definition linmath.h:43
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.
Definition linmath.h:1364