diff --git a/src/editor/level_editor.jai b/src/editor/level_editor.jai index fc10968..ff027ed 100644 --- a/src/editor/level_editor.jai +++ b/src/editor/level_editor.jai @@ -217,6 +217,8 @@ 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()); + print("Collison point %\n", ray_plane_collision_point(ray, 0)); } draw_level_editor :: () { diff --git a/src/ray.jai b/src/ray.jai index 5fce7ab..74c9acb 100644 --- a/src/ray.jai +++ b/src/ray.jai @@ -40,6 +40,18 @@ Ray_Collision :: struct { normal : Vector3; } +// 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) -> Vector2 { + // @ToDo: This is stupid, but I don't feel like bothering to do this correctly right now... + collision_cube : Collision_Cube = .{ + .{-100000, plane_height, -100000}, + .{100000, plane_height + 0.001, 100000} + }; + collision := does_ray_hit_cube(ray, collision_cube); + return .{collision.point.x, collision.point.z}; +} + // Ported over from Raylib. does_ray_hit_cube :: (og_ray: Ray, cube: Collision_Cube) -> Ray_Collision { ray := og_ray;