typhoon/tempest/vector/C3Vector.cpp

44 lines
1,013 B
C++
Raw Permalink Normal View History

2020-11-22 23:25:22 -06:00
#include "tempest/vector/C3Vector.hpp"
2020-11-26 10:48:52 -06:00
#include "tempest/Math.hpp"
#include "tempest/Matrix.hpp"
2020-11-22 23:25:22 -06:00
C3Vector& C3Vector::operator*=(float a) {
this->x *= a;
this->y *= a;
this->z *= a;
return *this;
}
2020-11-26 10:48:52 -06:00
float C3Vector::Mag() const {
return CMath::sqrt(this->SquaredMag());
}
2020-11-26 10:59:42 -06:00
void C3Vector::Normalize() {
this->operator*=(1.0f / this->Mag());
}
2020-11-22 23:25:22 -06:00
float C3Vector::SquaredMag() const {
return this->x * this->x + this->y * this->y + this->z * this->z;
}
C3Vector operator+(const C3Vector& l, const C3Vector& r) {
float x = l.x + r.x;
float y = l.y + r.y;
float z = l.z + r.z;
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;
}