diff options
Diffstat (limited to 'src/Vector.hpp')
-rw-r--r-- | src/Vector.hpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/Vector.hpp b/src/Vector.hpp index 5795db2..aa79ef0 100644 --- a/src/Vector.hpp +++ b/src/Vector.hpp @@ -31,6 +31,24 @@ struct Vector3 { std::swap(z, rhs.z); } + T dot(const Vector3 &rhs) const { + return x*rhs.x + y*rhs.y + z*rhs.z; + } + + double cosBetween(const Vector3<T> &rhs) const { + return dot(rhs) / GetLength() / rhs.GetLength(); + } + + Vector3<double> normalize() { + auto length = GetLength(); + + return Vector3<double> ( + x / length, + y / length, + z / length + ); + } + Vector3 &operator=(Vector3 rhs) noexcept { rhs.swap(*this); return *this; @@ -68,6 +86,14 @@ struct Vector3 { ); } + Vector3 operator-() const { + return Vector3<T> ( + -x, + -y, + -z + ); + } + Vector3 operator*(const Vector3 &rhs) const { return Vector3<T>( x * rhs.x, |