Moved Plane and its initialization into linmath

dev
Shariq Shah 6 years ago
parent da1bf26b41
commit 9d120e6428
  1. 7
      src/common/linmath.c
  2. 9
      src/common/linmath.h
  3. 2
      src/game/bounding_volumes.c
  4. 7
      src/game/bounding_volumes.h
  5. 11
      src/game/editor.c
  6. 3
      todo.txt
  7. 5
      tools/clean_and_regen_project.bat

@ -824,3 +824,10 @@ void quat_mul_mat4(quat* res, quat* val, mat4* mat)
res->z = v.z; res->z = v.z;
res->w = v.w; 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;
}

@ -51,6 +51,12 @@ typedef struct quat_t
float w; float w;
} quat; } quat;
typedef struct plane_t
{
vec3 normal;
float constant;
} Plane;
/* constants */ /* constants */
extern const vec3 UNIT_X; extern const vec3 UNIT_X;
extern const vec3 UNIT_Y; 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_fill(quat* res, float x, float y, float z, float w);
void quat_mul_mat4(quat* res, quat* val, mat4* mat); void quat_mul_mat4(quat* res, quat* val, mat4* mat);
/* Plane */
void plane_init(Plane* plane, vec3* normal, vec3* point);
#endif #endif

@ -144,7 +144,7 @@ bool bv_intersect_sphere_ray(struct Bounding_Sphere* sphere, vec3* sphere_abs_po
//return true; //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 dot = vec3_dot(&plane->normal, &ray->direction);
float abs_dot = fabsf(dot); float abs_dot = fabsf(dot);

@ -42,11 +42,6 @@ struct Ray
vec3 origin; vec3 origin;
}; };
struct Plane
{
vec3 normal;
float constant;
};
struct Raycast_Result 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); 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); 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 #endif

@ -109,7 +109,7 @@ void editor_init(struct Editor* editor)
editor->current_mode = EDITOR_MODE_NORMAL; editor->current_mode = EDITOR_MODE_NORMAL;
editor->current_axis = EDITOR_AXIS_XY; editor->current_axis = EDITOR_AXIS_XY;
editor->grid_enabled = 1; editor->grid_enabled = 1;
editor->grid_num_lines = 50; editor->grid_num_lines = 100;
editor->grid_scale = 1.f; editor->grid_scale = 1.f;
editor->tool_mesh_draw_enabled = 0; editor->tool_mesh_draw_enabled = 0;
editor->tool_snap_enabled = 1; 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) void editor_on_mousemotion(const struct Event* event)
{ {
struct Game_State* game_state = game_state_get(); struct Game_State* game_state = game_state_get();
struct Editor* editor = game_state->editor; struct Editor* editor = game_state->editor;
switch(editor->current_mode) switch(editor->current_mode)
{ {
@ -439,10 +439,8 @@ void editor_on_mousemotion(const struct Event* event)
struct Ray cam_ray; struct Ray cam_ray;
cam_ray = camera_screen_coord_to_ray(editor_camera, event->mousemotion.x, event->mousemotion.y); cam_ray = camera_screen_coord_to_ray(editor_camera, event->mousemotion.x, event->mousemotion.y);
struct Plane ground_plane; Plane ground_plane;
vec3_fill(&ground_plane.normal, 0.f, 1.f, 0.f); plane_init(&ground_plane, &(vec3){0.f, 1.f, 0.f}, &position);
float dot = vec3_dot(&ground_plane.normal, &position);
ground_plane.constant = -dot;
float distance = bv_distance_ray_plane(&cam_ray, &ground_plane); float distance = bv_distance_ray_plane(&cam_ray, &ground_plane);
if(distance < INFINITY && distance > -INFINITY) if(distance < INFINITY && distance > -INFINITY)
@ -460,7 +458,6 @@ void editor_on_mousemotion(const struct Event* event)
vec3_assign(&editor->tool_mesh_position, &position); vec3_assign(&editor->tool_mesh_position, &position);
} }
} }
log_message("%.3f, %.3f, %.3f", position.x, position.y, position.z);
} }
} }
break; break;

@ -1,11 +1,11 @@
Todo: Todo:
- Move plane creation into its own function
- Vertical translation in translate mode - 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 - 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 - 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 - Editor Undo
- Scale Mode - Scale Mode
- Rotate 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 - 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 - 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 - 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. * 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. 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. 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

@ -0,0 +1,5 @@
@echo off
chdir /D W:\build\
rmdir /S /Q W:\build\vs2017
W:\tools\genie.exe vs2017
Loading…
Cancel
Save