extern crate gml; use gml::*; #[test] fn triangle_normal() { let a = Vector3::new( 1.0, 3.0, 2.0); let b = Vector3::new( 5.0, 11.0, 3.0); let c = Vector3::new(-4.0, -8.0,-1.0); let triangle_normal = (c - a).cross(b - a).normalize(); let expected_answer = Vector3::new(0.849837, -0.457604, 0.261488); assert!(triangle_normal.eq_approx(expected_answer , 1e-5 )); } #[test] fn matrix_transform() { let translate = 3.0f32; let rotate = Vector3f::new(4.0, 7.0, 5.0); let projection = perspective(45.0f32, 4.0f32 / 3.0f32, 0.1f32, 100.0f32); let view_translate = Matrix4x4f::unit().translate( Vector3::new(0.0f32, 0.0f32, -translate)); let view_rotate_x = view_translate.rotate(rotate.y, Vector3f::new(-1.0, 0.0, 0.0)); let view = view_rotate_x.rotate(rotate.x, Vector3f::new(0.0, 1.0, 0.0)); let model = Matrix4x4f::unit().scale(Vector3f::new_s(0.5)); let mvp = projection * view * model; let expect = Matrix4x4f::new(-0.439393, 0.445646, -0.285849, -0.285278, 0.0 , 0.675719, 0.329151, 0.328493, -0.508739, -0.384901, 0.246885, 0.246392, 0.0 , 0.0 , 3.006006, 3.0 ); assert!(mvp.eq_approx(expect, 1e-5) ); }