twn_camera: fix aspect of ortho projection

This commit is contained in:
veclavtalica
2025-03-07 11:07:05 +03:00
parent 67feb5974a
commit a03e1d885d
3 changed files with 11 additions and 14 deletions

View File

@ -436,26 +436,23 @@ void draw_camera(Vec3 position, Vec3 direction, Vec3 up, float fov, float zoom,
if (!orthographic && fov >= (float)(M_PI))
log_warn("Invalid fov given (%f)", (double)fov);
float const aspect = (float)ctx.base_render_width / (float)ctx.base_render_height;
Camera const camera = {
.fov = fov,
.pos = position,
.target = vec3_norm(direction),
.up = up,
.viewbox = {
(Vec2){ 1/-zoom, 1/zoom },
(Vec2){ 1/zoom, 1/-zoom }
aspect/-zoom, aspect/zoom,
1/zoom, 1/-zoom
},
.far_z = draw_distance
};
if (!orthographic)
camera_projection_matrix = camera_perspective(&camera);
else
camera_projection_matrix = camera_orthographic(&camera);
camera_far_z = draw_distance;
camera_projection_matrix = orthographic ? camera_orthographic(&camera) : camera_perspective(&camera);
camera_look_at_matrix = camera_look_at(&camera);
camera_far_z = draw_distance;
}