twn_draw.c: draw_camera_2d()!

This commit is contained in:
veclavtalica
2025-02-05 00:54:38 +03:00
parent d9d7072c86
commit d9df3f9b04
6 changed files with 63 additions and 3 deletions

View File

@ -17,19 +17,30 @@
DeferredCommand *deferred_commands;
/* TODO: have a default initialized one */
/* TODO: with buffered render, don't we use camera of wrong frame right now ? */
Matrix4 camera_projection_matrix;
Matrix4 camera_look_at_matrix;
float camera_2d_rotation;
Vec2 camera_2d_position;
float camera_2d_zoom;
double depth_range_low, depth_range_high;
static void reset_camera_2d(void) {
camera_2d_position = (Vec2){0};
camera_2d_zoom = 1;
camera_2d_rotation = 0;
}
void render_clear(void) {
draw_camera((Vec3){0, 0, 0}, (Vec3){0, 0, 1}, (Vec3){0, 1, 0}, 1.57079632679f, 1);
reset_camera_2d();
text_cache_reset_arena(&ctx.text_cache);
/* since i don't intend to free the queues, */
/* it's faster and simpler to just "start over" */
/* and start overwriting the existing data */
@ -415,6 +426,22 @@ void render(void) {
}
/* TODO: check for NaNs and alike */
TWN_API void draw_camera_2d(Vec2 position,
float rotation,
float zoom)
{
if (zoom <= 0) {
log_warn("Invalid zoom value given to draw_camera_2d()");
zoom = 0.1f;
}
camera_2d_position = position;
camera_2d_rotation = rotation;
camera_2d_zoom = zoom;
}
/* TODO: check for NaNs and alike */
void draw_camera(Vec3 position, Vec3 direction, Vec3 up, float fov, float zoom) {
bool const orthographic = fabsf(0.0f - fov) < 0.00001f;
if (!orthographic && fov >= (float)(M_PI))
@ -441,6 +468,8 @@ void draw_camera(Vec3 position, Vec3 direction, Vec3 up, float fov, float zoom)
/* TODO: https://stackoverflow.com/questions/62493770/how-to-add-roll-in-camera-class */
/* TODO: check for NaNs and alike */
/* TODOL call draw_camera() instead, to reuse the code */
DrawCameraFromPrincipalAxesResult draw_camera_from_principal_axes(Vec3 position,
float roll,
float pitch,