feat(vector): add operator* for C3Vector and C44Matrix

This commit is contained in:
fallenoak 2022-12-24 17:08:45 -06:00
parent e960598699
commit 3619492e39
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
2 changed files with 13 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#include "tempest/vector/C3Vector.hpp"
#include "tempest/Math.hpp"
#include "tempest/Matrix.hpp"
C3Vector& C3Vector::operator*=(float a) {
this->x *= a;
@ -29,6 +30,14 @@ C3Vector operator+(const C3Vector& l, const C3Vector& r) {
return { x, y, z };
}
C3Vector operator*(const C3Vector& l, const C44Matrix& r) {
float x = r.c0 * l.z + r.b0 * l.y + r.a0 * l.x + r.d0;
float y = r.c1 * l.z + r.b1 * l.y + r.a1 * l.x + r.d1;
float z = r.c2 * l.z + r.b2 * l.y + r.a2 * l.x + r.d2;
return { x, y, z };
}
bool operator!=(const C3Vector& l, const C3Vector& r) {
return l.x != r.x || l.y != r.y || l.z != r.z;
}