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);
|
||||
|
||||
Reference in New Issue
Block a user