Function gl_utils::camera3d::transform_mat_world_to_view[][src]

pub fn transform_mat_world_to_view(
    view_position: &Point3<f32>,
    view_orientation: &Basis3<f32>
) -> Matrix4<f32>

Builds a 4x4 transformation matrix that will transform points in world space coordinates to view space coordinates for a given view position and orientation.

Note this accepts input such that the identity orientation defines the view looking down the positive Y axis with the 'up' vector defined by the positive Z axis and the constructed matrix will send points in front of the view to the negative Z axis and points above the view to the positive Y axis:

use cgmath::{ApproxEq, EuclideanSpace, One, Rotation3, Transform};
let position      = cgmath::Point3::origin();
let orientation   = cgmath::Basis3::one();
let transform_mat = transform_mat_world_to_view (&position, &orientation);
assert_eq!(
 transform_mat,
 cgmath::Matrix4::new (
   1.0, 0.0, 0.0, 0.0,
   0.0, 0.0, -1.0, 0.0,
   0.0, 1.0, 0.0, 0.0,
   0.0, 0.0, 0.0, 1.0)
);
let point = cgmath::Point3::new (0.0, 10.0, 0.0);
assert_eq!(
  transform_mat.transform_point (point),
  cgmath::Point3::new (0.0, 0.0, -10.0)
);
let orientation   = cgmath::Basis3::from_angle_z (cgmath::Rad (FRAC_PI_2));
let transform_mat = transform_mat_world_to_view (&position, &orientation);
let point = cgmath::Point3::new (-10.0, 0.0, 0.0);
assert_relative_eq!(
  transform_mat.transform_point (point),
  cgmath::Point3::new (0.0, 0.0, -10.0),
  epsilon = 10.0 * f32::default_epsilon()
);