2018-12-14 19:50:58 +08:00
|
|
|
extern crate nalgebra as na;
|
|
|
|
extern crate nalgebra_glm as glm;
|
|
|
|
|
|
|
|
use glm::Mat4;
|
|
|
|
use glm::Vec4;
|
2020-04-06 00:49:48 +08:00
|
|
|
use na::Orthographic3;
|
|
|
|
use na::Perspective3;
|
2018-12-14 19:50:58 +08:00
|
|
|
|
|
|
|
#[test]
|
2020-04-06 00:49:48 +08:00
|
|
|
pub fn orthographic_glm_nalgebra_same() {
|
|
|
|
let na_mat: Mat4 =
|
|
|
|
Orthographic3::new(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner();
|
|
|
|
let gl_mat: Mat4 = glm::ortho(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32);
|
2018-12-14 19:50:58 +08:00
|
|
|
|
|
|
|
assert_eq!(na_mat, gl_mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-06 00:49:48 +08:00
|
|
|
pub fn perspective_glm_nalgebra_same() {
|
|
|
|
let na_mat: Mat4 =
|
|
|
|
Perspective3::new(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32).into_inner();
|
|
|
|
let gl_mat: Mat4 = glm::perspective(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32);
|
2018-12-14 19:50:58 +08:00
|
|
|
|
|
|
|
assert_eq!(na_mat, gl_mat);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-06 00:49:48 +08:00
|
|
|
pub fn orthographic_glm_nalgebra_project_same() {
|
|
|
|
let point = Vec4::new(1.0, 0.0, -20.0, 1.0);
|
2018-12-14 19:50:58 +08:00
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
let na_mat: Mat4 =
|
|
|
|
Orthographic3::new(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner();
|
|
|
|
let gl_mat: Mat4 = glm::ortho(-100.0f32, 100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32);
|
2018-12-14 19:50:58 +08:00
|
|
|
|
|
|
|
let na_pt = na_mat * point;
|
|
|
|
let gl_pt = gl_mat * point;
|
|
|
|
|
2018-12-14 20:03:13 +08:00
|
|
|
assert_eq!(na_mat, gl_mat);
|
2018-12-14 19:50:58 +08:00
|
|
|
assert_eq!(na_pt, gl_pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-04-06 00:49:48 +08:00
|
|
|
pub fn perspective_glm_nalgebra_project_same() {
|
|
|
|
let point = Vec4::new(1.0, 0.0, -20.0, 1.0);
|
2018-12-14 19:50:58 +08:00
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
let na_mat: Mat4 =
|
|
|
|
Perspective3::new(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32).into_inner();
|
|
|
|
let gl_mat: Mat4 = glm::perspective(16.0f32 / 9.0f32, 3.14f32 / 2.0f32, 0.1f32, 100.0f32);
|
2018-12-14 19:50:58 +08:00
|
|
|
|
|
|
|
let na_pt = na_mat * point;
|
|
|
|
let gl_pt = gl_mat * point;
|
|
|
|
|
2018-12-14 20:03:13 +08:00
|
|
|
assert_eq!(na_mat, gl_mat);
|
2018-12-14 19:50:58 +08:00
|
|
|
assert_eq!(na_pt, gl_pt);
|
2019-02-03 17:56:30 +08:00
|
|
|
}
|