summaryrefslogtreecommitdiff
path: root/src/maths/maths.h
diff options
context:
space:
mode:
authorOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-31 00:48:11 +1100
committerOmniscient <17525998+omnisci3nce@users.noreply.github.com>2024-03-31 00:48:11 +1100
commitc4bf1916fe219324e14384fc938e767daeab26c9 (patch)
tree84b33ea8feff5792f77a8e832b66c2a23f1104b5 /src/maths/maths.h
parentb638fd776253fa0cb841175e3e134df4587101b6 (diff)
working on cube (hardcoded)
Diffstat (limited to 'src/maths/maths.h')
-rw-r--r--src/maths/maths.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 41fbdfc..9206c5c 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -132,6 +132,24 @@ static inline mat4 mat4_mult(mat4 lhs, mat4 rhs) {
return out_matrix;
}
+#if defined(CEL_REND_BACKEND_VULKAN)
+/** @brief Creates a perspective projection matrix compatible with Vulkan */
+static inline mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip, f32 far_clip) {
+ // near_clip *= -1.0;
+ // far_clip *= -1.0;
+
+ f32 half_tan_fov = tanf(fov_radians * 0.5f);
+ mat4 out_matrix = { .data = { 0 } };
+
+ out_matrix.data[0] = 1.0f / (aspect_ratio * half_tan_fov);
+ out_matrix.data[5] = -1.0f / half_tan_fov; // Flip Y-axis for Vulkan
+ out_matrix.data[10] = -((far_clip + near_clip) / (far_clip - near_clip));
+ out_matrix.data[11] = -1.0f;
+ out_matrix.data[14] = -((2.0f * far_clip * near_clip) / (far_clip - near_clip));
+
+ return out_matrix;
+}
+#else
/** @brief Creates a perspective projection matrix */
static inline mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_clip,
f32 far_clip) {
@@ -144,6 +162,7 @@ static inline mat4 mat4_perspective(f32 fov_radians, f32 aspect_ratio, f32 near_
out_matrix.data[14] = -((2.0f * far_clip * near_clip) / (far_clip - near_clip));
return out_matrix;
}
+#endif
/** @brief Creates an orthographic projection matrix */
static inline mat4 mat4_orthographic(f32 left, f32 right, f32 bottom, f32 top, f32 near_clip,