From 9d120e6428a5ed3291633d0f36f6dd44072e4f2a Mon Sep 17 00:00:00 2001 From: Shariq Shah Date: Tue, 23 Apr 2019 22:00:46 +1000 Subject: [PATCH] Moved Plane and its initialization into linmath --- src/common/linmath.c | 7 +++++++ src/common/linmath.h | 9 +++++++++ src/game/bounding_volumes.c | 2 +- src/game/bounding_volumes.h | 7 +------ src/game/editor.c | 11 ++++------- todo.txt | 3 ++- tools/clean_and_regen_project.bat | 5 +++++ 7 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 tools/clean_and_regen_project.bat diff --git a/src/common/linmath.c b/src/common/linmath.c index 93bdb1f..6ae68e7 100755 --- a/src/common/linmath.c +++ b/src/common/linmath.c @@ -824,3 +824,10 @@ void quat_mul_mat4(quat* res, quat* val, mat4* mat) res->z = v.z; res->w = v.w; } + +void plane_init(Plane* plane, vec3* normal, vec3* point) +{ + vec3_assign(&plane->normal, normal); + float dot = vec3_dot(&plane->normal, point); + plane->constant = -dot; +} diff --git a/src/common/linmath.h b/src/common/linmath.h index 2c79135..235ba84 100755 --- a/src/common/linmath.h +++ b/src/common/linmath.h @@ -51,6 +51,12 @@ typedef struct quat_t float w; } quat; +typedef struct plane_t +{ + vec3 normal; + float constant; +} Plane; + /* constants */ extern const vec3 UNIT_X; extern const vec3 UNIT_Y; @@ -134,4 +140,7 @@ void quat_identity(quat* res); void quat_fill(quat* res, float x, float y, float z, float w); void quat_mul_mat4(quat* res, quat* val, mat4* mat); +/* Plane */ +void plane_init(Plane* plane, vec3* normal, vec3* point); + #endif diff --git a/src/game/bounding_volumes.c b/src/game/bounding_volumes.c index 39dca51..d13edc5 100755 --- a/src/game/bounding_volumes.c +++ b/src/game/bounding_volumes.c @@ -144,7 +144,7 @@ bool bv_intersect_sphere_ray(struct Bounding_Sphere* sphere, vec3* sphere_abs_po //return true; } -float bv_distance_ray_plane(struct Ray* ray, struct Plane* plane) +float bv_distance_ray_plane(struct Ray* ray, Plane* plane) { float dot = vec3_dot(&plane->normal, &ray->direction); float abs_dot = fabsf(dot); diff --git a/src/game/bounding_volumes.h b/src/game/bounding_volumes.h index 8c129f2..16133af 100755 --- a/src/game/bounding_volumes.h +++ b/src/game/bounding_volumes.h @@ -42,11 +42,6 @@ struct Ray vec3 origin; }; -struct Plane -{ - vec3 normal; - float constant; -}; struct Raycast_Result { @@ -58,6 +53,6 @@ int bv_intersect_frustum_box(vec4* frustum, struct Bounding_Box* box, vec3* bo 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_sphere_ray(struct Bounding_Sphere* sphere, vec3* sphere_abs_position, struct Ray* ray); -float bv_distance_ray_plane(struct Ray* ray, struct Plane* plane); +float bv_distance_ray_plane(struct Ray* ray, Plane* plane); #endif diff --git a/src/game/editor.c b/src/game/editor.c index 160d9e7..c9952ed 100755 --- a/src/game/editor.c +++ b/src/game/editor.c @@ -109,7 +109,7 @@ void editor_init(struct Editor* editor) editor->current_mode = EDITOR_MODE_NORMAL; editor->current_axis = EDITOR_AXIS_XY; editor->grid_enabled = 1; - editor->grid_num_lines = 50; + editor->grid_num_lines = 100; editor->grid_scale = 1.f; editor->tool_mesh_draw_enabled = 0; editor->tool_snap_enabled = 1; @@ -420,7 +420,7 @@ void editor_on_mousebutton(const struct Event* event) void editor_on_mousemotion(const struct Event* event) { struct Game_State* game_state = game_state_get(); - struct Editor* editor = game_state->editor; + struct Editor* editor = game_state->editor; switch(editor->current_mode) { @@ -439,10 +439,8 @@ void editor_on_mousemotion(const struct Event* event) struct Ray cam_ray; cam_ray = camera_screen_coord_to_ray(editor_camera, event->mousemotion.x, event->mousemotion.y); - struct Plane ground_plane; - vec3_fill(&ground_plane.normal, 0.f, 1.f, 0.f); - float dot = vec3_dot(&ground_plane.normal, &position); - ground_plane.constant = -dot; + Plane ground_plane; + plane_init(&ground_plane, &(vec3){0.f, 1.f, 0.f}, &position); float distance = bv_distance_ray_plane(&cam_ray, &ground_plane); if(distance < INFINITY && distance > -INFINITY) @@ -460,7 +458,6 @@ void editor_on_mousemotion(const struct Event* event) vec3_assign(&editor->tool_mesh_position, &position); } } - log_message("%.3f, %.3f, %.3f", position.x, position.y, position.z); } } break; diff --git a/todo.txt b/todo.txt index 544276c..b3cd8ac 100644 --- a/todo.txt +++ b/todo.txt @@ -1,11 +1,11 @@ Todo: - - Move plane creation into its own function - Vertical translation in translate mode - Highlight if we are about to select an entity or perform the tool action like translate when mouse is hovered and an entity can be selected at that location - Display the projected position if we perform the action for example display what the new location would be right next to the tool mesh - Editor Undo - Scale Mode - Rotate Mode + - Use actual selected entity's mesh for tool mesh when the entity already has a mesh and use a placeholder like a sphere when there is not mesh - Add warning to genie build script when running on windows and WindowsSdkVersion cannot be found. This happens when the script is not run from vcvarsall command prompt - Improve README and add a screenshot to make the repository ready for making it public - Refactor all global application state into 'Application_Context' struct. A single global instance of which is available everywhere @@ -221,4 +221,5 @@ Done: * Editor modes for Transform, Rotate, Scale that operate similar to vim or blender. Modes can be toggled by hotkeys and the operation will be applied to the selected object. By default, we work on the ground axis i.e the xz plane and when we have alt pressed, we work in the vertical or y axis. + * Move plane creation into its own function diff --git a/tools/clean_and_regen_project.bat b/tools/clean_and_regen_project.bat new file mode 100644 index 0000000..62a4090 --- /dev/null +++ b/tools/clean_and_regen_project.bat @@ -0,0 +1,5 @@ +@echo off + +chdir /D W:\build\ +rmdir /S /Q W:\build\vs2017 +W:\tools\genie.exe vs2017