| 1 |
#![allow(unused_variables)] |
| 2 |
|
| 3 |
extern crate nalgebra as na; |
| 4 |
|
| 5 |
use na::{Perspective3, Point2, Point3, Unit}; |
| 6 |
use std::f32::consts; |
| 7 |
|
| 8 |
fn main() { |
| 9 |
let projection = Perspective3::new(800.0 / 600.0, consts::PI / 2.0, 1.0, 1000.0); |
| 10 |
let screen_point = Point2::new(10.0f32, 20.0); |
| 11 |
|
| 12 |
// Compute two points in clip-space. |
| 13 |
// "ndc" = normalized device coordinates. |
| 14 |
let near_ndc_point = Point3::new(screen_point.x / 800.0, screen_point.y / 600.0, -1.0); |
| 15 |
let far_ndc_point = Point3::new(screen_point.x / 800.0, screen_point.y / 600.0, 1.0); |
| 16 |
|
| 17 |
// Unproject them to view-space. |
| 18 |
let near_view_point = projection.unproject_point(&near_ndc_point); |
| 19 |
let far_view_point = projection.unproject_point(&far_ndc_point); |
| 20 |
|
| 21 |
// Compute the view-space line parameters. |
| 22 |
let line_location = near_view_point; |
| 23 |
let line_direction = Unit::new_normalize(far_view_point - near_view_point); |
| 24 |
} |