more vect operators
This commit is contained in:
@@ -4,10 +4,9 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace maths {
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Vectors //
|
// Operators //
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -16,13 +15,18 @@ Vec2<T> operator+(const Vec2<T>& vect, const Vec2<T>& other) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Vec3<T> operator- (const Vec3<T>& vect) {
|
Vec2<T> operator- (const Vec2<T>& vect) {
|
||||||
return { -vect.x, -vect.y, -vect.z };
|
return { -vect.x, -vect.y };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Vec4<T> operator- (const Vec4<T>& vect) {
|
Vec2<T> operator- (const Vec2<T>& vect, const Vec2<T>& other) {
|
||||||
return { -vect.x, -vect.y, -vect.z, -vect.w };
|
return vect + (-other);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec3<T> operator- (const Vec3<T>& vect) {
|
||||||
|
return { -vect.x, -vect.y, -vect.z };
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -35,6 +39,27 @@ Vec3<T> operator- (const Vec3<T>& vect, const Vec3<T>& other) {
|
|||||||
return vect + (-other);
|
return vect + (-other);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec4<T> operator- (const Vec4<T>& vect) {
|
||||||
|
return { -vect.x, -vect.y, -vect.z, -vect.w };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec4<T> operator+ (const Vec4<T>& vect, const Vec4<T>& other) {
|
||||||
|
return { vect.x + other.x, vect.y + other.y, vect.z + other.y, vect.w + other.w };
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
Vec4<T> operator- (const Vec4<T>& vect, const Vec4<T>& other) {
|
||||||
|
return vect + (-other);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// Vectors //
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
namespace maths {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T Length(const Vec3<T>& vect) {
|
T Length(const Vec3<T>& vect) {
|
||||||
return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);
|
return std::sqrt(vect.x * vect.x + vect.y * vect.y + vect.z * vect.z);
|
||||||
|
|||||||
Reference in New Issue
Block a user