pub fn screen_to_world(
        &self,
        camera: &Camera,
        windows: &Windows,
        camera_transform: &GlobalTransform,
        screen_pos: Vec2,
    ) -> Option<Vec3> {
        let window_size = get_window_size(camera, windows)?;

        // Convert screen position [0..resolution] to ndc [-1..1]
        let ndc = (screen_pos / window_size) * 2.0 - Vec2::ONE;

        let min = -Vec2::ONE;
        let max = Vec2::ONE;
        let below_min = !ndc.cmpge(min);
        let above_max = !ndc.cmplt(max);
        if below_min.any() || above_max.any() {
            return None;
        }

        let ndc_to_world = camera_transform.compute_matrix() * camera.projection_matrix.inverse();

        let world_pos = ndc_to_world.project_point3(ndc.extend(-1.0));
        let world_pos = world_pos.truncate().extend(0.0);

        Some(world_pos)
    }
/// Converts a screen position [0..resolution] to a world position
Converts a screen position [0..resolution] to a world position
Converts a screen position [ 0 .. resolution ] to a world position
pub fn screen_to_world(
        &self,
        camera: &Camera,
        windows: &Windows,
        camera_transform: &GlobalTransform,
        screen_pos: Vec2,
    ) -> Option<Vec3> {
        let window_size = get_window_size(camera, windows)?;
        // Convert screen position [0..resolution] to ndc [-1..1]
        let ndc = (screen_pos / window_size) * 2.0 - Vec2::ONE;
        let min = -Vec2::ONE;
        let max = Vec2::ONE;
        let below_min = !ndc.cmpge(min);
        let above_max = !ndc.cmplt(max);
        if below_min.any() || above_max.any() {
            return None;
        }
        let ndc_to_world = camera_transform.compute_matrix() * camera.projection_matrix.inverse();
        let world_pos = ndc_to_world.project_point3(ndc.extend(-1.0));
        let world_pos = world_pos.truncate().extend(0.0);
        Some(world_pos)
    }
pub fn screen_to_world ( & self , camera : & Camera , windows : & Windows , camera_transform : & GlobalTransform , screen_pos : Vec2 , ) -> Option < Vec3 > { let window_size = get_window_size ( camera , windows ) ? ; // Convert screen position [0..resolution] to ndc [-1..1] let ndc = ( screen_pos / window_size ) * 2.0 - Vec2 :: ONE ; let min = - Vec2 :: ONE ; let max = Vec2 :: ONE ; let below_min = ! ndc . cmpge ( min ) ; let above_max = ! ndc . cmplt ( max ) ; if below_min . any ( ) || above_max . any ( ) { return None ; } let ndc_to_world = camera_transform . compute_matrix ( ) * camera . projection_matrix . inverse ( ) ; let world_pos = ndc_to_world . project_point3 ( ndc . extend ( - 1.0 ) ) ; let world_pos = world_pos . truncate ( ) . extend ( 0.0 ) ; Some ( world_pos ) }
Converts a screen position [0..resolution] to a world position
Converts a screen position [ 0 .. resolution ] to a world position
&self
camera
&Camera
windows
&Windows
camera_transform
&GlobalTransform
screen_pos
Vec2
&self
camera
&Camera
windows
&Windows
camera_transform
&GlobalTransform
screen_pos
Vec2