From 3619492e39504c1d1537b8fa1069784b67918fb2 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Sat, 24 Dec 2022 17:08:45 -0600 Subject: [PATCH] feat(vector): add operator* for C3Vector and C44Matrix --- tempest/vector/C3Vector.cpp | 9 +++++++++ tempest/vector/C3Vector.hpp | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/tempest/vector/C3Vector.cpp b/tempest/vector/C3Vector.cpp index 8e222c2..0e6053b 100644 --- a/tempest/vector/C3Vector.cpp +++ b/tempest/vector/C3Vector.cpp @@ -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; } diff --git a/tempest/vector/C3Vector.hpp b/tempest/vector/C3Vector.hpp index 49b3c9c..c66c01f 100644 --- a/tempest/vector/C3Vector.hpp +++ b/tempest/vector/C3Vector.hpp @@ -1,6 +1,8 @@ #ifndef TEMPEST_VECTOR_C_3VECTOR_HPP #define TEMPEST_VECTOR_C_3VECTOR_HPP +class C44Matrix; + class C3Vector { public: // Member variables @@ -22,6 +24,8 @@ class C3Vector { C3Vector operator+(const C3Vector& l, const C3Vector& r); +C3Vector operator*(const C3Vector& l, const C44Matrix& r); + bool operator!=(const C3Vector& l, const C3Vector& r); #endif