public static RotationMatrix Multiply(RotationMatrix left, RotationMatrix right) { RotationMatrix result = new RotationMatrix(); result.M00 = (left.M00 * right.M00) + (left.M01 * right.M10) + (left.M02 * right.M20); result.M01 = (left.M00 * right.M01) + (left.M01 * right.M11) + (left.M02 * right.M21); result.M02 = (left.M00 * right.M02) + (left.M01 * right.M12) + (left.M02 * right.M22); result.M10 = (left.M10 * right.M00) + (left.M11 * right.M10) + (left.M12 * right.M20); result.M11 = (left.M10 * right.M01) + (left.M11 * right.M11) + (left.M12 * right.M21); result.M12 = (left.M10 * right.M02) + (left.M11 * right.M12) + (left.M12 * right.M22); result.M20 = (left.M20 * right.M00) + (left.M21 * right.M10) + (left.M22 * right.M20); result.M21 = (left.M20 * right.M01) + (left.M21 * right.M11) + (left.M22 * right.M21); result.M22 = (left.M20 * right.M02) + (left.M21 * right.M12) + (left.M22 * right.M22); return result; // this code was before I remembered matrix multiplication is hard. /*RotationMatrix m = new RotationMatrix(); m.M00 = m1.M00 * m2.M00; m.M01 = m1.M01 * m2.M01; m.M02 = m1.M02 * m2.M02; m.M10 = m1.M10 * m2.M10; m.M11 = m1.M11 * m2.M11; m.M12 = m1.M12 * m2.M12; m.M20 = m1.M20 * m2.M20; m.M21 = m1.M21 * m2.M21; m.M22 = m1.M22 * m2.M22; return m;*/ }
public static RotationMatrix Multiply(RotationMatrix left, RotationMatrix right) { RotationMatrix result = new RotationMatrix(); result.M00 = (left.M00 * right.M00) + (left.M01 * right.M10) + (left.M02 * right.M20); result.M01 = (left.M00 * right.M01) + (left.M01 * right.M11) + (left.M02 * right.M21); result.M02 = (left.M00 * right.M02) + (left.M01 * right.M12) + (left.M02 * right.M22); result.M10 = (left.M10 * right.M00) + (left.M11 * right.M10) + (left.M12 * right.M20); result.M11 = (left.M10 * right.M01) + (left.M11 * right.M11) + (left.M12 * right.M21); result.M12 = (left.M10 * right.M02) + (left.M11 * right.M12) + (left.M12 * right.M22); result.M20 = (left.M20 * right.M00) + (left.M21 * right.M10) + (left.M22 * right.M20); result.M21 = (left.M20 * right.M01) + (left.M21 * right.M11) + (left.M22 * right.M21); result.M22 = (left.M20 * right.M02) + (left.M21 * right.M12) + (left.M22 * right.M22); return(result); // this code was before I remembered matrix multiplication is hard. /*RotationMatrix m = new RotationMatrix(); * m.M00 = m1.M00 * m2.M00; * m.M01 = m1.M01 * m2.M01; * m.M02 = m1.M02 * m2.M02; * * m.M10 = m1.M10 * m2.M10; * m.M11 = m1.M11 * m2.M11; * m.M12 = m1.M12 * m2.M12; * * m.M20 = m1.M20 * m2.M20; * m.M21 = m1.M21 * m2.M21; * m.M22 = m1.M22 * m2.M22; * * return m;*/ }
public static RotationMatrix RotateX(float degrees) { float radians = (float)(degrees * (Math.PI / 180)); RotationMatrix matrix = new RotationMatrix(); matrix.M00 = 1; matrix.M01 = 0; matrix.M02 = 0; matrix.M10 = 0; matrix.M11 = (float)Math.Cos(radians); matrix.M12 = -((float)Math.Sin(radians)); matrix.M20 = 0; matrix.M21 = (float)Math.Sin(radians); matrix.M22 = (float)Math.Cos(radians); return(matrix); }
public static RotationMatrix RotateZ(float degrees) { float radians = (float)(degrees * (Math.PI / 180)); RotationMatrix matrix = new RotationMatrix(); matrix.M00 = (float)Math.Cos(radians); matrix.M01 = 0; matrix.M02 = (float)Math.Sin(radians); matrix.M10 = 0; matrix.M11 = 1; matrix.M12 = 0; matrix.M20 = -((float)Math.Sin(radians)); matrix.M21 = 0; matrix.M22 = (float)Math.Cos(radians); return matrix; }
public static RotationMatrix Rotate(float x, float y, float z) { return(RotationMatrix.RotateX(x) * RotationMatrix.RotateY(y) * RotationMatrix.RotateZ(z)); }