start working on level editing with raycasting
This commit is contained in:
parent
ad04c6e32f
commit
3797a94aae
@ -217,6 +217,8 @@ add_trile :: (name: string, x: float, y: float, z: float) {
|
|||||||
|
|
||||||
tick_level_editor :: () {
|
tick_level_editor :: () {
|
||||||
tick_level_editor_camera();
|
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 :: () {
|
draw_level_editor :: () {
|
||||||
|
|||||||
12
src/ray.jai
12
src/ray.jai
@ -40,6 +40,18 @@ Ray_Collision :: struct {
|
|||||||
normal : Vector3;
|
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.
|
// Ported over from Raylib.
|
||||||
does_ray_hit_cube :: (og_ray: Ray, cube: Collision_Cube) -> Ray_Collision {
|
does_ray_hit_cube :: (og_ray: Ray, cube: Collision_Cube) -> Ray_Collision {
|
||||||
ray := og_ray;
|
ray := og_ray;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user