mirror of
https://github.com/thunderbrewhq/typhoon.git
synced 2025-12-12 02:22:30 +00:00
feat(matrix): add operator* for C44Matrix and float
This commit is contained in:
parent
63a478841a
commit
571f2369f9
3 changed files with 49 additions and 0 deletions
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,4 +44,6 @@ class C44Matrix {
|
|||
float Determinant();
|
||||
};
|
||||
|
||||
C44Matrix operator*(const C44Matrix& l, float a);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -127,3 +127,26 @@ TEST_CASE("C44Matrix::Determinant", "[matrix]") {
|
|||
REQUIRE(determinant == -704.0f);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("C44Matrix global operators", "[matrix]") {
|
||||
SECTION("C44Matrix * float") {
|
||||
auto matrix1 = C44Matrix(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f);
|
||||
auto matrix2 = matrix1 * 2.0f;
|
||||
CHECK(matrix2.a0 == 2.0f);
|
||||
CHECK(matrix2.a1 == 4.0f);
|
||||
CHECK(matrix2.a2 == 6.0f);
|
||||
CHECK(matrix2.a3 == 8.0f);
|
||||
CHECK(matrix2.b0 == 10.0f);
|
||||
CHECK(matrix2.b1 == 12.0f);
|
||||
CHECK(matrix2.b2 == 14.0f);
|
||||
CHECK(matrix2.b3 == 16.0f);
|
||||
CHECK(matrix2.c0 == 18.0f);
|
||||
CHECK(matrix2.c1 == 20.0f);
|
||||
CHECK(matrix2.c2 == 22.0f);
|
||||
CHECK(matrix2.c3 == 24.0f);
|
||||
CHECK(matrix2.d0 == 26.0f);
|
||||
CHECK(matrix2.d1 == 28.0f);
|
||||
CHECK(matrix2.d2 == 30.0f);
|
||||
CHECK(matrix2.d3 == 32.0f);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue