Implemented bounding box visualization in editor

dev
Shariq Shah 6 years ago
parent a9c6acf721
commit 5b69d7fc23
  1. 43
      src/game/bounding_volumes.c
  2. 2
      src/game/bounding_volumes.h
  3. 22
      src/game/editor.c
  4. 2
      todo.txt

@ -203,3 +203,46 @@ void bv_bounding_box_vertices_get(struct Bounding_Box* bounding_box, vec3 out_ve
vec3_fill(&out_vertices[6], bounding_box->max.x, bounding_box->min.y, bounding_box->max.z); vec3_fill(&out_vertices[6], bounding_box->max.x, bounding_box->min.y, bounding_box->max.z);
vec3_fill(&out_vertices[7], bounding_box->max.x, bounding_box->max.y, bounding_box->min.z); vec3_fill(&out_vertices[7], bounding_box->max.x, bounding_box->max.y, bounding_box->min.z);
} }
void bv_bounding_box_vertices_get_line_visualization(struct Bounding_Box* bounding_box, vec3 out_vertices[24])
{
// Back
vec3_fill(&out_vertices[0], bounding_box->min.x, bounding_box->min.y, bounding_box->min.z);
vec3_fill(&out_vertices[1], bounding_box->min.x, bounding_box->max.y, bounding_box->min.z);
vec3_fill(&out_vertices[2], bounding_box->min.x, bounding_box->min.y, bounding_box->min.z);
vec3_fill(&out_vertices[3], bounding_box->max.x, bounding_box->min.y, bounding_box->min.z);
vec3_fill(&out_vertices[4], bounding_box->min.x, bounding_box->max.y, bounding_box->min.z);
vec3_fill(&out_vertices[5], bounding_box->max.x, bounding_box->max.y, bounding_box->min.z);
vec3_fill(&out_vertices[6], bounding_box->max.x, bounding_box->max.y, bounding_box->min.z);
vec3_fill(&out_vertices[7], bounding_box->max.x, bounding_box->min.y, bounding_box->min.z);
// Front
vec3_fill(&out_vertices[8], bounding_box->min.x, bounding_box->min.y, bounding_box->max.z);
vec3_fill(&out_vertices[9], bounding_box->min.x, bounding_box->max.y, bounding_box->max.z);
vec3_fill(&out_vertices[10], bounding_box->min.x, bounding_box->min.y, bounding_box->max.z);
vec3_fill(&out_vertices[11], bounding_box->max.x, bounding_box->min.y, bounding_box->max.z);
vec3_fill(&out_vertices[12], bounding_box->min.x, bounding_box->max.y, bounding_box->max.z);
vec3_fill(&out_vertices[13], bounding_box->max.x, bounding_box->max.y, bounding_box->max.z);
vec3_fill(&out_vertices[14], bounding_box->max.x, bounding_box->max.y, bounding_box->max.z);
vec3_fill(&out_vertices[15], bounding_box->max.x, bounding_box->min.y, bounding_box->max.z);
// Left
vec3_fill(&out_vertices[16], bounding_box->min.x, bounding_box->max.y, bounding_box->min.z);
vec3_fill(&out_vertices[17], bounding_box->min.x, bounding_box->max.y, bounding_box->max.z);
vec3_fill(&out_vertices[18], bounding_box->min.x, bounding_box->min.y, bounding_box->min.z);
vec3_fill(&out_vertices[19], bounding_box->min.x, bounding_box->min.y, bounding_box->max.z);
// Right
vec3_fill(&out_vertices[20], bounding_box->max.x, bounding_box->min.y, bounding_box->min.z);
vec3_fill(&out_vertices[21], bounding_box->max.x, bounding_box->min.y, bounding_box->max.z);
vec3_fill(&out_vertices[22], bounding_box->max.x, bounding_box->max.y, bounding_box->min.z);
vec3_fill(&out_vertices[23], bounding_box->max.x, bounding_box->max.y, bounding_box->max.z);
}

