firmath 0.2.0

Math Library for Graphics
Documentation
pub struct Matrix4 {
    m: [[f32; 4]; 4]
}

impl Matrix4 {
    pub fn new(m: [[f32; 4]; 4]) -> Matrix4 {
        Matrix4 {
            m
        }
    }

    pub fn identity() -> Matrix4 {
        Matrix4 {
            m: [
                [1.0, 0.0, 0.0, 0.0],
                [0.0, 1.0, 0.0, 0.0],
                [0.0, 0.0, 1.0, 0.0],
                [0.0, 0.0, 0.0, 1.0]
            ]
        }
    }
}

impl std::ops::Mul for Matrix4 {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self::Output {
        let mut mat = Matrix4::new([[0.0; 4]; 4]);

        for i in 0..4 {
            for j in 0..4 {
                for k in 0..4 {
                    mat.m[i][j] += self.m.concat()[i + 4 * k] * rhs.m.concat()[k + 4 * j]; 
                }
            }
        }

        Self {
            m: mat.m
        }
    } 
}