nalgebra/examples/mvp.rs

30 lines
963 B
Rust
Raw Permalink Normal View History

2017-02-13 01:17:09 +08:00
#![allow(unused_variables)]
extern crate nalgebra as na;
2018-02-02 19:26:35 +08:00
use na::{Isometry3, Perspective3, Point3, Vector3};
2021-08-16 00:12:17 +08:00
use std::f32::consts;
2017-02-13 01:17:09 +08:00
fn main() {
// Our object is translated along the x axis.
let model = Isometry3::new(Vector3::x(), na::zero());
// Our camera looks toward the point (1.0, 0.0, 0.0).
// It is located at (0.0, 0.0, 1.0).
2018-02-02 19:26:35 +08:00
let eye = Point3::new(0.0, 0.0, 1.0);
2017-02-13 01:17:09 +08:00
let target = Point3::new(1.0, 0.0, 0.0);
2018-02-02 19:26:35 +08:00
let view = Isometry3::look_at_rh(&eye, &target, &Vector3::y());
2017-02-13 01:17:09 +08:00
// A perspective projection.
2021-08-16 00:12:17 +08:00
let projection = Perspective3::new(16.0 / 9.0, consts::PI / 2.0, 1.0, 1000.0);
2017-02-13 01:17:09 +08:00
// The combination of the model with the view is still an isometry.
let model_view = view * model;
2017-02-13 01:17:09 +08:00
// Convert everything to a `Matrix4` so that they can be combined.
let mat_model_view = model_view.to_homogeneous();
// Combine everything.
let model_view_projection = projection.as_matrix() * mat_model_view;
}