feat(matrix): add operator* for C44Matrix and float

This commit is contained in:
fallenoak 2020-11-29 13:40:10 -06:00
parent 63a478841a
commit 571f2369f9
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
3 changed files with 49 additions and 0 deletions

View file

@ -27,3 +27,27 @@ C44Matrix C44Matrix::Adjoint() const {
float C44Matrix::Determinant() {
return (this->b1 * this->c2 * this->d3 + this->c3 * this->b2 * this->d1 + this->b3 * this->c1 * this->d2 - this->c2 * this->b3 * this->d1 - this->d3 * (this->c1 * this->b2) - this->b1 * this->c3 * this->d2) * this->a0 - (this->c2 * this->b0 * this->d3 + this->c3 * this->b2 * this->d0 + this->b3 * this->c0 * this->d2 - this->b3 * this->c2 * this->d0 - this->d3 * (this->c0 * this->b2) - this->b0 * this->c3 * this->d2) * this->a1 + (this->c1 * this->b0 * this->d3 + this->c3 * this->b1 * this->d0 + this->b3 * this->c0 * this->d1 - this->b3 * this->c1 * this->d0 - this->d3 * (this->c0 * this->b1) - this->b0 * this->c3 * this->d1) * this->a2 - (this->c1 * this->b0 * this->d2 + this->c2 * this->b1 * this->d0 + this->b2 * this->c0 * this->d1 - this->b2 * this->c1 * this->d0 - this->d2 * (this->c0 * this->b1) - this->b0 * this->c2 * this->d1) * this->a3;
}
C44Matrix operator*(const C44Matrix& l, float a) {
float a0 = l.a0 * a;
float a1 = l.a1 * a;
float a2 = l.a2 * a;
float a3 = l.a3 * a;
float b0 = l.b0 * a;
float b1 = l.b1 * a;
float b2 = l.b2 * a;
float b3 = l.b3 * a;
float c0 = l.c0 * a;
float c1 = l.c1 * a;
float c2 = l.c2 * a;
float c3 = l.c3 * a;
float d0 = l.d0 * a;
float d1 = l.d1 * a;
float d2 = l.d2 * a;
float d3 = l.d3 * a;
return { a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3 };
}

View file

@ -44,4 +44,6 @@ class C44Matrix {
float Determinant();
};
C44Matrix operator*(const C44Matrix& l, float a);
#endif