Implemented saving/loaded bounding boxes for entities that are not static meshes

dev
Shariq Shah 6 years ago
parent c3d2e2c4c1
commit 43fe537db1
  1. 8
      README.md
  2. 2
      assets/scenes/Level_1.symtres
  3. 2
      src/common/version.h
  4. 26
      src/game/editor.c
  5. 14
      src/game/entity.c
  6. 9
      todo.txt

@ -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) Binary builds are available on the project's Itch.io page: [Link](https://bluerriq.itch.io/symmetry)
## Building ## 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 ```shell
cd build 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 -**Linux(Ubuntu)**: Execute the following in the project's root directory

@ -19,7 +19,9 @@ Player
rotation : 0.000 -0.760 0.000 0.651 rotation : 0.000 -0.760 0.000 0.651
active : true active : true
position : -68.875 1.832 -69.569 position : -68.875 1.832 -69.569
bouding_box_min : -0.500 -0.500 -0.500
name : Player name : Player
bouding_box_max : 0.500 0.500 0.500
camera_clear_color : 0.298 0.600 0.898 1.000 camera_clear_color : 0.298 0.600 0.898 1.000
} }

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */ /* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0 #define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1 #define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 299 #define SYMMETRY_VERSION_REVISION 300
#define SYMMETRY_VERSION_BRANCH "dev" #define SYMMETRY_VERSION_BRANCH "dev"
#endif #endif

@ -31,6 +31,7 @@
#include "gui.h" #include "gui.h"
#include "console.h" #include "console.h"
#include "debug_vars.h" #include "debug_vars.h"
#include "../common/version.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -254,25 +255,6 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
for(int i = 0; i <= 22; i += 2) 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); 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 */ /* Draw selected entity with projected transformation applied */
if(editor->draw_cursor_entity) 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_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_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_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); nk_layout_row_push(context, 0.1f);
static int frames = 0; static int frames = 0;
static int fps = 0; static int fps = 0;
@ -635,7 +620,6 @@ void editor_update(struct Editor* editor, float dt)
frames = 0; frames = 0;
} }
nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps); nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps);
} }
nk_end(context); nk_end(context);

@ -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_vec3_set(entity_data, "scale", &entity->transform.scale);
hashmap_quat_set(entity_data, "rotation", &entity->transform.rotation); 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) switch(entity->type)
{ {
case ET_CAMERA: case ET_CAMERA:
@ -499,7 +505,6 @@ struct Entity* entity_read(struct Parser_Object* object, struct Entity* parent_e
break; 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 }; vec3 position = { 0.f, 0.f, 0.f };
quat rotation = { 0.f, 0.f, 0.f, 1.f }; quat rotation = { 0.f, 0.f, 0.f, 1.f };
vec3 scale = { 1.f, 1.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_set_position(new_entity, &position);
transform_scale(new_entity, &scale); transform_scale(new_entity, &scale);
quat_mul(&new_entity->transform.rotation, &new_entity->transform.rotation, &rotation); 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); transform_update_transmat(new_entity);
return new_entity; return new_entity;

@ -1,7 +1,4 @@
Todo: 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 - 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 ? 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 - 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 * 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 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 * Implemented base and derived bounding boxes for all entity types
* Imlpemented picking entities of all types in editor * 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
Loading…
Cancel
Save