pub fn ray_from_window_point(
    point: Vec2,
    screen_size: (f32, f32),
    camera_transform_matrix: Mat4,
    camera_projection_matrix: Mat4,
) -> Ray3 {
    let screen_size = Vec2::new(screen_size.0, screen_size.1);

    // Normalized device coordinates (NDC) describes cursor position from (-1, -1, -1) to (1, 1, 1).
    let cursor_pos_ndc: Vec3 = ((point / screen_size) * 2.0 - Vec2::from([1.0, 1.0])).extend(1.0);

    let (_, _, camera_position) = camera_transform_matrix.to_scale_rotation_translation();

    let ndc_to_world = camera_transform_matrix * camera_projection_matrix.inverse();
    let cursor_position = ndc_to_world.project_point3(cursor_pos_ndc);

    let ray_direction = cursor_position - camera_position;

    Ray3::new(camera_position, ray_direction)
}
/// Constructs a 3D ray starting from the window camera's near plane, pointing toward the screen space `point`.
Constructs a 3D ray starting from the window camera's near plane, pointing toward the screen space `point`.
Constructs a 3D ray starting from the window camera ' s near plane pointing toward the screen space ` point ` .
pub fn ray_from_window_point(
    point: Vec2,
    screen_size: (f32, f32),
    camera_transform_matrix: Mat4,
    camera_projection_matrix: Mat4,
) -> Ray3 {
    let screen_size = Vec2::new(screen_size.0, screen_size.1);
    // Normalized device coordinates (NDC) describes cursor position from (-1, -1, -1) to (1, 1, 1).
    let cursor_pos_ndc: Vec3 = ((point / screen_size) * 2.0 - Vec2::from([1.0, 1.0])).extend(1.0);
    let (_, _, camera_position) = camera_transform_matrix.to_scale_rotation_translation();
    let ndc_to_world = camera_transform_matrix * camera_projection_matrix.inverse();
    let cursor_position = ndc_to_world.project_point3(cursor_pos_ndc);
    let ray_direction = cursor_position - camera_position;
    Ray3::new(camera_position, ray_direction)
}
pub fn ray_from_window_point ( point : Vec2 , screen_size : ( f32 , f32 ) , camera_transform_matrix : Mat4 , camera_projection_matrix : Mat4 , ) -> Ray3 { let screen_size = Vec2 :: new ( screen_size . 0 , screen_size . 1 ) ; // Normalized device coordinates (NDC) describes cursor position from (-1, -1, -1) to (1, 1, 1). let cursor_pos_ndc : Vec3 = ( ( point / screen_size ) * 2.0 - Vec2 :: from ( [ 1.0 , 1.0 ] ) ) . extend ( 1.0 ) ; let ( _ , _ , camera_position ) = camera_transform_matrix . to_scale_rotation_translation ( ) ; let ndc_to_world = camera_transform_matrix * camera_projection_matrix . inverse ( ) ; let cursor_position = ndc_to_world . project_point3 ( cursor_pos_ndc ) ; let ray_direction = cursor_position - camera_position ; Ray3 :: new ( camera_position , ray_direction ) }
Constructs a 3D ray starting from the window camera's near plane, pointing toward the screen space `point`.
Constructs a 3D ray starting from the window camera ' s near plane pointing toward the screen space ` point ` .
point
Vec2
screen_size
(f32, f32)
camera_transform_matrix
Mat4
camera_projection_matrix
Mat4
point
Vec2
screen_size
(f32, f32)
camera_transform_matrix
Mat4
camera_projection_matrix
Mat4