public Mat3f(Mat3f m) { for (int i = 0; i < Size; i++) { cols[i] = new Vec3f(m.cols[i]); } }
public Mat4(Mat3f m, Vec4 v) { for (int i = 0; i < Size - 1; i++) { cols[i] = new Vec4(m[i]); } cols[Size - 1] = new Vec4(v); }
public static Mat3f Identity() { Mat3f m = new Mat3f(); m[0, 0] = 1; m[1, 1] = 1; m[2, 2] = 1; return(m); }
public void Set(Mat3f m) { for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { this[i, j] = m[i, j]; } } }
public static Mat3f operator *(Mat3f l, Mat3f r) { Mat3f Result = new Mat3f(); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { for (int k = 0; k < Size; k++) { Result[i, j] += l[i, k] * r[k, j]; } } } return(Result); }
public void Inverse() { //Generated with https://github.com/willnode/N-Matrix-Programmer var det = this[0, 0] * (this[1, 1] * this[2, 2] - this[1, 2] * this[2, 1]) - this[0, 1] * (this[1, 0] * this[2, 2] - this[1, 2] * this[2, 0]) + this[0, 2] * (this[1, 0] * this[2, 1] - this[1, 1] * this[2, 0]); if (det == 0) { throw new Exception("Error: determinant is zero can't calculate inverse"); } det = 1 / det; Mat3f r = new Mat3f(); r[0, 0] = det * (this[1, 1] * this[2, 2] - this[1, 2] * this[2, 1]); r[0, 1] = det * -(this[0, 1] * this[2, 2] - this[0, 2] * this[2, 1]); r[0, 2] = det * (this[0, 1] * this[1, 2] - this[0, 2] * this[1, 1]); r[1, 0] = det * -(this[1, 0] * this[2, 2] - this[1, 2] * this[2, 0]); r[1, 1] = det * (this[0, 0] * this[2, 2] - this[0, 2] * this[2, 0]); r[1, 2] = det * -(this[0, 0] * this[1, 2] - this[0, 2] * this[1, 0]); r[2, 0] = det * (this[1, 0] * this[2, 1] - this[1, 1] * this[2, 0]); r[2, 1] = det * -(this[0, 0] * this[2, 1] - this[0, 1] * this[2, 0]); r[2, 2] = det * (this[0, 0] * this[1, 1] - this[0, 1] * this[1, 0]); for (int i = 0; i < Size; i++) { for (int j = 0; j < Size; j++) { this[i, j] = r[i, j]; } } }