21 #define K_PI 3.14159265358979323846f
24 #define K_2PI (2.0f * K_PI)
27 #define K_4PI (4.0f * K_PI)
30 #define K_HALF_PI (0.5f * K_PI)
33 #define K_QUARTER_PI (0.25f * K_PI)
36 #define K_ONE_OVER_PI (1.0f / K_PI)
39 #define K_ONE_OVER_TWO_PI (1.0f / K_2PI)
42 #define K_SQRT_TWO 1.41421356237309504880f
45 #define K_SQRT_THREE 1.73205080756887729352f
48 #define K_SQRT_ONE_OVER_TWO 0.70710678118654752440f
51 #define K_SQRT_ONE_OVER_THREE 0.57735026918962576450f
54 #define K_DEG2RAD_MULTIPLIER (K_PI / 180.0f)
57 #define K_RAD2DEG_MULTIPLIER (180.0f / K_PI)
60 #define K_SEC_TO_US_MULTIPLIER (1000.0f * 1000.0f)
63 #define K_SEC_TO_MS_MULTIPLIER 1000.0f
66 #define K_MS_TO_SEC_MULTIPLIER 0.001f
69 #define K_INFINITY (1e30f * 1e30f)
72 #define K_FLOAT_EPSILON 1.192092896e-07f
74 #define K_FLOAT_MIN -3.40282e+38F
76 #define K_FLOAT_MAX 3.40282e+38F
93 #define KSWAP(type, a, b) \
102 return x == 0.0f ? 0.0f : x < 0.0f ? -1.0f
108 return x < edge ? 0.0f : 1.0f;
206 return a + t * (b - a);
216 return (value != 0) && ((value & (value - 1)) == 0);
267 f32 t =
KCLAMP((x - edge_0) / (edge_1 - edge_0), 0.0f, 1.0f);
268 return t * t * (3.0 - 2.0 * t);
347 return (
vec2){vector_0.
x + vector_1.
x, vector_0.
y + vector_1.
y};
358 return (
vec2){vector_0.
x - vector_1.
x, vector_0.
y - vector_1.
y};
369 return (
vec2){vector_0.
x * vector_1.
x, vector_0.
y * vector_1.
y};
381 return (
vec2){vector_0.
x * scalar, vector_0.
y * scalar};
394 vector_0.
x * vector_1.
x + vector_2.
x,
395 vector_0.
y * vector_1.
y + vector_2.
y};
406 return (
vec2){vector_0.
x / vector_1.
x, vector_0.
y / vector_1.
y};
416 return vector.
x * vector.
x + vector.
y * vector.
y;
462 if (
kabs(vector_0.
x - vector_1.
x) > tolerance) {
466 if (
kabs(vector_0.
y - vector_1.
y) > tolerance) {
481 vec2 d = (
vec2){vector_0.
x - vector_1.
x, vector_0.
y - vector_1.
y};
494 vec2 d = (
vec2){vector_0.
x - vector_1.
x, vector_0.
y - vector_1.
y};
520 return (
vec3){vector.
x, vector.
y, vector.
z};
532 return (
vec3){vector.
x, vector.
y, z};
544 return (
vec4){vector.
x, vector.
y, vector.
z, w};
597 return (
vec3){vector_0.
x + vector_1.
x, vector_0.
y + vector_1.
y,
598 vector_0.
z + vector_1.
z};
609 return (
vec3){vector_0.
x - vector_1.
x, vector_0.
y - vector_1.
y,
610 vector_0.
z - vector_1.
z};
621 return (
vec3){vector_0.
x * vector_1.
x, vector_0.
y * vector_1.
y,
622 vector_0.
z * vector_1.
z};
634 return (
vec3){vector_0.
x * scalar, vector_0.
y * scalar, vector_0.
z * scalar};
647 vector_0.
x * vector_1.
x + vector_2.
x,
648 vector_0.
y * vector_1.
y + vector_2.
y,
649 vector_0.
z * vector_1.
z + vector_2.
z};
660 return (
vec3){vector_0.
x / vector_1.
x, vector_0.
y / vector_1.
y,
661 vector_0.
z / vector_1.
z};
666 for (
u64 i = 0; i < 3; ++i) {
679 return vector.
x * vector.
x + vector.
y * vector.
y + vector.
z * vector.
z;
725 p += vector_0.
x * vector_1.
x;
726 p += vector_0.
y * vector_1.
y;
727 p += vector_0.
z * vector_1.
z;
741 return (
vec3){vector_0.
y * vector_1.
z - vector_0.
z * vector_1.
y,
742 vector_0.
z * vector_1.
x - vector_0.
x * vector_1.
z,
743 vector_0.
x * vector_1.
y - vector_0.
y * vector_1.
x};
757 if (
kabs(vector_0.
x - vector_1.
x) > tolerance) {
761 if (
kabs(vector_0.
y - vector_1.
y) > tolerance) {
765 if (
kabs(vector_0.
z - vector_1.
z) > tolerance) {
780 vec3 d = (
vec3){vector_0.
x - vector_1.
x, vector_0.
y - vector_1.
y,
781 vector_0.
z - vector_1.
z};
794 vec3 d = (
vec3){vector_0.
x - vector_1.
x, vector_0.
y - vector_1.
y,
795 vector_0.
z - vector_1.
z};
808 if (length_sq == 0.0f) {
846 #if defined(KUSE_SIMD)
847 out_vector.data = _mm_setr_ps(x, y, z, w);
865 return (
vec3){vector.
x, vector.
y, vector.
z};
877 #if defined(KUSE_SIMD)
879 out_vector.data = _mm_setr_ps(x, y, z, w);
882 return (
vec4){vector.
x, vector.
y, vector.
z, w};
907 for (
u64 i = 0; i < 4; ++i) {
922 for (
u64 i = 0; i < 4; ++i) {
937 for (
u64 i = 0; i < 4; ++i) {
952 return (
vec4){vector_0.
x * scalar, vector_0.
y * scalar, vector_0.
z * scalar, vector_0.
w * scalar};
965 vector_0.
x * vector_1.
x + vector_2.
x,
966 vector_0.
y * vector_1.
y + vector_2.
y,
967 vector_0.
z * vector_1.
z + vector_2.
z,
968 vector_0.
w * vector_1.
w + vector_2.
w,
981 for (
u64 i = 0; i < 4; ++i) {
989 for (
u64 i = 0; i < 4; ++i) {
1002 return vector.
x * vector.
x + vector.
y * vector.
y + vector.
z * vector.
z +
1003 vector.
w * vector.
w;
1023 vector->
x /= length;
1024 vector->
y /= length;
1025 vector->
z /= length;
1026 vector->
w /= length;
1057 p = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
1072 if (
kabs(vector_0.
x - vector_1.
x) > tolerance) {
1076 if (
kabs(vector_0.
y - vector_1.
y) > tolerance) {
1080 if (
kabs(vector_0.
z - vector_1.
z) > tolerance) {
1084 if (
kabs(vector_0.
w - vector_1.
w) > tolerance) {
1100 for (
u8 i = 0; i < 4; ++i) {
1134 out_matrix.
data[0] = 1.0f;
1135 out_matrix.
data[5] = 1.0f;
1136 out_matrix.
data[10] = 1.0f;
1137 out_matrix.
data[15] = 1.0f;
1151 const f32* m1_ptr = matrix_0.
data;
1152 const f32* m2_ptr = matrix_1.
data;
1153 f32* dst_ptr = out_matrix.
data;
1155 for (
i32 i = 0; i < 4; ++i) {
1156 for (
i32 j = 0; j < 4; ++j) {
1157 *dst_ptr = m1_ptr[0] * m2_ptr[0 + j] + m1_ptr[1] * m2_ptr[4 + j] +
1158 m1_ptr[2] * m2_ptr[8 + j] + m1_ptr[3] * m2_ptr[12 + j];
1179 f32 near_clip,
f32 far_clip) {
1182 f32 lr = 1.0f / (left - right);
1183 f32 bt = 1.0f / (bottom - top);
1184 f32 nf = 1.0f / (near_clip - far_clip);
1186 out_matrix.
data[0] = -2.0f * lr;
1187 out_matrix.
data[5] = -2.0f * bt;
1188 out_matrix.
data[10] = nf;
1190 out_matrix.
data[12] = (left + right) * lr;
1191 out_matrix.
data[13] = (top + bottom) * bt;
1192 out_matrix.
data[14] = -near_clip * nf;
1208 f32 half_tan_fov =
ktan(fov_radians * 0.5f);
1211 out_matrix.
data[0] = 1.0f / (aspect_ratio * half_tan_fov);
1212 out_matrix.
data[5] = 1.0f / half_tan_fov;
1213 out_matrix.
data[10] = far_clip / (near_clip - far_clip);
1214 out_matrix.
data[11] = -1.0f;
1215 out_matrix.
data[14] = (far_clip * near_clip) / (near_clip - far_clip);
1234 out_matrix.
data[0] = x_axis.
x;
1235 out_matrix.
data[1] = y_axis.
x;
1236 out_matrix.
data[2] = -z_axis.
x;
1237 out_matrix.
data[3] = 0;
1238 out_matrix.
data[4] = x_axis.
y;
1239 out_matrix.
data[5] = y_axis.
y;
1240 out_matrix.
data[6] = -z_axis.
y;
1241 out_matrix.
data[7] = 0;
1242 out_matrix.
data[8] = x_axis.
z;
1243 out_matrix.
data[9] = y_axis.
z;
1244 out_matrix.
data[10] = -z_axis.
z;
1245 out_matrix.
data[11] = 0;
1249 out_matrix.
data[15] = 1.0f;
1261 out_matrix.
data[0] = matrix.
data[0];
1262 out_matrix.
data[1] = matrix.
data[4];
1263 out_matrix.
data[2] = matrix.
data[8];
1264 out_matrix.
data[3] = matrix.
data[12];
1265 out_matrix.
data[4] = matrix.
data[1];
1266 out_matrix.
data[5] = matrix.
data[5];
1267 out_matrix.
data[6] = matrix.
data[9];
1268 out_matrix.
data[7] = matrix.
data[13];
1269 out_matrix.
data[8] = matrix.
data[2];
1270 out_matrix.
data[9] = matrix.
data[6];
1271 out_matrix.
data[10] = matrix.
data[10];
1272 out_matrix.
data[11] = matrix.
data[14];
1273 out_matrix.
data[12] = matrix.
data[3];
1274 out_matrix.
data[13] = matrix.
data[7];
1275 out_matrix.
data[14] = matrix.
data[11];
1276 out_matrix.
data[15] = matrix.
data[15];
1289 f32 t0 = m[10] * m[15];
1290 f32 t1 = m[14] * m[11];
1291 f32 t2 = m[6] * m[15];
1292 f32 t3 = m[14] * m[7];
1293 f32 t4 = m[6] * m[11];
1294 f32 t5 = m[10] * m[7];
1295 f32 t6 = m[2] * m[15];
1296 f32 t7 = m[14] * m[3];
1297 f32 t8 = m[2] * m[11];
1298 f32 t9 = m[10] * m[3];
1299 f32 t10 = m[2] * m[7];
1300 f32 t11 = m[6] * m[3];
1305 o[0] = (t0 * m[5] + t3 * m[9] + t4 * m[13]) -
1306 (t1 * m[5] + t2 * m[9] + t5 * m[13]);
1307 o[1] = (t1 * m[1] + t6 * m[9] + t9 * m[13]) -
1308 (t0 * m[1] + t7 * m[9] + t8 * m[13]);
1309 o[2] = (t2 * m[1] + t7 * m[5] + t10 * m[13]) -
1310 (t3 * m[1] + t6 * m[5] + t11 * m[13]);
1311 o[3] = (t5 * m[1] + t8 * m[5] + t11 * m[9]) -
1312 (t4 * m[1] + t9 * m[5] + t10 * m[9]);
1314 f32 determinant = 1.0f / (m[0] * o[0] + m[4] * o[1] + m[8] * o[2] + m[12] * o[3]);
1327 f32 t0 = m[10] * m[15];
1328 f32 t1 = m[14] * m[11];
1329 f32 t2 = m[6] * m[15];
1330 f32 t3 = m[14] * m[7];
1331 f32 t4 = m[6] * m[11];
1332 f32 t5 = m[10] * m[7];
1333 f32 t6 = m[2] * m[15];
1334 f32 t7 = m[14] * m[3];
1335 f32 t8 = m[2] * m[11];
1336 f32 t9 = m[10] * m[3];
1337 f32 t10 = m[2] * m[7];
1338 f32 t11 = m[6] * m[3];
1339 f32 t12 = m[8] * m[13];
1340 f32 t13 = m[12] * m[9];
1341 f32 t14 = m[4] * m[13];
1342 f32 t15 = m[12] * m[5];
1343 f32 t16 = m[4] * m[9];
1344 f32 t17 = m[8] * m[5];
1345 f32 t18 = m[0] * m[13];
1346 f32 t19 = m[12] * m[1];
1347 f32 t20 = m[0] * m[9];
1348 f32 t21 = m[8] * m[1];
1349 f32 t22 = m[0] * m[5];
1350 f32 t23 = m[4] * m[1];
1355 o[0] = (t0 * m[5] + t3 * m[9] + t4 * m[13]) -
1356 (t1 * m[5] + t2 * m[9] + t5 * m[13]);
1357 o[1] = (t1 * m[1] + t6 * m[9] + t9 * m[13]) -
1358 (t0 * m[1] + t7 * m[9] + t8 * m[13]);
1359 o[2] = (t2 * m[1] + t7 * m[5] + t10 * m[13]) -
1360 (t3 * m[1] + t6 * m[5] + t11 * m[13]);
1361 o[3] = (t5 * m[1] + t8 * m[5] + t11 * m[9]) -
1362 (t4 * m[1] + t9 * m[5] + t10 * m[9]);
1364 f32 d = 1.0f / (m[0] * o[0] + m[4] * o[1] + m[8] * o[2] + m[12] * o[3]);
1367 if (
kabs(d) < 1e-6f) {
1376 o[4] = d * ((t1 * m[4] + t2 * m[8] + t5 * m[12]) -
1377 (t0 * m[4] + t3 * m[8] + t4 * m[12]));
1378 o[5] = d * ((t0 * m[0] + t7 * m[8] + t8 * m[12]) -
1379 (t1 * m[0] + t6 * m[8] + t9 * m[12]));
1380 o[6] = d * ((t3 * m[0] + t6 * m[4] + t11 * m[12]) -
1381 (t2 * m[0] + t7 * m[4] + t10 * m[12]));
1382 o[7] = d * ((t4 * m[0] + t9 * m[4] + t10 * m[8]) -
1383 (t5 * m[0] + t8 * m[4] + t11 * m[8]));
1384 o[8] = d * ((t12 * m[7] + t15 * m[11] + t16 * m[15]) -
1385 (t13 * m[7] + t14 * m[11] + t17 * m[15]));
1386 o[9] = d * ((t13 * m[3] + t18 * m[11] + t21 * m[15]) -
1387 (t12 * m[3] + t19 * m[11] + t20 * m[15]));
1388 o[10] = d * ((t14 * m[3] + t19 * m[7] + t22 * m[15]) -
1389 (t15 * m[3] + t18 * m[7] + t23 * m[15]));
1390 o[11] = d * ((t17 * m[3] + t20 * m[7] + t23 * m[11]) -
1391 (t16 * m[3] + t21 * m[7] + t22 * m[11]));
1392 o[12] = d * ((t14 * m[10] + t17 * m[14] + t13 * m[6]) -
1393 (t16 * m[14] + t12 * m[6] + t15 * m[10]));
1394 o[13] = d * ((t20 * m[14] + t12 * m[2] + t19 * m[10]) -
1395 (t18 * m[10] + t21 * m[14] + t13 * m[2]));
1396 o[14] = d * ((t18 * m[6] + t23 * m[14] + t15 * m[2]) -
1397 (t22 * m[14] + t14 * m[2] + t19 * m[6]));
1398 o[15] = d * ((t22 * m[10] + t16 * m[2] + t21 * m[6]) -
1399 (t20 * m[6] + t23 * m[10] + t17 * m[2]));
1412 out_matrix.
data[12] = position.
x;
1413 out_matrix.
data[13] = position.
y;
1414 out_matrix.
data[14] = position.
z;
1426 out_matrix.
data[0] = scale.
x;
1427 out_matrix.
data[5] = scale.
y;
1428 out_matrix.
data[10] = scale.
z;
1443 out_matrix.
data[0] = (1.0f - 2.0f * (r.
y * r.
y + r.
z * r.
z)) * s.
x;
1444 out_matrix.
data[1] = (r.
x * r.
y + r.
z * r.
w) * s.
x * 2.0f;
1445 out_matrix.
data[2] = (r.
x * r.
z - r.
y * r.
w) * s.
x * 2.0f;
1446 out_matrix.
data[3] = 0.0f;
1447 out_matrix.
data[4] = (r.
x * r.
y - r.
z * r.
w) * s.
y * 2.0f;
1448 out_matrix.
data[5] = (1.0f - 2.0f * (r.
x * r.
x + r.
z * r.
z)) * s.
y;
1449 out_matrix.
data[6] = (r.
y * r.
z + r.
x * r.
w) * s.
y * 2.0f;
1450 out_matrix.
data[7] = 0.0f;
1451 out_matrix.
data[8] = (r.
x * r.
z + r.
y * r.
w) * s.
z * 2.0f;
1452 out_matrix.
data[9] = (r.
y * r.
z - r.
x * r.
w) * s.
z * 2.0f;
1453 out_matrix.
data[10] = (1.0f - 2.0f * (r.
x * r.
x + r.
y * r.
y)) * s.
z;
1454 out_matrix.
data[11] = 0.0f;
1455 out_matrix.
data[12] = t.
x;
1456 out_matrix.
data[13] = t.
y;
1457 out_matrix.
data[14] = t.
z;
1458 out_matrix.
data[15] = 1.0f;
1474 out_matrix.
data[5] = c;
1475 out_matrix.
data[6] = s;
1476 out_matrix.
data[9] = -s;
1477 out_matrix.
data[10] = c;
1492 out_matrix.
data[0] = c;
1493 out_matrix.
data[2] = -s;
1494 out_matrix.
data[8] = s;
1495 out_matrix.
data[10] = c;
1511 out_matrix.
data[0] = c;
1512 out_matrix.
data[1] = s;
1513 out_matrix.
data[4] = -s;
1514 out_matrix.
data[5] = c;
1531 out_matrix =
mat4_mul(out_matrix, rz);
1543 forward.
x = -matrix.
data[8];
1544 forward.
y = -matrix.
data[9];
1545 forward.
z = -matrix.
data[10];
1558 backward.
x = matrix.
data[8];
1559 backward.
y = matrix.
data[9];
1560 backward.
z = matrix.
data[10];
1573 up.
x = matrix.
data[1];
1574 up.
y = matrix.
data[5];
1575 up.
z = matrix.
data[9];
1588 down.
x = -matrix.
data[1];
1589 down.
y = -matrix.
data[5];
1590 down.
z = -matrix.
data[9];
1603 left.
x = -matrix.
data[0];
1604 left.
y = -matrix.
data[1];
1605 left.
z = -matrix.
data[2];
1618 right.
x = matrix.
data[0];
1619 right.
y = matrix.
data[1];
1620 right.
z = matrix.
data[2];
1633 pos.
x = matrix.
data[12];
1634 pos.
y = matrix.
data[13];
1635 pos.
z = matrix.
data[14];
1715 return ksqrt(q.
x * q.
x + q.
y * q.
y + q.
z * q.
z + q.
w * q.
w);
1726 return (
quat){q.
x / normal, q.
y / normal, q.
z / normal, q.
w / normal};
1754 quat out_quaternion;
1757 q_0.
x * q_1.
w + q_0.
y * q_1.
z - q_0.
z * q_1.
y + q_0.
w * q_1.
x;
1760 -q_0.
x * q_1.
z + q_0.
y * q_1.
w + q_0.
z * q_1.
x + q_0.
w * q_1.
y;
1763 q_0.
x * q_1.
y - q_0.
y * q_1.
x + q_0.
z * q_1.
w + q_0.
w * q_1.
z;
1766 -q_0.
x * q_1.
x - q_0.
y * q_1.
y - q_0.
z * q_1.
z + q_0.
w * q_1.
w;
1768 return out_quaternion;
1779 return q_0.
x * q_1.
x + q_0.
y * q_1.
y + q_0.
z * q_1.
z + q_0.
w * q_1.
w;
1784 KMIN(vector_0.
x, vector_1.
y),
1785 KMIN(vector_0.
y, vector_1.
y),
1786 KMIN(vector_0.
z, vector_1.
z));
1791 KMAX(vector_0.
x, vector_1.
y),
1792 KMAX(vector_0.
y, vector_1.
y),
1793 KMAX(vector_0.
z, vector_1.
z));
1824 out_matrix.
data[0] = 1.0f - 2.0f * n.
y * n.
y - 2.0f * n.
z * n.
z;
1825 out_matrix.
data[1] = 2.0f * n.
x * n.
y - 2.0f * n.
z * n.
w;
1826 out_matrix.
data[2] = 2.0f * n.
x * n.
z + 2.0f * n.
y * n.
w;
1828 out_matrix.
data[4] = 2.0f * n.
x * n.
y + 2.0f * n.
z * n.
w;
1829 out_matrix.
data[5] = 1.0f - 2.0f * n.
x * n.
x - 2.0f * n.
z * n.
z;
1830 out_matrix.
data[6] = 2.0f * n.
y * n.
z - 2.0f * n.
x * n.
w;
1832 out_matrix.
data[8] = 2.0f * n.
x * n.
z - 2.0f * n.
y * n.
w;
1833 out_matrix.
data[9] = 2.0f * n.
y * n.
z + 2.0f * n.
x * n.
w;
1834 out_matrix.
data[10] = 1.0f - 2.0f * n.
x * n.
x - 2.0f * n.
y * n.
y;
1851 o[0] = (q.
x * q.
x) - (q.
y * q.
y) - (q.
z * q.
z) + (q.
w * q.
w);
1852 o[1] = 2.0f * ((q.
x * q.
y) + (q.
z * q.
w));
1853 o[2] = 2.0f * ((q.
x * q.
z) - (q.
y * q.
w));
1854 o[3] = center.
x - center.
x * o[0] - center.
y * o[1] - center.
z * o[2];
1856 o[4] = 2.0f * ((q.
x * q.
y) - (q.
z * q.
w));
1857 o[5] = -(q.
x * q.
x) + (q.
y * q.
y) - (q.
z * q.
z) + (q.
w * q.
w);
1858 o[6] = 2.0f * ((q.
y * q.
z) + (q.
x * q.
w));
1859 o[7] = center.
y - center.
x * o[4] - center.
y * o[5] - center.
z * o[6];
1861 o[8] = 2.0f * ((q.
x * q.
z) + (q.
y * q.
w));
1862 o[9] = 2.0f * ((q.
y * q.
z) - (q.
x * q.
w));
1863 o[10] = -(q.
x * q.
x) - (q.
y * q.
y) + (q.
z * q.
z) + (q.
w * q.
w);
1864 o[11] = center.
z - center.
x * o[8] - center.
y * o[9] - center.
z * o[10];
1882 const f32 half_angle = 0.5f * angle;
1886 quat q = (
quat){s * axis.
x, s * axis.
y, s * axis.
z, c};
1904 quat out_quaternion;
1926 const f32 DOT_THRESHOLD = 0.9995f;
1927 if (dot > DOT_THRESHOLD) {
1930 out_quaternion = (
quat){v0.
x + ((v1.
x - v0.
x) * percentage),
1931 v0.
y + ((v1.
y - v0.
y) * percentage),
1932 v0.
z + ((v1.
z - v0.
z) * percentage),
1933 v0.
w + ((v1.
w - v0.
w) * percentage)};
1940 f32 theta = theta_0 * percentage;
1942 f32 sin_theta_0 =
ksin(theta_0);
1946 dot * sin_theta / sin_theta_0;
1947 f32 s1 = sin_theta / sin_theta_0;
1949 return (
quat){(v0.
x * s0) + (v1.
x * s1), (v0.
y * s0) + (v1.
y * s1),
1950 (v0.
z * s0) + (v1.
z * s1), (v0.
w * s0) + (v1.
w * s1)};
1981 return (((value - old_min) * (new_max - new_min)) / (old_max - old_min)) +
1994 *out_u32 = (((r & 0x0FF) << 16) | ((g & 0x0FF) << 8) | (b & 0x0FF));
2006 *out_r = (rgbu >> 16) & 0x0FF;
2007 *out_g = (rgbu >> 8) & 0x0FF;
2008 *out_b = (rgbu) & 0x0FF;
2021 out_v->
r = r / 255.0f;
2022 out_v->
g = g / 255.0f;
2023 out_v->
b = b / 255.0f;
2139 const vec3* extents);
2142 return (point.
x >= rect.
x && point.
x <= rect.
x + rect.
width) && (point.
y >= rect.
y && point.
y <= rect.
y + rect.
height);
2149 (extents.
min.
x + extents.
max.
x) * 0.5f,
2150 (extents.
min.
y + extents.
max.
y) * 0.5f,
2163 (extents.
min.
x + extents.
max.
x) * 0.5f,
2164 (extents.
min.
y + extents.
max.
y) * 0.5f,
2165 (extents.
min.
z + extents.
max.
z) * 0.5f,
2179 (v_0.
x - v_1.
x) * 0.5f,
2180 (v_0.
y - v_1.
y) * 0.5f};
2185 (v_0.
x - v_1.
x) * 0.5f,
2186 (v_0.
y - v_1.
y) * 0.5f,
2187 (v_0.
z - v_1.
z) * 0.5f};
2211 if (dot > 0.9999f) {
2216 if (dot < -0.9999f) {
This file contains global type definitions which are used throughout the entire engine and applicatio...
#define KAPI
Import/export qualifier.
Definition: defines.h:205
unsigned int u32
Unsigned 32-bit integer.
Definition: defines.h:25
_Bool b8
8-bit boolean type
Definition: defines.h:58
float f32
32-bit floating point number
Definition: defines.h:47
#define KMIN(x, y)
Definition: defines.h:291
signed int i32
Signed 32-bit integer.
Definition: defines.h:39
#define KMAX(x, y)
Definition: defines.h:292
#define KINLINE
Inline qualifier.
Definition: defines.h:252
#define KCLAMP(value, min, max)
Clamps value to a range of min and max (inclusive).
Definition: defines.h:232
unsigned long long u64
Unsigned 64-bit integer.
Definition: defines.h:28
unsigned char u8
Unsigned 8-bit integer.
Definition: defines.h:19
KINLINE mat4 mat4_inverse(mat4 matrix)
Creates and returns an inverse of the provided matrix.
Definition: kmath.h:1324
KINLINE vec3 vec3_cross(vec3 vector_0, vec3 vector_1)
Calculates and returns the cross product of the supplied vectors. The cross product is a new vector w...
Definition: kmath.h:740
KINLINE quat quat_conjugate(quat q)
Returns the conjugate of the provided quaternion. That is, The x, y and z elements are negated,...
Definition: kmath.h:1736
KINLINE vec2 vec2_mul(vec2 vector_0, vec2 vector_1)
Multiplies vector_0 by vector_1 and returns a copy of the result.
Definition: kmath.h:368
KINLINE vec4 vec4_one(void)
Creates and returns a 4-component vector with all components set to 1.0f.
Definition: kmath.h:896
KINLINE mat4 mat4_mul(mat4 matrix_0, mat4 matrix_1)
Returns the result of multiplying matrix_0 and matrix_1.
Definition: kmath.h:1148
KINLINE vec3 vec3_sign(vec3 v)
Definition: kmath.h:1796
KINLINE mat4 mat4_from_translation_rotation_scale(vec3 t, quat r, vec3 s)
Returns a matrix created from the provided translation, rotation and scale (TRS).
Definition: kmath.h:1440
KAPI f32 klog2(f32 x)
Computes the base-2 logarithm of x (i.e. how many times x can be divided by 2).
KINLINE vec4 vec4_div(vec4 vector_0, vec4 vector_1)
Divides vector_0 by vector_1 and returns a copy of the result.
Definition: kmath.h:979
KAPI i32 krandom_in_range(i32 min, i32 max)
Returns a random integer that is within the given range (inclusive).
KAPI f32 kacos(f32 x)
Calculates the arc cosine of x.
KINLINE vec2 vec2_one(void)
Creates and returns a 2-component vector with all components set to 1.0f.
Definition: kmath.h:317
KINLINE mat4 mat4_translation(vec3 position)
Creates and returns a translation matrix from the given position.
Definition: kmath.h:1410
KINLINE vec2 vec2_up(void)
Creates and returns a 2-component vector pointing up (0, 1).
Definition: kmath.h:322
KINLINE void rgbu_to_u32(u32 r, u32 g, u32 b, u32 *out_u32)
Converts rgb int values [0-255] to a single 32-bit integer.
Definition: kmath.h:1993
KINLINE f32 vec2_distance_squared(vec2 vector_0, vec2 vector_1)
Returns the squared distance between vector_0 and vector_1. NOTE: If purely for comparison purposes,...
Definition: kmath.h:493
KINLINE vec3 extents_2d_center(extents_2d extents)
Definition: kmath.h:2147
KINLINE vec3 vec3_backward(void)
Creates and returns a 3-component vector pointing backward (0, 0, 1).
Definition: kmath.h:587
KINLINE vec4 vec3_to_vec4(vec3 vector, f32 w)
Returns a new vec4 using vector as the x, y and z components and w for w.
Definition: kmath.h:543
KAPI b8 plane_intersects_sphere(const plane_3d *p, const vec3 *center, f32 radius)
Indicates if plane p intersects a sphere constructed via center and radius.
KAPI f32 ktan(f32 x)
Calculates the tangent of x.
KINLINE mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, f32 far_clip)
Creates and returns a perspective matrix. Typically used to render 3d scenes.
Definition: kmath.h:1207
KINLINE vec4 vec4_mul_mat4(vec4 v, mat4 m)
Performs v * m.
Definition: kmath.h:1689
KINLINE vec3 vec3_max(vec3 vector_0, vec3 vector_1)
Definition: kmath.h:1789
KINLINE f32 klerp(f32 a, f32 b, f32 t)
Definition: kmath.h:205
KINLINE f32 vec2_distance(vec2 vector_0, vec2 vector_1)
Returns the distance between vector_0 and vector_1.
Definition: kmath.h:480
KINLINE vec3 vec3_lerp(vec3 v_0, vec3 v_1, f32 t)
Definition: kmath.h:2190
KINLINE mat4 mat4_identity(void)
Creates and returns an identity matrix:
Definition: kmath.h:1131
KINLINE mat4 mat4_look_at(vec3 position, vec3 target, vec3 up)
Creates and returns a look-at matrix, or a matrix looking at target from the perspective of position.
Definition: kmath.h:1228
KINLINE vec3 vec3_mid(vec3 v_0, vec3 v_1)
Definition: kmath.h:2183
KAPI f32 kfloor(f32 x)
Returns the largest integer value less than or equal to x.
KAPI f32 ksqrt(f32 x)
Calculates the square root of x.
KINLINE void kswapf(f32 *a, f32 *b)
Definition: kmath.h:87
KINLINE vec3 mat4_right(mat4 matrix)
Returns a right vector relative to the provided matrix.
Definition: kmath.h:1616
KINLINE f32 vec4_dot_f32(f32 a0, f32 a1, f32 a2, f32 a3, f32 b0, f32 b1, f32 b2, f32 b3)
Calculates the dot product using the elements of vec4s provided in split-out format.
Definition: kmath.h:1054
KAPI b8 frustum_intersects_aabb(const frustum *f, const vec3 *center, const vec3 *extents)
Indicates if frustum f intersects an axis-aligned bounding box constructed via center and extents.
KINLINE void vec4_normalize(vec4 *vector)
Normalizes the provided vector in place to a unit vector.
Definition: kmath.h:1021
KINLINE vec2 vec2_sub(vec2 vector_0, vec2 vector_1)
Subtracts vector_1 from vector_0 and returns a copy of the result.
Definition: kmath.h:357
KAPI f32 ksin(f32 x)
Calculates the sine of x.
KAPI f32 kabs(f32 x)
Calculates the absolute value of x.
KINLINE mat4 mat4_scale(vec3 scale)
Returns a scale matrix using the provided scale.
Definition: kmath.h:1424
KAPI b8 frustum_intersects_ksphere(const frustum *f, const ksphere *sphere)
Indicates if the frustum intersects (or contains) a sphere constructed via center and radius.
KINLINE vec3 vec3_forward(void)
Creates and returns a 3-component vector pointing forward (0, 0, -1).
Definition: kmath.h:582
KAPI f32 kfrandom_in_range(f32 min, f32 max)
Returns a random floating-point number that is within the given range (inclusive).
KINLINE f32 vec4_length_squared(vec4 vector)
Returns the squared length of the provided vector.
Definition: kmath.h:1001
KAPI f32 plane_signed_distance(const plane_3d *p, const vec3 *position)
Obtains the signed distance between the plane p and the provided postion.
KAPI b8 plane_intersects_aabb(const plane_3d *p, const vec3 *center, const vec3 *extents)
Indicates if plane p intersects an axis-aligned bounding box constructed via center and extents.
KINLINE vec3 triangle_get_normal(const triangle *tri)
Definition: kmath.h:2194
KINLINE vec3 mat4_backward(mat4 matrix)
Returns a backward vector relative to the provided matrix.
Definition: kmath.h:1556
KINLINE void vec2_normalize(vec2 *vector)
Normalizes the provided vector in place to a unit vector.
Definition: kmath.h:434
KINLINE vec3 vec3_mul(vec3 vector_0, vec3 vector_1)
Multiplies vector_0 by vector_1 and returns a copy of the result.
Definition: kmath.h:620
KINLINE vec2 vec2_right(void)
Creates and returns a 2-component vector pointing right (1, 0).
Definition: kmath.h:337
KINLINE vec2 vec2_mul_add(vec2 vector_0, vec2 vector_1, vec2 vector_2)
Multiplies vector_0 by vector_1, then adds the result to vector_2.
Definition: kmath.h:392
KINLINE mat4 mat4_orthographic(f32 left, f32 right, f32 bottom, f32 top, f32 near_clip, f32 far_clip)
Creates and returns an orthographic projection matrix. Typically used to render flat or 2D scenes.
Definition: kmath.h:1178
KINLINE quat quat_inverse(quat q)
Returns an inverse copy of the provided quaternion.
Definition: kmath.h:1744
KINLINE vec3 vec3_mul_add(vec3 vector_0, vec3 vector_1, vec3 vector_2)
Multiplies vector_0 by vector_1, then adds the result to vector_2.
Definition: kmath.h:645
KINLINE f32 vec3_length(vec3 vector)
Returns the length of the provided vector.
Definition: kmath.h:688
KINLINE vec3 vec3_sub(vec3 vector_0, vec3 vector_1)
Subtracts vector_1 from vector_0 and returns a copy of the result.
Definition: kmath.h:608
KINLINE vec2 vec2_mul_scalar(vec2 vector_0, f32 scalar)
Multiplies all elements of vector_0 by scalar and returns a copy of the result.
Definition: kmath.h:380
KAPI f32 katan(f32 x)
Calculates the arctangent of x.
KAPI f32 kattenuation_min_max(f32 min, f32 max, f32 x)
Returns the attenuation of x based off distance from the midpoint of min and max.
KINLINE vec3 mat4_mul_vec3(mat4 m, vec3 v)
Performs m * v.
Definition: kmath.h:1646
KINLINE void rgb_u32_to_vec3(u32 r, u32 g, u32 b, vec3 *out_v)
Converts rgb integer values [0-255] to a vec3 of floating-point values [0.0-1.0].
Definition: kmath.h:2020
KAPI f32 kfrandom(void)
Returns a random floating-point number.
KINLINE vec2 vec2_create(f32 x, f32 y)
Creates and returns a new 2-element vector using the supplied values.
Definition: kmath.h:300
KINLINE f32 ksmoothstep(f32 edge_0, f32 edge_1, f32 x)
Perform Hermite interpolation between two values.
Definition: kmath.h:266
#define K_RAD2DEG_MULTIPLIER
A multiplier used to convert radians to degrees.
Definition: kmath.h:57
KINLINE mat4 quat_to_rotation_matrix(quat q, vec3 center)
Calculates a rotation matrix based on the quaternion and the passed in center point.
Definition: kmath.h:1847
KINLINE vec2 vec2_down(void)
Creates and returns a 2-component vector pointing down (0, -1).
Definition: kmath.h:327
KINLINE b8 is_power_of_2(u64 value)
Indicates if the value is a power of 2. 0 is considered not a power of 2.
Definition: kmath.h:215
KAPI f32 vec3_distance_to_line(vec3 point, vec3 line_start, vec3 line_direction)
KINLINE vec3 mat4_left(mat4 matrix)
Returns a left vector relative to the provided matrix.
Definition: kmath.h:1601
KINLINE f32 deg_to_rad(f32 degrees)
Converts provided degrees to radians.
Definition: kmath.h:1959
KAPI f32 kpow(f32 x, f32 y)
KINLINE f32 vec3_length_squared(vec3 vector)
Returns the squared length of the provided vector.
Definition: kmath.h:678
KINLINE vec4 vec4_mul(vec4 vector_0, vec4 vector_1)
Multiplies vector_0 by vector_1 and returns a copy of the result.
Definition: kmath.h:935
KINLINE vec4 vec4_add(vec4 vector_0, vec4 vector_1)
Adds vector_1 to vector_0 and returns a copy of the result.
Definition: kmath.h:905
KAPI b8 frustum_intersects_sphere(const frustum *f, const vec3 *center, f32 radius)
Indicates if the frustum intersects (or contains) a sphere constructed via center and radius.
KINLINE vec4 vec4_mul_scalar(vec4 vector_0, f32 scalar)
Multiplies all elements of vector_0 by scalar and returns a copy of the result.
Definition: kmath.h:951
KINLINE quat quat_normalize(quat q)
Returns a normalized copy of the provided quaternion.
Definition: kmath.h:1724
KINLINE f32 vec2_length_squared(vec2 vector)
Returns the squared length of the provided vector.
Definition: kmath.h:415
KAPI i32 krandom(void)
Returns a random integer.
KINLINE mat4 mat4_euler_x(f32 angle_radians)
Creates a rotation matrix from the provided x angle.
Definition: kmath.h:1469
KAPI f32 kceil(f32 x)
Returns the smallest integer value greater than or equal to x.
KINLINE vec4 vec4_normalized(vec4 vector)
Returns a normalized copy of the supplied vector.
Definition: kmath.h:1035
KINLINE vec2 vec2_normalized(vec2 vector)
Returns a normalized copy of the supplied vector.
Definition: kmath.h:446
KINLINE vec3 vec3_from_vec4(vec4 vector)
Definition: kmath.h:519
KINLINE f32 quat_dot(quat q_0, quat q_1)
Calculates the dot product of the provided quaternions.
Definition: kmath.h:1778
KAPI f32 kcos(f32 x)
Calculates the cosine of x.
KINLINE vec3 vec3_create(f32 x, f32 y, f32 z)
Creates and returns a new 3-element vector using the supplied values.
Definition: kmath.h:510
KINLINE vec3 extents_3d_half(extents_3d extents)
Definition: kmath.h:2169
KAPI u64 krandom_u64(void)
Returns a random unsigned 64-bit integer.
KINLINE vec3 mat4_position(mat4 matrix)
Returns the position relative to the provided matrix.
Definition: kmath.h:1631
KINLINE quat quat_from_surface_normal(vec3 normal, vec3 reference_up)
Definition: kmath.h:2202
KINLINE vec4 vec4_from_vec3(vec3 vector, f32 w)
Returns a new vec4 using vector as the x, y and z components and w for w.
Definition: kmath.h:876
KINLINE void vec3_normalize(vec3 *vector)
Normalizes the provided vector in place to a unit vector.
Definition: kmath.h:697
KINLINE vec3 mat4_down(mat4 matrix)
Returns a downward vector relative to the provided matrix.
Definition: kmath.h:1586
KINLINE vec4 vec4_zero(void)
Creates and returns a 4-component vector with all components set to 0.0f.
Definition: kmath.h:890
KINLINE vec2 vec2_div(vec2 vector_0, vec2 vector_1)
Divides vector_0 by vector_1 and returns a copy of the result.
Definition: kmath.h:405
KINLINE f32 vec2_length(vec2 vector)
Returns the length of the provided vector.
Definition: kmath.h:425
KINLINE f32 quat_normal(quat q)
Returns the normal of the provided quaternion.
Definition: kmath.h:1714
KINLINE b8 rect_2d_contains_point(rect_2d rect, vec2 point)
Definition: kmath.h:2141
KINLINE void vec4_clamp(vec4 *vector, f32 min, f32 max)
Clamps the provided vector in-place to the given min/max values.
Definition: kmath.h:1098
KINLINE vec2 vec2_add(vec2 vector_0, vec2 vector_1)
Adds vector_1 to vector_0 and returns a copy of the result.
Definition: kmath.h:346
KINLINE mat4 mat4_euler_y(f32 angle_radians)
Creates a rotation matrix from the provided y angle.
Definition: kmath.h:1487
KINLINE vec3 vec3_min(vec3 vector_0, vec3 vector_1)
Definition: kmath.h:1782
KINLINE f32 mat4_determinant(mat4 matrix)
Calculates the determinant of the given matrix.
Definition: kmath.h:1286
KINLINE f32 vec3_distance_squared(vec3 vector_0, vec3 vector_1)
Returns the squared distance between vector_0 and vector_1. Less intensive than calling the non-squar...
Definition: kmath.h:793
KINLINE mat4 mat4_transposed(mat4 matrix)
Returns a transposed copy of the provided matrix (rows->colums)
Definition: kmath.h:1259
KAPI f32 katan2(f32 x, f32 y)
KINLINE quat quat_identity(void)
Creates an identity quaternion.
Definition: kmath.h:1706
#define K_FLOAT_EPSILON
Smallest positive number where 1.0 + FLOAT_EPSILON != 0.
Definition: kmath.h:72
KINLINE f32 rad_to_deg(f32 radians)
Converts provided radians to degrees.
Definition: kmath.h:1967
KINLINE quat quat_mul(quat q_0, quat q_1)
Multiplies the provided quaternions.
Definition: kmath.h:1753
KAPI f32 klog(f32 x)
Computes the logarithm of x.
KINLINE mat4 mat4_euler_z(f32 angle_radians)
Creates a rotation matrix from the provided z angle.
Definition: kmath.h:1505
KINLINE vec3 vec3_up(void)
Creates and returns a 3-component vector pointing up (0, 1, 0).
Definition: kmath.h:562
KINLINE vec3 vec3_mul_mat4(vec3 v, mat4 m)
Performs v * m.
Definition: kmath.h:1660
KINLINE vec4 vec4_create(f32 x, f32 y, f32 z, f32 w)
Creates and returns a new 4-element vector using the supplied values.
Definition: kmath.h:844
KINLINE vec4 vec4_div_scalar(vec4 vector_0, f32 scalar)
Definition: kmath.h:987
KINLINE vec3 vec3_down(void)
Creates and returns a 3-component vector pointing down (0, -1, 0).
Definition: kmath.h:567
KINLINE vec2 vec2_zero(void)
Creates and returns a 2-component vector with all components set to 0.0f.
Definition: kmath.h:311
KAPI frustum frustum_from_view_projection(mat4 view_projection)
KINLINE vec2 vec2_mid(vec2 v_0, vec2 v_1)
Definition: kmath.h:2177
KINLINE vec3 vec3_project(vec3 v_0, vec3 v_1)
Projects v_0 onto v_1.
Definition: kmath.h:806
KINLINE vec3 mat4_forward(mat4 matrix)
Returns a forward vector relative to the provided matrix.
Definition: kmath.h:1541
KINLINE f32 ksign(f32 x)
Returns 0.0f if x == 0.0f, -1.0f if negative, otherwise 1.0f.
Definition: kmath.h:101
KINLINE vec2 vec2_left(void)
Creates and returns a 2-component vector pointing left (-1, 0).
Definition: kmath.h:332
KINLINE vec3 extents_3d_center(extents_3d extents)
Definition: kmath.h:2161
KINLINE b8 vec2_compare(vec2 vector_0, vec2 vector_1, f32 tolerance)
Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.
Definition: kmath.h:461
KINLINE vec3 vec3_mul_scalar(vec3 vector_0, f32 scalar)
Multiplies all elements of vector_0 by scalar and returns a copy of the result.
Definition: kmath.h:633
KINLINE void vec3_to_rgb_u32(vec3 v, u32 *out_r, u32 *out_g, u32 *out_b)
Converts a vec3 of rgbvalues [0.0-1.0] to integer rgb values [0-255].
Definition: kmath.h:2034
KINLINE f32 kstep(f32 edge, f32 x)
Compares x to edge, returning 0 if x < edge; otherwise 1.0f;.
Definition: kmath.h:107
KINLINE f32 vec4_length(vec4 vector)
Returns the length of the provided vector.
Definition: kmath.h:1012
KINLINE mat4 mat4_euler_xyz(f32 x_radians, f32 y_radians, f32 z_radians)
Creates a rotation matrix from the provided x, y and z axis rotations.
Definition: kmath.h:1526
KINLINE vec3 vec3_left(void)
Creates and returns a 3-component vector pointing left (-1, 0, 0).
Definition: kmath.h:572
KINLINE mat4 quat_to_mat4(quat q)
Creates a rotation matrix from the given quaternion.
Definition: kmath.h:1817
KINLINE b8 kfloat_compare(f32 f_0, f32 f_1)
Compares the two floats and returns true if both are less than K_FLOAT_EPSILON apart; otherwise false...
Definition: kmath.h:285
KINLINE vec3 mat4_up(mat4 matrix)
Returns a upward vector relative to the provided matrix.
Definition: kmath.h:1571
KINLINE vec3 vec4_to_vec3(vec4 vector)
Returns a new vec3 containing the x, y and z components of the supplied vec4, essentially dropping th...
Definition: kmath.h:864
KINLINE vec3 vec3_div_scalar(vec3 vector_0, f32 scalar)
Definition: kmath.h:664
KINLINE vec4 vec4_mul_add(vec4 vector_0, vec4 vector_1, vec4 vector_2)
Multiplies vector_0 by vector_1, then adds the result to vector_2.
Definition: kmath.h:963
KINLINE vec3 vec3_from_vec2(vec2 vector, f32 z)
Definition: kmath.h:531
KINLINE vec4 vec4_sub(vec4 vector_0, vec4 vector_1)
Subtracts vector_1 from vector_0 and returns a copy of the result.
Definition: kmath.h:920
KINLINE vec3 vec3_rotate(vec3 v, quat q)
Definition: kmath.h:1800
KINLINE b8 vec3_compare(vec3 vector_0, vec3 vector_1, f32 tolerance)
Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.
Definition: kmath.h:756
KAPI plane_3d plane_3d_create(vec3 p1, vec3 norm)
KINLINE vec3 vec3_right(void)
Creates and returns a 3-component vector pointing right (1, 0, 0).
Definition: kmath.h:577
KAPI void frustum_corner_points_world_space(mat4 projection_view, vec4 *corners)
KINLINE quat quat_from_axis_angle(vec3 axis, f32 angle, b8 normalize)
Creates a quaternion from the given axis and angle.
Definition: kmath.h:1881
KINLINE vec3 extents_2d_half(extents_2d extents)
Definition: kmath.h:2154
KINLINE vec3 vec3_one(void)
Creates and returns a 3-component vector with all components set to 1.0f.
Definition: kmath.h:557
KINLINE vec4 mat4_mul_vec4(mat4 m, vec4 v)
Performs m * v.
Definition: kmath.h:1674
KINLINE b8 vec4_compare(vec4 vector_0, vec4 vector_1, f32 tolerance)
Compares all elements of vector_0 and vector_1 and ensures the difference is less than tolerance.
Definition: kmath.h:1071
KINLINE f32 vec3_dot(vec3 vector_0, vec3 vector_1)
Returns the dot product between the provided vectors. Typically used to calculate the difference in d...
Definition: kmath.h:723
KINLINE f32 vec3_distance(vec3 vector_0, vec3 vector_1)
Returns the distance between vector_0 and vector_1.
Definition: kmath.h:779
KINLINE void u32_to_rgb(u32 rgbu, u32 *out_r, u32 *out_g, u32 *out_b)
Converts the given 32-bit integer to rgb values [0-255].
Definition: kmath.h:2005
KAPI frustum frustum_create(const vec3 *position, const vec3 *target, const vec3 *up, f32 aspect, f32 fov, f32 near, f32 far)
Creates and returns a frustum based on the provided position, direction vectors, aspect,...
KINLINE vec3 vec3_transform(vec3 v, f32 w, mat4 m)
Transform v by m.
Definition: kmath.h:823
KINLINE vec3 vec3_div(vec3 vector_0, vec3 vector_1)
Divides vector_0 by vector_1 and returns a copy of the result.
Definition: kmath.h:659
KINLINE quat quat_slerp(quat q_0, quat q_1, f32 percentage)
Calculates spherical linear interpolation of a given percentage between two quaternions.
Definition: kmath.h:1903
KINLINE vec3 vec3_zero(void)
Creates and returns a 3-component vector with all components set to 0.0f.
Definition: kmath.h:551
KINLINE vec3 vec3_add(vec3 vector_0, vec3 vector_1)
Adds vector_1 to vector_0 and returns a copy of the result.
Definition: kmath.h:596
KINLINE f32 range_convert_f32(f32 value, f32 old_min, f32 old_max, f32 new_min, f32 new_max)
Converts value from the "old" range to the "new" range.
Definition: kmath.h:1979
#define K_DEG2RAD_MULTIPLIER
A multiplier used to convert degrees to radians.
Definition: kmath.h:54
KINLINE vec3 vec3_normalized(vec3 vector)
Returns a normalized copy of the supplied vector.
Definition: kmath.h:710
KINLINE vec4 vec4_clamped(vec4 vector, f32 min, f32 max)
Returns a clamped copy of the provided vector.
Definition: kmath.h:1114
This file contains the structures and functions of the memory system. This is responsible for memory ...
KAPI void * kzero_memory(void *block, u64 size)
Zeroes out the provided memory block.
Contains various math types required for the engine.
union vec2_u vec2
A 2-element vector.
union vec3_u vec3
A 3-element vector.
vec4 quat
A quaternion, used to represent rotational orientation.
Definition: math_types.h:135
Represents the extents of a 2d object.
Definition: math_types.h:203
vec2 max
The maximum extents of the object.
Definition: math_types.h:207
vec2 min
The minimum extents of the object.
Definition: math_types.h:205
Represents the extents of a 3d object.
Definition: math_types.h:213
vec3 min
The minimum extents of the object.
Definition: math_types.h:215
vec3 max
The maximum extents of the object.
Definition: math_types.h:217
Definition: math_types.h:272
Definition: math_types.h:395
Definition: math_types.h:256
Definition: math_types.h:391
vec3 verts[3]
Definition: math_types.h:392
A 3x3 matrix.
Definition: math_types.h:189
f32 data[12]
The matrix elements.
Definition: math_types.h:191
a 4x4 matrix, typically used to represent object transformations.
Definition: math_types.h:195
f32 data[16]
The matrix elements.
Definition: math_types.h:197
A 2-element vector.
Definition: math_types.h:19
f32 x
The first element.
Definition: math_types.h:25
f32 y
The second element.
Definition: math_types.h:35
A 3-element vector.
Definition: math_types.h:49
f32 elements[3]
An array of x, y, z.
Definition: math_types.h:51
f32 r
The first element.
Definition: math_types.h:57
f32 b
The third element.
Definition: math_types.h:77
f32 x
The first element.
Definition: math_types.h:55
f32 g
The second element.
Definition: math_types.h:67
f32 z
The third element.
Definition: math_types.h:75
f32 y
The second element.
Definition: math_types.h:65
A 4-element vector.
Definition: math_types.h:89
f32 elements[4]
An array of x, y, z, w.
Definition: math_types.h:91
f32 height
The fourth element.
Definition: math_types.h:128
f32 x
The first element.
Definition: math_types.h:96
f32 width
The third element.
Definition: math_types.h:118
f32 z
The third element.
Definition: math_types.h:112
f32 y
The second element.
Definition: math_types.h:104
f32 w
The fourth element.
Definition: math_types.h:122