diff options
| -rw-r--r-- | engine/src/data_types/matrix.rs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/engine/src/data_types/matrix.rs b/engine/src/data_types/matrix.rs index a1e9bb6..b480c35 100644 --- a/engine/src/data_types/matrix.rs +++ b/engine/src/data_types/matrix.rs @@ -353,6 +353,119 @@ where } } +impl<Value, const COLUMNS: usize> Mul<Vec3<Value>> for Matrix<Value, 3, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec3<Value>; + + fn mul(self, rhs: Vec3<Value>) -> Self::Output + { + &self * &rhs + } +} + +impl<Value, const COLUMNS: usize> Mul<&Vec3<Value>> for Matrix<Value, 3, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec3<Value>; + + fn mul(self, rhs: &Vec3<Value>) -> Self::Output + { + &self * rhs + } +} + +impl<Value, const COLUMNS: usize> Mul<Vec3<Value>> for &Matrix<Value, 3, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec3<Value>; + + fn mul(self, rhs: Vec3<Value>) -> Self::Output + { + self * &rhs + } +} + +impl<Value, const COLUMNS: usize> Mul<&Vec3<Value>> for &Matrix<Value, 3, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec3<Value>; + + fn mul(self, rhs: &Vec3<Value>) -> Self::Output + { + let rhs_mat = Matrix::<Value, 3, 1> { items: [[rhs.x], [rhs.y], [rhs.z]] }; + + let Matrix { items: [[out_x], [out_y], [out_z]] } = self * &rhs_mat; + + Vec3 { x: out_x, y: out_y, z: out_z } + } +} + +impl<Value, const COLUMNS: usize> Mul<Vec4<Value>> for Matrix<Value, 4, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec4<Value>; + + fn mul(self, rhs: Vec4<Value>) -> Self::Output + { + &self * &rhs + } +} + +impl<Value, const COLUMNS: usize> Mul<&Vec4<Value>> for Matrix<Value, 4, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec4<Value>; + + fn mul(self, rhs: &Vec4<Value>) -> Self::Output + { + &self * rhs + } +} + +impl<Value, const COLUMNS: usize> Mul<Vec4<Value>> for &Matrix<Value, 4, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec4<Value>; + + fn mul(self, rhs: Vec4<Value>) -> Self::Output + { + self * &rhs + } +} + +impl<Value, const COLUMNS: usize> Mul<&Vec4<Value>> for &Matrix<Value, 4, COLUMNS> +where + Value: Mul<Output = Value> + Add<Output = Value> + Default + Copy, +{ + type Output = Vec4<Value>; + + fn mul(self, rhs: &Vec4<Value>) -> Self::Output + { + let rhs_mat = Matrix::<Value, 4, 1> { + items: [[rhs.x], [rhs.y], [rhs.z], [rhs.w]], + }; + + let Matrix { + items: [[out_x], [out_y], [out_z], [out_w]], + } = self * &rhs_mat; + + Vec4 { + x: out_x, + y: out_y, + z: out_z, + w: out_w, + } + } +} + impl<Value, const ROWS: usize, const COLUMNS: usize> Index<CellPos> for Matrix<Value, ROWS, COLUMNS> { |
