From 43fe537db17ed06b0eb8643ebc3b145ac961f030 Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Sat, 4 Jan 2020 22:26:59 +1100 Subject: [PATCH] Implemented saving/loaded bounding boxes for entities that are not static meshes --- README.md | 8 ++++---- assets/scenes/Level_1.symtres | 2 ++ src/common/version.h | 2 +- src/game/editor.c | 26 +++++--------------------- src/game/entity.c | 14 +++++++++++++- todo.txt | 9 +++++---- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index fe2919f..939e8a0 100755 --- a/README.md +++ b/README.md @@ -22,16 +22,16 @@ For more information visit the development blog at my website: [Link](http://sha Binary builds are available on the project's Itch.io page: [Link](https://bluerriq.itch.io/symmetry) ## Building -The game uses the [GENie](https://github.com/bkaradzic/GENie) build system. The game can be build by llowing steps: +The game uses the [GENie](https://github.com/bkaradzic/GENie) build system. The game can be build by the following steps: --**Windows**: Execute the following command in the project's root directory by opening a visual studio veloper command prompt: +-**Windows**: Execute the following command in the project's root directory by opening a visual studio developer command prompt: ```shell cd build - ..\tools\genie.exe vs2017 + ..\tools\genie.exe vs2019 ``` -This will generate a visual studio 2017 solution in the *build/vs2017* folder which can be opened in sual studio and built and run as ususal. +This will generate a visual studio 2019 solution in the *build/vs2019* folder which can be opened in sual studio and built and run as ususal. -**Linux(Ubuntu)**: Execute the following in the project's root directory diff --git a/assets/scenes/Level_1.symtres b/assets/scenes/Level_1.symtres index e4ebde5..433cc0f 100755 --- a/assets/scenes/Level_1.symtres +++ b/assets/scenes/Level_1.symtres @@ -19,7 +19,9 @@ Player rotation : 0.000 -0.760 0.000 0.651 active : true position : -68.875 1.832 -69.569 + bouding_box_min : -0.500 -0.500 -0.500 name : Player + bouding_box_max : 0.500 0.500 0.500 camera_clear_color : 0.298 0.600 0.898 1.000 } diff --git a/src/common/version.h b/src/common/version.h index c408b25..6a8a6b5 100755 --- a/src/common/version.h +++ b/src/common/version.h @@ -4,7 +4,7 @@ /* Auto generated version file. DO NOT MODIFY */ #define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MINOR 1 -#define SYMMETRY_VERSION_REVISION 299 +#define SYMMETRY_VERSION_REVISION 300 #define SYMMETRY_VERSION_BRANCH "dev" #endif \ No newline at end of file diff --git a/src/game/editor.c b/src/game/editor.c index 6a318eb..2b16c7e 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -31,6 +31,7 @@ #include "gui.h" #include "console.h" #include "debug_vars.h" +#include "../common/version.h" #include #include @@ -254,25 +255,6 @@ void editor_render(struct Editor* editor, struct Camera * active_camera) for(int i = 0; i <= 22; i += 2) im_line(vertices[i], vertices[i + 1], (vec3) { 0.f, 0.f, 0.f }, (quat) { 0.f, 0.f, 0.f, 1.f }, editor->cursor_entity_color, 3); - if(editor->selected_entity->type == ET_STATIC_MESH) - { - struct Static_Mesh* mesh = (struct Static_Mesh*)editor->selected_entity; - struct Geometry* geom = geom_get(mesh->model.geometry_index); - if(geom) - { - struct Bounding_Sphere* sphere = &geom->bounding_sphere; - vec3 abs_position = { 0.f, 0.f, 0.f }; - vec3 abs_scale = { 1.f, 1.f, 1.f }; - transform_get_absolute_position(editor->selected_entity, &abs_position); - transform_get_absolute_scale(editor->selected_entity, &abs_scale); - float max_scale = abs_scale.x; - if(abs_scale.y > max_scale) max_scale = abs_scale.y; - if(abs_scale.z > max_scale) max_scale = abs_scale.z; - //im_circle(sphere->radius * max_scale, 32, false, abs_position, (quat) { 0.f, 0.f, 0.f, 1.f }, editor->axis_color_x, 5); - im_circle(sphere->radius * max_scale, 32, false, abs_position, (quat) { 0.f, 0.f, 0.f, 1.f }, editor->axis_color_y, 5); - } - } - /* Draw selected entity with projected transformation applied */ if(editor->draw_cursor_entity) { @@ -619,9 +601,12 @@ void editor_update(struct Editor* editor, float dt) nk_layout_row_push(context, 0.1f); nk_labelf(context, NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE, "Grid Length: %d", editor->grid_num_lines); - nk_layout_row_push(context, 0.38f); + nk_layout_row_push(context, 0.34f); nk_spacing(context, 1); + nk_layout_row_push(context, 0.04f); + nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "v%d.%d.%d-%s", SYMMETRY_VERSION_MAJOR, SYMMETRY_VERSION_MINOR, SYMMETRY_VERSION_REVISION, SYMMETRY_VERSION_BRANCH); + nk_layout_row_push(context, 0.1f); static int frames = 0; static int fps = 0; @@ -635,7 +620,6 @@ void editor_update(struct Editor* editor, float dt) frames = 0; } nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps); - } nk_end(context); diff --git a/src/game/entity.c b/src/game/entity.c index e44760e..e45c434 100755 --- a/src/game/entity.c +++ b/src/game/entity.c @@ -172,6 +172,12 @@ bool entity_write(struct Entity* entity, struct Parser_Object* object, bool writ hashmap_vec3_set(entity_data, "scale", &entity->transform.scale); hashmap_quat_set(entity_data, "rotation", &entity->transform.rotation); + if(entity->type != ET_STATIC_MESH) + { + hashmap_vec3_set(entity_data, "bouding_box_min", &entity->bounding_box.min); + hashmap_vec3_set(entity_data, "bouding_box_max", &entity->bounding_box.max); + } + switch(entity->type) { case ET_CAMERA: @@ -499,7 +505,6 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e break; } - //If there's a parent entity then it means this is a child entity and we shoud load it's relative transform values vec3 position = { 0.f, 0.f, 0.f }; quat rotation = { 0.f, 0.f, 0.f, 1.f }; vec3 scale = { 1.f, 1.f, 1.f }; @@ -511,6 +516,13 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e transform_set_position(new_entity, &position); transform_scale(new_entity, &scale); quat_mul(&new_entity->transform.rotation, &new_entity->transform.rotation, &rotation); + + if(new_entity->type != ET_STATIC_MESH) + { + if(hashmap_value_exists(object->data, "bounding_box_min")) new_entity->bounding_box.min = hashmap_vec3_get(object->data, "bounding_box_min"); + if(hashmap_value_exists(object->data, "bounding_box_max")) new_entity->bounding_box.max = hashmap_vec3_get(object->data, "bounding_box_max"); + } + transform_update_transmat(new_entity); return new_entity; diff --git a/todo.txt b/todo.txt index 1641c86..ce51f28 100644 --- a/todo.txt +++ b/todo.txt @@ -1,7 +1,4 @@ Todo: - - Figure out the revision number and branching situation - - Add links to Itch.io builds of the game in readme and on the blog. Add link to blog in the readme as well - - Save/Load base bounding boxes for entity types other than static mesh - Determine whether we should enable or disble picking when a tool is active within an editor ? Only show bounding box for hovered entity instead of wireframe mesh - Fix crash where if an entity is hoverd in editor and deleted, the game crashes because the hovered variable in editor doesn't know that the entity was deleted @@ -401,4 +398,8 @@ Done: * Fixed rotation gizmo for scaled meshes * Implemented ray-bounding box picking and determine whether that is enough for our needs or do we need to implement OBB * Implemented base and derived bounding boxes for all entity types - * Imlpemented picking entities of all types in editor \ No newline at end of file + * Imlpemented picking entities of all types in editor + * Figure out the revision number and branching situation + * Add links to Itch.io builds of the game in readme and on the blog. Add link to blog in the readme as well + * Show version number in editor and console + * Save/Load base bounding boxes for entity types other than static mesh \ No newline at end of file