feat: add viewport and test

This commit is contained in:
2025-08-28 21:36:55 +02:00
parent 471b21b952
commit d94ccfbbaa
3 changed files with 49 additions and 7 deletions

View File

@@ -1,8 +1,38 @@
#include <stdio.h>
#include "math/mat4.h"
#include "cam.h"
#include "math/vec4.h"
Vec4f_t mat4f_mul_vec4f(const Mat4f_t mat, Vec4f_t v)
{
Vec4f_t out;
for (int i = 0; i < 4; i++)
{
out.data[i] = 0.f;
for (int j = 0; j < 4; j++)
out.data[i] += mat.m[i*4 + j] * v.data[j];
}
return out;
}
int main(int argc, const char** argv)
{
printf("hello world");
const float fov = 60;
const float width = 1000, height = 800;
const float near = 0.1, far = 1000;
const float aspect = width / height;
// xyz = [-1, 1]
Vec4f_t vec = vec4f(0.f, 0.f, -1.f, 1.f);
Mat4f_t proj = perspCam(fov, aspect, near, far);
Vec4f_t v_clip = mat4f_mul_vec4f(proj, vec);
normCoord_r(&v_clip);
viewport_r(&v_clip, width, height);
printf("Screen coordinates: x = %f, y = %f, z = %f\n",
v_clip.x, v_clip.y, v_clip.z);
return 0;
}