start working on level editing with raycasting

This commit is contained in:
Tuomas Katajisto 2025-09-14 19:55:55 +03:00
parent ad04c6e32f
commit 3797a94aae
2 changed files with 14 additions and 0 deletions

View File

@ -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 :: () {

View File

@ -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;