1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
use std::ops::*; use crate::vec::*; macro_rules! mat3s { ($($n:ident => $t:ident),+) => { $(#[derive(Clone, Copy, Debug)] pub struct $n { pub cols: [$t; 3], } impl $n { #[inline] pub fn new(col1: $t, col2: $t, col3: $t) -> Self { $n { cols: [col1, col2, col3], } } } impl Mul<$t> for $n { type Output = $t; #[inline] fn mul(self, rhs: $t) -> $t { let a = self.cols[0]; let b = self.cols[1]; let c = self.cols[2]; $t::new( a.x * rhs.x + b.x * rhs.y + c.x * rhs.z, a.y * rhs.x + b.y * rhs.y + c.y * rhs.z, a.z * rhs.x + b.z * rhs.y + c.z * rhs.z, ) } })+ } } mat3s!(Mat3 => Vec3, Wat3 => Wec3);