Function gl_utils::camera2d::screen_2d_to_ndc_2d [−][src]
pub fn screen_2d_to_ndc_2d(
screen_dimensions: Vector2<u16>,
screen_coord: Point2<i16>
) -> Point2<f32>
Convert screen coordinate to OpenGL NDC based on a given screen resolution.
Examples
assert_eq!( screen_2d_to_ndc_2d (cgmath::vec2 (640, 480), (320, 240).into()), (0.0, 0.0).into() ); assert_relative_eq!( screen_2d_to_ndc_2d (cgmath::vec2 (640, 480), (480, 264).into()), (0.5, 0.1).into() ); assert_eq!( screen_2d_to_ndc_2d (cgmath::vec2 (640, 480), (0, 0).into()), (-1.0, -1.0).into() ); assert_eq!( screen_2d_to_ndc_2d (cgmath::vec2 (640, 480), (0, 480).into()), (-1.0, 1.0).into() ); assert_eq!( screen_2d_to_ndc_2d (cgmath::vec2 (640, 480), (640, 0).into()), (1.0, -1.0).into() ); assert_eq!( screen_2d_to_ndc_2d (cgmath::vec2 (640, 480), (640, 480).into()), (1.0, 1.0).into() );