@ -53,9 +53,9 @@ int bv_intersect_frustum_box(vec4* frustum, struct Bounding_Box* box, vec3* bo
int bv_intersect_frustum_box_(vec4* frustum, struct Bounding_Box* box); int bv_intersect_frustum_box_(vec4* frustum, struct Bounding_Box* box);
int bv_intersect_frustum_sphere(vec4* frustum, struct Bounding_Sphere* sphere, vec3* sphere_abs_pos, vec3* sphere_abs_scale); int bv_intersect_frustum_sphere(vec4* frustum, struct Bounding_Sphere* sphere, vec3* sphere_abs_pos, vec3* sphere_abs_scale);
bool bv_intersect_frustum_point(vec4* frustum, const vec3* point); bool bv_intersect_frustum_point(vec4* frustum, const vec3* point);
//bool bv_intersect_sphere_ray(struct Bounding_Sphere* sphere, vec3* sphere_abs_position, struct Ray* ray);
int bv_intersect_sphere_ray(struct Bounding_Sphere* sphere, vec3* sphere_abs_position, vec3* sphere_abs_scale, struct Ray* ray); int bv_intersect_sphere_ray(struct Bounding_Sphere* sphere, vec3* sphere_abs_position, vec3* sphere_abs_scale, struct Ray* ray);
float bv_distance_ray_plane(struct Ray* ray, Plane* plane); float bv_distance_ray_plane(struct Ray* ray, Plane* plane);
void bv_bounding_box_vertices_get(struct Bounding_Box* box, vec3 out_vertices[8]); void bv_bounding_box_vertices_get(struct Bounding_Box* box, vec3 out_vertices[8]);
void bv_bounding_box_vertices_get_line_visualization(struct Bounding_Box* bounding_box, vec3 out_vertices[24]);
#endif #endif

@ -249,24 +249,10 @@ void editor_render(struct Editor* editor, struct Camera * active_camera)
} }
/* Draw bounding box for selected entity */ /* Draw bounding box for selected entity */
vec3 points[8]; static vec3 vertices[24];
bv_bounding_box_vertices_get(&editor->selected_entity->transform.bounding_box, points); bv_bounding_box_vertices_get_line_visualization(&editor->selected_entity->transform.bounding_box, vertices);
for(int i = 0; i <= 22; i += 2)
//struct Geometry* geom = geom_get(((struct Static_Mesh*)editor->selected_entity)->model.geometry_index); 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, GDM_LINES);
//bv_bounding_box_vertices_get(&geom->bounding_box, points);
vec3 abs_position = { 0.f, 0.f, 0.f };
transform_get_absolute_position(editor->selected_entity, &abs_position);
vec3 scale = { 0.f, 0.f, 0.f };
scale.x = editor->selected_entity->transform.bounding_box.max.x - editor->selected_entity->transform.bounding_box.min.x;
scale.y = editor->selected_entity->transform.bounding_box.max.y - editor->selected_entity->transform.bounding_box.min.y;
scale.z = editor->selected_entity->transform.bounding_box.max.z - editor->selected_entity->transform.bounding_box.min.z;
vec3_scale(&scale, &scale, 0.5f);
//vec3_sub(&abs_position, &abs_position, &scale);
im_box(fabsf(scale.x), fabsf(scale.y), fabsf(scale.z), abs_position, (quat) { 0.f, 0.f, 0.f, 1.f }, editor->cursor_entity_color, GDM_TRIANGLES, 3);
im_begin((vec3) { 0.f, 0.f, 0.f }, (quat) { 0.f, 0.f, 0.f, 1.f }, (vec3) { 1.f, 1.f, 1.f }, (vec4) { 1.f, 0.f, 1.f, 1.2f }, GDM_LINE_LOOP, 3);
for(int i = 0; i < 8; i++)
im_pos(points[i].x, points[i].y, points[i].z);
im_end();
/* Draw selected entity with projected transformation applied */ /* Draw selected entity with projected transformation applied */
if(editor->draw_cursor_entity) if(editor->draw_cursor_entity)

@ -1,5 +1,4 @@
Todo: Todo:
- Implement bounding box visualization
- Fix rotation gizmo for scaled meshes - Fix rotation gizmo for scaled meshes
- Implement ray-bounding box picking and determine whether that is enough for our needs or do we need to implement OBB - Implement ray-bounding box picking and determine whether that is enough for our needs or do we need to implement OBB
- Command to create a placeholder entity of a particular type in a file - Command to create a placeholder entity of a particular type in a file
@ -401,3 +400,4 @@ Done:
* Implement resetting complete transform or just rotation, translation * Implement resetting complete transform or just rotation, translation
or scale for selected entity or scale for selected entity
* Save transformation information when saving entity archetypes * Save transformation information when saving entity archetypes
* Implement bounding box visualization
Loading…
Cancel
Save