pub fn world_to_screen(
        &self,
        windows: &Windows,
        camera_transform: &GlobalTransform,
        world_position: Vec3,
    ) -> Option<Vec2> {
        let window = windows.get(self.window)?;
        let window_size = Vec2::new(window.width(), window.height());
        // Build a transform to convert from world to NDC using camera data
        let world_to_ndc: Mat4 =
            self.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
        }
    }
/// Given a position in world space, use the camera to compute the screen space coordinates.
Given a position in world space, use the camera to compute the screen space coordinates.
Given a position in world space use the camera to compute the screen space coordinates .
pub fn world_to_screen(
        &self,
        windows: &Windows,
        camera_transform: &GlobalTransform,
        world_position: Vec3,
    ) -> Option<Vec2> {
        let window = windows.get(self.window)?;
        let window_size = Vec2::new(window.width(), window.height());
        // Build a transform to convert from world to NDC using camera data
        let world_to_ndc: Mat4 =
            self.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 , windows : & Windows , camera_transform : & GlobalTransform , world_position : Vec3 , ) -> Option < Vec2 > { let window = windows . get ( self . window ) ? ; let window_size = Vec2 :: new ( window . width ( ) , window . height ( ) ) ; // Build a transform to convert from world to NDC using camera data let world_to_ndc : Mat4 = self . 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 } }
Given a position in world space, use the camera to compute the screen space coordinates.
Given a position in world space use the camera to compute the screen space coordinates .
&self
windows
&Windows
camera_transform
&GlobalTransform
world_position
Vec3
&self
windows
&Windows
camera_transform
&GlobalTransform
world_position
Vec3