From f21c8ca19954b45050bb86c381cc7c439383342c Mon Sep 17 00:00:00 2001 From: 0scar Date: Mon, 12 Feb 2024 17:26:31 +0100 Subject: Add camera --- src/core/include/engine/core/platform.h | 3 +-- src/core/include/engine/engine.h | 1 - src/core/src/loop.c | 45 ++++++++------------------------- 3 files changed, 12 insertions(+), 37 deletions(-) (limited to 'src/core') diff --git a/src/core/include/engine/core/platform.h b/src/core/include/engine/core/platform.h index 9dc9a8b..76137c9 100644 --- a/src/core/include/engine/core/platform.h +++ b/src/core/include/engine/core/platform.h @@ -32,8 +32,7 @@ typedef struct Platform { bool mouse_lclick; bool mouse_rclick; - i32 camera_x; - i32 camera_y; + Camera *cam; /* Global resources that live from engine_init to engine_free */ Resources* resources; diff --git a/src/core/include/engine/engine.h b/src/core/include/engine/engine.h index d5b0922..75f6313 100644 --- a/src/core/include/engine/engine.h +++ b/src/core/include/engine/engine.h @@ -39,7 +39,6 @@ void render_set_zoom(f32 new_zoom); void render_adjust_zoom(f32 diff); void render_add_unit(RenderUnit* u); - /* Input handling */ void engine_input_ctx_push(i_ctx* ctx); void engine_input_ctx_pop(void); diff --git a/src/core/src/loop.c b/src/core/src/loop.c index f9c100c..c4435fb 100644 --- a/src/core/src/loop.c +++ b/src/core/src/loop.c @@ -36,6 +36,10 @@ Platform* GLOBAL_PLATFORM = NULL; +static Camera default_camera = { + .pos = {3, 0, 0}, +}; + input_callback_t* callbacks[128]; usize callbacks_len; @@ -235,9 +239,6 @@ Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight p->mouse_lclick = false; p->mouse_rclick = false; - p->camera_x = 0; - p->camera_y = 0; - p->edit_text = NULL; p->edit_pos = 0; @@ -245,6 +246,9 @@ Platform* engine_init(const char* windowtitle, i32 windowWidth, i32 windowHeight p->bindings_sz = 0; p->bindings_len = 0; + p->cam = &default_camera; + glm_ortho_default(45.f, p->cam->per); + { int x,y,n; test_image = stbi_load(img_filename, &x, &y, &n, 0); @@ -351,8 +355,7 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) { // // } // -// i_flush_bindings(callbacks_len, mem->data, callbacks); -// callbacks_len = 0; + i_flush_bindings(dt, callbacks_len, callbacks, mem->data); // // /* update */ StateType next_state; @@ -368,6 +371,9 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) { engine_input_ctx_reset(); + // Reset camera to default camera + p->cam = &default_camera; + state = next_state; update_func = State_updateFunc(state); { @@ -381,35 +387,6 @@ i32 engine_run(Platform* p, StateType initial_state, void* state_arg) { render_begin(p->window); - //gl->UseProgram(p->testobject->shaderprogram); - - //{ - // vec3 cam = {4., 3., 3.}; // perspective - // mat4 per; // perspective - // mat4 v; // view - // mat4 model = GLM_MAT4_IDENTITY_INIT; - // mat4 modelviewprojection; - - // f32 ratio = (float)p->window->windowsize.x / (float)p->window->windowsize.y; - // //glm_perspective(45.f , 600.f / 400.f, 0.1, 100.0f, per); - // glm_ortho(-10 * ratio, 10 * ratio, -10, 10, -10, 10, per); - - // glm_lookat(cam, GLM_VEC3_ZERO, GLM_YUP, v); - - // { mat4 t; - // //modelviewprojection = p * v * model - // glm_mat4_mul(v, model, t); - // glm_rotate_at(t, (vec3){0,0,0}, get_time() / 2.f, (vec3){0,1,0}); //, (vec3)({0,1,0})); - // glm_mat4_mul(per, t, modelviewprojection); - // } - - // // TODO: Do this only once during initialization - // u32 matrix = gl->GetUniformLocation(p->testobject->shaderprogram, "MVP"); - - // gl->UniformMatrix4fv(matrix, 1, GL_FALSE, &modelviewprojection[0][0]); - //} - - //gl->EnableVertexAttribArray(0); //gl->BindBuffer(GL_ARRAY_BUFFER, p->testobject->vbo); //gl->VertexAttribPointer( -- cgit v1.3