Skip to main content

yog_body/
math.rs

1//! The vectors and matrices bodies use are `yog-graphics`' own.
2
3pub use yog_graphics::{Mat4, Vec3, rad};
4
5/// `ModelPart.translateAndRotate`: to the pivot, turned, scaled.
6pub fn part(pivot: Vec3, rotation: Vec3, scale: Vec3) -> Mat4 {
7    Mat4::translation(pivot) * Mat4::rotation_zyx(rotation) * Mat4::scaling(scale)
8}
9
10#[cfg(test)]
11mod tests {
12    use super::*;
13
14    #[test]
15    fn a_part_moves_after_turning() {
16        let m = part(Vec3::new(5.0, 0.0, 0.0), Vec3::new(0.0, 0.0, std::f32::consts::FRAC_PI_2), Vec3::ONE);
17        let p = m.transform_point(Vec3::new(1.0, 0.0, 0.0));
18        assert!((p.x - 5.0).abs() < 1e-5 && (p.y - 1.0).abs() < 1e-5, "{p:?}");
19    }
20}