Renamed v2 camera ray procs and added auto normalization of screen coords
This commit is contained in:
@@ -162,7 +162,7 @@ screen_to_world :: (camera: Camera, screen_position: Vector2, distance: float) -
|
||||
return world_position;
|
||||
}
|
||||
|
||||
normalized_screen_to_ray_v2 :: (camera: Camera, screen_position: Vector2) -> Ray {
|
||||
normalized_screen_to_ray :: (camera: Camera, screen_position: Vector2) -> Ray {
|
||||
nds : Vector2;
|
||||
nds.x = (2.0 * screen_position.x) - 1.0;
|
||||
nds.y = (2.0 * screen_position.y) - 1.0;
|
||||
@@ -195,7 +195,9 @@ normalized_screen_to_ray_v2 :: (camera: Camera, screen_position: Vector2) -> Ray
|
||||
}
|
||||
|
||||
|
||||
screen_to_ray_v2 :: (camera: Camera, screen_position: Vector2, screen_size: Vector2) -> Ray {
|
||||
screen_to_ray :: (camera: Camera, screen_position: Vector2) -> Ray {
|
||||
screen_size := Vector2.{xx engine.renderer.render_target_width, xx engine.renderer.render_target_height};
|
||||
|
||||
nds : Vector2;
|
||||
nds.x = (2.0 * screen_position.x) / screen_size.x - 1.0;
|
||||
nds.y = (2.0 * screen_position.y) / screen_size.y - 1.0;
|
||||
@@ -227,32 +229,6 @@ screen_to_ray_v2 :: (camera: Camera, screen_position: Vector2, screen_size: Vect
|
||||
return ray;
|
||||
}
|
||||
|
||||
screen_to_ray :: (camera: *Camera, screen_position: Vector2, screen_size: Vector2) -> Ray {
|
||||
ray : Ray;
|
||||
ray.origin = camera.position;
|
||||
|
||||
ray_nds : Vector3;
|
||||
ray_nds.x = (2.0 * screen_position.x) / screen_size.x - 1.0;
|
||||
ray_nds.y = (2.0 * screen_position.y) / screen_size.y - 1.0;
|
||||
ray_nds.z = 0.0;
|
||||
|
||||
ray_clip : Vector4;
|
||||
ray_clip.x = ray_nds.x;
|
||||
ray_clip.y = ray_nds.y;
|
||||
ray_clip.z = -1.0;
|
||||
ray_clip.w = 1.0;
|
||||
|
||||
success :, ray_eye := inverse(camera.projection_matrix) * ray_clip;
|
||||
ray_eye.z = 1.0;
|
||||
ray_eye.w = 0.0;
|
||||
|
||||
success2 :, inv_cam_matrix := inverse(camera.view_matrix);
|
||||
ray_world := to_v3(inv_cam_matrix * ray_eye);
|
||||
ray.direction = normalize(ray_world);
|
||||
|
||||
return ray;
|
||||
}
|
||||
|
||||
set_fov :: (camera: *Camera, fov: float) {
|
||||
camera.fov = fov;
|
||||
camera.projection_matrix = make_lh_projection_matrix(fov * (TAU / 360.0), camera.aspect_ratio, camera.z_near, camera.z_far);
|
||||
|
||||
@@ -220,7 +220,7 @@ update_transform_gizmo :: (ray: Ray, mouse_position: Vector2) -> bool {
|
||||
r1.origin = selected_entity.transform.position;
|
||||
r1.direction = rotate(axis_vec, engine.editor.transform_gizmo.transform.orientation);
|
||||
|
||||
r2 := normalized_screen_to_ray_v2(*engine.editor.camera, mouse_position);
|
||||
r2 := normalized_screen_to_ray(*engine.editor.camera, mouse_position);
|
||||
|
||||
d, t1, t2 := closest_distance_between_rays(r1, r2);
|
||||
|
||||
@@ -376,11 +376,7 @@ update_transform_gizmo :: (ray: Ray, mouse_position: Vector2) -> bool {
|
||||
mouse_position.x = xx engine.input.mouse.x;
|
||||
mouse_position.y = xx engine.input.mouse.y;
|
||||
|
||||
screen_size : Vector2;
|
||||
screen_size.x = cast(float)engine.window.width;
|
||||
screen_size.y = cast(float)engine.window.height;
|
||||
|
||||
r2 := screen_to_ray_v2(*engine.editor.camera, mouse_position, screen_size);
|
||||
r2 := screen_to_ray(*engine.editor.camera, mouse_position);
|
||||
|
||||
d, t1, t2 := closest_distance_between_rays(r1, r2);
|
||||
new_position := r1.origin + r1.direction * t1;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#load "../ui/widgets.jai";
|
||||
|
||||
pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
|
||||
ray := normalized_screen_to_ray_v2(camera, coordinates);
|
||||
ray := normalized_screen_to_ray(camera, coordinates);
|
||||
|
||||
if engine.editor.should_check_entities {
|
||||
hit_entity : *Entity;
|
||||
@@ -182,7 +182,7 @@ base_editor_update :: () {
|
||||
coordinates.y = 1.0 - coordinates.y;
|
||||
|
||||
//coordinates := Vector2.{engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
|
||||
ray := normalized_screen_to_ray_v2(engine.editor.camera, coordinates);
|
||||
ray := normalized_screen_to_ray(engine.editor.camera, coordinates);
|
||||
|
||||
if !blocking_input {
|
||||
if update_transform_gizmo(ray, coordinates) {
|
||||
|
||||
Reference in New Issue
Block a user