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

        // Build a transform to convert from world to NDC using camera data
        let world_to_ndc: Mat4 =
            camera.projection_matrix * camera_transform.compute_matrix().inverse();
        let ndc_space_coords: Vec3 = world_to_ndc.project_point3(world_position);

        // NDC z-values outside of 0 < z < 1 are outside the camera frustum and are thus not in screen space
        if ndc_space_coords.z < 0.0 || ndc_space_coords.z > 1.0 {
            return None;
        }

        // Once in NDC space, we can discard the z element and rescale x/y to fit the screen
        let screen_space_coords = (ndc_space_coords.truncate() + Vec2::ONE) / 2.0 * window_size;
        if !screen_space_coords.is_nan() {
            Some(screen_space_coords)
        } else {
            None
        }
    }
/// Converts a world position to a screen position (0..resolution)
Converts a world position to a screen position (0..resolution)
Converts a world position to a screen position ( 0 .. resolution )
pub fn world_to_screen(
        &self,
        camera: &Camera,
        windows: &Windows,
        camera_transform: &GlobalTransform,
        world_position: Vec3,
    ) -> Option<Vec2> {
        let window_size = get_window_size(camera, windows)?;
        // Build a transform to convert from world to NDC using camera data
        let world_to_ndc: Mat4 =
            camera.projection_matrix * camera_transform.compute_matrix().inverse();
        let ndc_space_coords: Vec3 = world_to_ndc.project_point3(world_position);
        // NDC z-values outside of 0 < z < 1 are outside the camera frustum and are thus not in screen space
        if ndc_space_coords.z < 0.0 || ndc_space_coords.z > 1.0 {
            return None;
        }
        // Once in NDC space, we can discard the z element and rescale x/y to fit the screen
        let screen_space_coords = (ndc_space_coords.truncate() + Vec2::ONE) / 2.0 * window_size;
        if !screen_space_coords.is_nan() {
            Some(screen_space_coords)
        } else {
            None
        }
    }
pub fn world_to_screen ( & self , camera : & Camera , windows : & Windows , camera_transform : & GlobalTransform , world_position : Vec3 , ) -> Option < Vec2 > { let window_size = get_window_size ( camera , windows ) ? ; // Build a transform to convert from world to NDC using camera data let world_to_ndc : Mat4 = camera . projection_matrix * camera_transform . compute_matrix ( ) . inverse ( ) ; let ndc_space_coords : Vec3 = world_to_ndc . project_point3 ( world_position ) ; // NDC z-values outside of 0 < z < 1 are outside the camera frustum and are thus not in screen space if ndc_space_coords . z < 0.0 || ndc_space_coords . z > 1.0 { return None ; } // Once in NDC space, we can discard the z element and rescale x/y to fit the screen let screen_space_coords = ( ndc_space_coords . truncate ( ) + Vec2 :: ONE ) / 2.0 * window_size ; if ! screen_space_coords . is_nan ( ) { Some ( screen_space_coords ) } else { None } }
Converts a world position to a screen position (0..resolution)
Converts a world position to a screen position ( 0 .. resolution )
&self
camera
&Camera
windows
&Windows
camera_transform
&GlobalTransform
world_position
Vec3
&self
camera
&Camera
windows
&Windows
camera_transform
&GlobalTransform
world_position
Vec3