twn_draw.c: draw_camera_2d()!
This commit is contained in:
@ -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,
|
||||
|
@ -17,6 +17,10 @@
|
||||
extern Matrix4 camera_projection_matrix;
|
||||
extern Matrix4 camera_look_at_matrix;
|
||||
|
||||
extern float camera_2d_rotation;
|
||||
extern Vec2 camera_2d_position;
|
||||
extern float camera_2d_zoom;
|
||||
|
||||
extern double depth_range_low, depth_range_high;
|
||||
|
||||
#define QUAD_ELEMENT_BUFFER_LENGTH (65536 / 6)
|
||||
|
@ -161,8 +161,15 @@ static void finally_use_2d_pipeline(void) {
|
||||
glOrtho(0, (double)ctx.base_render_width, (double)ctx.base_render_height, 0, 0, 1);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
/* TODO: 2d camera */
|
||||
glLoadIdentity();
|
||||
/* rotate against center of the viewport */
|
||||
Vec2 const center_offset = { ctx.game.resolution.x / 2, ctx.game.resolution.y / 2 };
|
||||
glTranslatef(center_offset.x, center_offset.y, 0);
|
||||
glRotatef(camera_2d_rotation, 0, 0, 1);
|
||||
glScalef(camera_2d_zoom, camera_2d_zoom, 1);
|
||||
glTranslatef(-center_offset.x, -center_offset.y, 0);
|
||||
/* apply the rest */
|
||||
glTranslatef(-camera_2d_position.x, -camera_2d_position.y, 0);
|
||||
|
||||
texture_mode_last_used = -1;
|
||||
pipeline_last_used = PIPELINE_2D;
|
||||
|
Reference in New Issue
Block a user