diff --git a/README.md b/README.md index 778c7fb..60cf0b0 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,6 @@ - ## TODO - - Fix bugs with sprite batch renderer not working with projection matrix - Implement necessary changes to run Soloud on linux - Get rid of pkg-confg and system-installed SDL2 dependancy on linux and instead put custom compiled SDL libs in third_party similar to how we're handling it in windows - Add fallback shader @@ -340,3 +339,5 @@ * Fixed bugs with shader include file pre-processor * Fixed bugs with editor's camera property viewer * Fixed bugs related to changing camera projection + * Fixed bugs with sprite batch renderer not working with projection matrix + * Fixed broken orthographic camera \ No newline at end of file diff --git a/src/libsymmetry/camera.c b/src/libsymmetry/camera.c index 3bc889f..7a4bf87 100644 --- a/src/libsymmetry/camera.c +++ b/src/libsymmetry/camera.c @@ -47,6 +47,7 @@ void camera_create(struct Entity* entity, int width, int height) camera->fov = 60.f; camera->ortho = false; camera->resizeable = true; + camera->zoom = 1.f; float aspect_ratio = (float)width / (float)height; camera->aspect_ratio = aspect_ratio <= 0.f ? (4.f / 3.f) : aspect_ratio; mat4_identity(&camera->view_mat); @@ -86,7 +87,7 @@ void camera_update_proj(struct Entity* entity) if(!camera->ortho) { mat4_perspective(&camera->proj_mat, - camera->fov, + camera->fov / camera->zoom, camera->aspect_ratio, camera->nearz, camera->farz); @@ -96,8 +97,13 @@ void camera_update_proj(struct Entity* entity) int width, height; struct Game_State* game_state = game_state_get(); platform->window.get_size(game_state->window, &width, &height); - - mat4_ortho(&camera->proj_mat, 0, width, height, 0, camera->nearz, camera->farz); + mat4_ortho(&camera->proj_mat, + -width / camera->zoom, + width / camera->zoom, + height / camera->zoom, + -height / camera->zoom, + camera->nearz, + camera->farz); } camera_update_view_proj(entity); } diff --git a/src/libsymmetry/editor.c b/src/libsymmetry/editor.c index 9c10dff..a3d2a6d 100644 --- a/src/libsymmetry/editor.c +++ b/src/libsymmetry/editor.c @@ -376,6 +376,15 @@ void editor_update(float dt) bool update = false; struct Camera* camera = &entity->camera; + nk_layout_row_dynamic(context, row_height, 2); + nk_label(context, "Orthographic", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE); + bool ortho = nk_checkbox_label(context, "", &camera->ortho); + if(ortho != camera->ortho) + { + update = true; + } + + if(!camera->ortho) { nk_layout_row_dynamic(context, row_height, 1); @@ -394,6 +403,14 @@ void editor_update(float dt) nk_layout_row_dynamic(context, row_height, 1); editor_widget_color_combov4(context, &camera->clear_color, 200, 300); + nk_layout_row_dynamic(context, row_height, 1); + float new_zoom = nk_propertyf(context, "Zoom", 1.f, camera->zoom, FLT_MAX, 0.1f, 1.f); + if(new_zoom != camera->zoom) + { + camera->zoom = new_zoom; + update = true; + } + nk_layout_row_dynamic(context, row_height, 1); float new_near_z = nk_propertyf(context, "NearZ", -FLT_MAX, camera->nearz, camera->farz, 0.1f, 1.f); if(new_near_z != camera->nearz) @@ -412,7 +429,7 @@ void editor_update(float dt) if(update) { - if(!camera->ortho) camera_update_view(entity); + camera_update_view(entity); camera_update_proj(entity); } diff --git a/src/libsymmetry/entity.c b/src/libsymmetry/entity.c index 4c67855..0e676da 100644 --- a/src/libsymmetry/entity.c +++ b/src/libsymmetry/entity.c @@ -226,6 +226,7 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object) hashmap_bool_set(entity_data, "ortho", camera->ortho); hashmap_bool_set(entity_data, "resizeable", camera->resizeable); hashmap_float_set(entity_data, "fov", camera->fov); + hashmap_float_set(entity_data, "zoom", camera->zoom); hashmap_float_set(entity_data, "nearz", camera->nearz); hashmap_float_set(entity_data, "farz", camera->farz); hashmap_vec4_set(entity_data, "clear_color", &camera->clear_color); @@ -395,6 +396,7 @@ struct Entity* entity_read(struct Parser_Object* object) if(hashmap_value_exists(object->data, "fov")) entity->camera.fov = hashmap_float_get(object->data, "fov"); if(hashmap_value_exists(object->data, "resizeable")) entity->camera.resizeable = hashmap_bool_get(object->data, "resizeable"); + if(hashmap_value_exists(object->data, "zoom")) entity->camera.zoom = hashmap_float_get(object->data, "zoom"); if(hashmap_value_exists(object->data, "nearz")) entity->camera.nearz = hashmap_float_get(object->data, "nearz"); if(hashmap_value_exists(object->data, "farz")) entity->camera.farz = hashmap_float_get(object->data, "farz"); if(hashmap_value_exists(object->data, "ortho")) entity->camera.ortho = hashmap_bool_get(object->data, "ortho"); diff --git a/src/libsymmetry/entity.h b/src/libsymmetry/entity.h index 3116c77..5a35df1 100644 --- a/src/libsymmetry/entity.h +++ b/src/libsymmetry/entity.h @@ -74,6 +74,7 @@ struct Camera float aspect_ratio; float nearz; float farz; + float zoom; bool ortho; int fbo; int render_tex; diff --git a/src/libsymmetry/game.c b/src/libsymmetry/game.c index 2a1582c..aa7ceea 100644 --- a/src/libsymmetry/game.c +++ b/src/libsymmetry/game.c @@ -220,7 +220,7 @@ void scene_setup(void) /*struct Camera* camera = &player->camera; camera->ortho = true; camera->farz = 500.f; - camera->nearz = 1.f; + camera->nearz = -500.f; camera_update_proj(player);*/ /*struct Entity* suz = entity_find("Suzanne");