Fixed broken orthographic camera

dev
Shariq Shah 8 years ago
parent 50b4b33bf1
commit 9703f74b0e
  1. 3
      README.md
  2. 12
      src/libsymmetry/camera.c
  3. 19
      src/libsymmetry/editor.c
  4. 2
      src/libsymmetry/entity.c
  5. 1
      src/libsymmetry/entity.h
  6. 2
      src/libsymmetry/game.c

@ -155,7 +155,6 @@
- ## TODO - ## TODO
- Fix bugs with sprite batch renderer not working with projection matrix
- Implement necessary changes to run Soloud on linux - 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 - 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 - Add fallback shader
@ -340,3 +339,5 @@
* Fixed bugs with shader include file pre-processor * Fixed bugs with shader include file pre-processor
* Fixed bugs with editor's camera property viewer * Fixed bugs with editor's camera property viewer
* Fixed bugs related to changing camera projection * Fixed bugs related to changing camera projection
* Fixed bugs with sprite batch renderer not working with projection matrix
* Fixed broken orthographic camera

@ -47,6 +47,7 @@ void camera_create(struct Entity* entity, int width, int height)
camera->fov = 60.f; camera->fov = 60.f;
camera->ortho = false; camera->ortho = false;
camera->resizeable = true; camera->resizeable = true;
camera->zoom = 1.f;
float aspect_ratio = (float)width / (float)height; float aspect_ratio = (float)width / (float)height;
camera->aspect_ratio = aspect_ratio <= 0.f ? (4.f / 3.f) : aspect_ratio; camera->aspect_ratio = aspect_ratio <= 0.f ? (4.f / 3.f) : aspect_ratio;
mat4_identity(&camera->view_mat); mat4_identity(&camera->view_mat);
@ -86,7 +87,7 @@ void camera_update_proj(struct Entity* entity)
if(!camera->ortho) if(!camera->ortho)
{ {
mat4_perspective(&camera->proj_mat, mat4_perspective(&camera->proj_mat,
camera->fov, camera->fov / camera->zoom,
camera->aspect_ratio, camera->aspect_ratio,
camera->nearz, camera->nearz,
camera->farz); camera->farz);
@ -96,8 +97,13 @@ void camera_update_proj(struct Entity* entity)
int width, height; int width, height;
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
platform->window.get_size(game_state->window, &width, &height); platform->window.get_size(game_state->window, &width, &height);
mat4_ortho(&camera->proj_mat,
mat4_ortho(&camera->proj_mat, 0, width, height, 0, camera->nearz, camera->farz); -width / camera->zoom,
width / camera->zoom,
height / camera->zoom,
-height / camera->zoom,
camera->nearz,
camera->farz);
} }
camera_update_view_proj(entity); camera_update_view_proj(entity);
} }

@ -376,6 +376,15 @@ void editor_update(float dt)
bool update = false; bool update = false;
struct Camera* camera = &entity->camera; 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) if(!camera->ortho)
{ {
nk_layout_row_dynamic(context, row_height, 1); 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); nk_layout_row_dynamic(context, row_height, 1);
editor_widget_color_combov4(context, &camera->clear_color, 200, 300); 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); 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); float new_near_z = nk_propertyf(context, "NearZ", -FLT_MAX, camera->nearz, camera->farz, 0.1f, 1.f);
if(new_near_z != camera->nearz) if(new_near_z != camera->nearz)
@ -412,7 +429,7 @@ void editor_update(float dt)
if(update) if(update)
{ {
if(!camera->ortho) camera_update_view(entity); camera_update_view(entity);
camera_update_proj(entity); camera_update_proj(entity);
} }

@ -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, "ortho", camera->ortho);
hashmap_bool_set(entity_data, "resizeable", camera->resizeable); hashmap_bool_set(entity_data, "resizeable", camera->resizeable);
hashmap_float_set(entity_data, "fov", camera->fov); 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, "nearz", camera->nearz);
hashmap_float_set(entity_data, "farz", camera->farz); hashmap_float_set(entity_data, "farz", camera->farz);
hashmap_vec4_set(entity_data, "clear_color", &camera->clear_color); 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, "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, "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, "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, "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"); if(hashmap_value_exists(object->data, "ortho")) entity->camera.ortho = hashmap_bool_get(object->data, "ortho");

@ -74,6 +74,7 @@ struct Camera
float aspect_ratio; float aspect_ratio;
float nearz; float nearz;
float farz; float farz;
float zoom;
bool ortho; bool ortho;
int fbo; int fbo;
int render_tex; int render_tex;

@ -220,7 +220,7 @@ void scene_setup(void)
/*struct Camera* camera = &player->camera; /*struct Camera* camera = &player->camera;
camera->ortho = true; camera->ortho = true;
camera->farz = 500.f; camera->farz = 500.f;
camera->nearz = 1.f; camera->nearz = -500.f;
camera_update_proj(player);*/ camera_update_proj(player);*/
/*struct Entity* suz = entity_find("Suzanne"); /*struct Entity* suz = entity_find("Suzanne");

Loading…
Cancel
Save