Skip to content

Instantly share code, notes, and snippets.

@cloudhead
Created May 19, 2014 02:48
Show Gist options
  • Save cloudhead/179ce4c86b16e892ebe7 to your computer and use it in GitHub Desktop.
Save cloudhead/179ce4c86b16e892ebe7 to your computer and use it in GitHub Desktop.
impl<T: Float + Show> Mul<Mat4<T>, Mat4<T>> for Mat4<T> {
fn mul(&self, rhs: &Mat4<T>) -> Mat4<T> {
Mat4::new(
self.a1 * rhs.a1 + self.b1 * rhs.a2 + self.c1 * rhs.a3 + self.d1 * rhs.a4,
self.a1 * rhs.b1 + self.b1 * rhs.b2 + self.c1 * rhs.b3 + self.d1 * rhs.b4,
self.a1 * rhs.c1 + self.b1 * rhs.c2 + self.c1 * rhs.c3 + self.d1 * rhs.c4,
self.a1 * rhs.d1 + self.b1 * rhs.d2 + self.c1 * rhs.d3 + self.d1 * rhs.d4,
self.a2 * rhs.a1 + self.b2 * rhs.a2 + self.c2 * rhs.a3 + self.d2 * rhs.a4,
self.a2 * rhs.b1 + self.b2 * rhs.b2 + self.c2 * rhs.b3 + self.d2 * rhs.b4,
self.a2 * rhs.c1 + self.b2 * rhs.c2 + self.c2 * rhs.c3 + self.d2 * rhs.c4,
self.a2 * rhs.d1 + self.b2 * rhs.d2 + self.c2 * rhs.d3 + self.d2 * rhs.d4,
self.a3 * rhs.a1 + self.b3 * rhs.a2 + self.c3 * rhs.a3 + self.d3 * rhs.a4,
self.a3 * rhs.b1 + self.b3 * rhs.b2 + self.c3 * rhs.b3 + self.d3 * rhs.b4,
self.a3 * rhs.c1 + self.b3 * rhs.c2 + self.c3 * rhs.c3 + self.d3 * rhs.c4,
self.a3 * rhs.d1 + self.b3 * rhs.d2 + self.c3 * rhs.d3 + self.d3 * rhs.d4,
self.a4 * rhs.a1 + self.b4 * rhs.a2 + self.c4 * rhs.a3 + self.d4 * rhs.a4,
self.a4 * rhs.b1 + self.b4 * rhs.b2 + self.c4 * rhs.b3 + self.d4 * rhs.b4,
self.a4 * rhs.c1 + self.b4 * rhs.c2 + self.c4 * rhs.c3 + self.d4 * rhs.c4,
self.a4 * rhs.d1 + self.b4 * rhs.d2 + self.c4 * rhs.d3 + self.d4 * rhs.d4
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment