Create orthographic projection function

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-05 13:51:13 +01:00
1 parent 6e37b45f28
commit a73975a766
3 files changed
+14 -1

No files matched your search

+10
View File
@@ -100,6 +100,16 @@ mat4_t mat4_perspective(float aspect, float fov, float near, float far)
};
}
mat4_t mat4_orthographic(float width, float height, float near, float far)
{
return (mat4_t) {
{ 1 / width, 0, 0, 0 },
{ 0, -1 / height, 0, 0 },
{ 0, 0, 1 / (far - near), 0 },
{ 0, 0, -near / (far - near), 1 },
};
}
mat4_t mat4_translate_vec3(vec3_t v)
{
return (mat4_t) {
+1
View File
@@ -86,6 +86,7 @@ float vec4_dot(vec4_t v, vec4_t u);
mat4_t mat4_mul(mat4_t m, mat4_t n);
mat4_t mat4_lookat(vec3_t camera, vec3_t target, vec3_t up);
mat4_t mat4_perspective(float aspect, float fov, float near, float far);
mat4_t mat4_orthographic(float width, float height, float near, float far);
mat4_t mat4_translate_vec3(vec3_t v);
mat4_t mat4_scale_vec3(vec3_t v);
mat4_t mat4_rotate_quaternion(vec4_t q);
+3 -1
View File
@@ -64,7 +64,9 @@ int main(int argc, char *argv[])
const mat4_t view = mat4_lookat(cam, tgt, up);
const mat4_t proj = mat4_perspective((float)W / H, PI / 8, 0.1, 100.0);
const mat4_t vp = mat4_mul(proj, view);
const mat4_t light_vp = mat4_lookat(light, tgt, up);
const mat4_t light_view = mat4_lookat(light, tgt, up);
const mat4_t light_proj = mat4_orthographic(5, 5, 10);
const mat4_t light_vp = mat4_mul(light_proj, light_view);
mat4_t transforms[NELEMS(gpu_models)] = {
mat4_mul(
MAT4_TRANSLATE(1, 0, 0),