diff --git a/src/editor/level_editor.jai b/src/editor/level_editor.jai index 58b67c2..64c44f4 100644 --- a/src/editor/level_editor.jai +++ b/src/editor/level_editor.jai @@ -34,6 +34,11 @@ pointerY : s32; world : World; +show_trile_preview : bool = true; +trile_preview_x : int = 0; +trile_preview_y : int = 0; +trile_preview_z : int = 0; + Level_Editor_Tab :: enum { TACOMA; TOOLS; @@ -241,9 +246,18 @@ add_trile :: (name: string, x: float, y: float, z: float) { tick_level_editor :: () { tick_level_editor_camera(); ray := get_mouse_ray(*get_level_editor_camera()); - hit, point := ray_plane_collision_point(ray, 0.0); - if hit && input_button_states[Key_Code.MOUSE_BUTTON_LEFT] & .START { - handle_tool_click(xx floor(point.x), 0, xx floor(point.y)); + hit, point := ray_plane_collision_point(ray, 0.0, 20); + + show_trile_preview = false; + if hit { + show_trile_preview = true; + trile_preview_x = xx floor(point.x); + trile_preview_y = xx floor(0); + trile_preview_z = xx floor(point.y); + + if input_button_states[Key_Code.MOUSE_BUTTON_LEFT] & .START { + handle_tool_click(xx floor(point.x), 0, xx floor(point.y)); + } } } @@ -269,6 +283,11 @@ draw_level_editor :: () { idx += 1; } + if show_trile_preview && it.trileName == editor_current_trile.name { + positions[idx] = .{xx trile_preview_x, xx trile_preview_y, xx trile_preview_z, 0.0}; + idx += 1; + } + sg_update_buffer(gPipelines.trile.bind.vertex_buffers[3], *(sg_range.{ ptr = positions.data, size = size_of(type_of(positions)), diff --git a/src/ray.jai b/src/ray.jai index 775b736..82fb62a 100644 --- a/src/ray.jai +++ b/src/ray.jai @@ -42,12 +42,15 @@ Ray_Collision :: struct { // At which 2D XZ point does a ray hit the ground plane at a height of // plane_height. Used for the level editor and maybe later the trile editor as well. -ray_plane_collision_point :: (ray: Ray, plane_height: float) -> (bool, Vector2) { +ray_plane_collision_point :: (ray: Ray, plane_height: float, acceptable_radius: float = -1) -> (bool, Vector2) { dist_to_plane := ray.origin.y - plane_height; if ray.direction.y >= 0 then return false, .{0,0}; multi := dist_to_plane / abs(ray.direction.y); ray_to_plane := ray.direction * multi; planePoint := ray_to_plane + ray.origin; + if acceptable_radius > 0 && abs(length(Vector2.{planePoint.x, planePoint.z} - Vector2.{ray.origin.x, ray.origin.z})) > acceptable_radius { + return false, .{}; + } return true, .{planePoint.x, planePoint.z}; }