Compare commits
No commits in common. "2898cfce76aaff988bcded8063d754e1e87aabad" and "3797a94aaed8e4cbf394c799d23784b9e78c2cb1" have entirely different histories.
2898cfce76
...
3797a94aae
@ -41,6 +41,8 @@ Level_Editor_Tab :: enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
current_tab : Level_Editor_Tab = .TOOLS;
|
current_tab : Level_Editor_Tab = .TOOLS;
|
||||||
|
current_trile : *Trile = null;
|
||||||
|
|
||||||
get_level_editor_camera :: () -> Camera {
|
get_level_editor_camera :: () -> Camera {
|
||||||
camera: Camera;
|
camera: Camera;
|
||||||
camera.near = 0.1;
|
camera.near = 0.1;
|
||||||
@ -196,32 +198,9 @@ draw_tacoma_tab :: (theme: *GR.Overall_Theme, total_r: GR.Rect) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_tool_click :: (x: int, y: int, z: int) {
|
|
||||||
if editor_current_trile != null then add_trile(editor_current_trile.name, cast(float)x, cast(float)y, cast(float)z);
|
|
||||||
}
|
|
||||||
|
|
||||||
#scope_export
|
#scope_export
|
||||||
|
|
||||||
add_trile :: (name: string, x: float, y: float, z: float) {
|
add_trile :: (name: string, x: float, y: float, z: float) {
|
||||||
|
|
||||||
loose_float_comp :: (a: float, b: float) -> bool {
|
|
||||||
return abs(a-b) < 0.001;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the position is already occupied. @ToDo: we would probably like to
|
|
||||||
// have some acceleration structure like a hashmap to speed up this check when
|
|
||||||
// we are checking for collisions.
|
|
||||||
for world.positions {
|
|
||||||
for v, idx: it.positions {
|
|
||||||
if loose_float_comp(v.x, x)
|
|
||||||
&& loose_float_comp(v.y, y)
|
|
||||||
&& loose_float_comp(v.z, z) {
|
|
||||||
array_unordered_remove_by_index(*it.positions, idx);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for world.positions {
|
for world.positions {
|
||||||
if it.trileName == name {
|
if it.trileName == name {
|
||||||
array_add(*it.positions, Vector4.{x,y,z,1});
|
array_add(*it.positions, Vector4.{x,y,z,1});
|
||||||
@ -236,15 +215,10 @@ add_trile :: (name: string, x: float, y: float, z: float) {
|
|||||||
array_add(*world.positions, poses);
|
array_add(*world.positions, poses);
|
||||||
} @Command
|
} @Command
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tick_level_editor :: () {
|
tick_level_editor :: () {
|
||||||
tick_level_editor_camera();
|
tick_level_editor_camera();
|
||||||
ray := get_mouse_ray(*get_level_editor_camera());
|
ray := get_mouse_ray(*get_level_editor_camera());
|
||||||
hit, point := ray_plane_collision_point(ray, 0.0);
|
print("Collison point %\n", ray_plane_collision_point(ray, 0));
|
||||||
if hit && input_button_states[Key_Code.MOUSE_BUTTON_LEFT] & .START {
|
|
||||||
handle_tool_click(xx floor(point.x), 0, xx floor(point.y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_level_editor :: () {
|
draw_level_editor :: () {
|
||||||
|
|||||||
15
src/ray.jai
15
src/ray.jai
@ -42,13 +42,14 @@ Ray_Collision :: struct {
|
|||||||
|
|
||||||
// At which 2D XZ point does a ray hit the ground plane at a height of
|
// 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.
|
// 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) -> Vector2 {
|
||||||
dist_to_plane := ray.origin.y - plane_height;
|
// @ToDo: This is stupid, but I don't feel like bothering to do this correctly right now...
|
||||||
if ray.direction.y >= 0 then return false, .{0,0};
|
collision_cube : Collision_Cube = .{
|
||||||
multi := dist_to_plane / abs(ray.direction.y);
|
.{-100000, plane_height, -100000},
|
||||||
ray_to_plane := ray.direction * multi;
|
.{100000, plane_height + 0.001, 100000}
|
||||||
planePoint := ray_to_plane + ray.origin;
|
};
|
||||||
return true, .{planePoint.x, planePoint.z};
|
collision := does_ray_hit_cube(ray, collision_cube);
|
||||||
|
return .{collision.point.x, collision.point.z};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ported over from Raylib.
|
// Ported over from Raylib.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user