From ab8278e3b61e009253e34d13d6706da7702dbb6c Mon Sep 17 00:00:00 2001 From: Elisey Puzko Date: Fri, 23 Feb 2018 11:51:09 +0300 Subject: Bare-bones face detection for a block placement --- src/Vector.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/Vector.hpp') 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 &rhs) const { + return dot(rhs) / GetLength() / rhs.GetLength(); + } + + Vector3 normalize() { + auto length = GetLength(); + + return Vector3 ( + 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 ( + -x, + -y, + -z + ); + } + Vector3 operator*(const Vector3 &rhs) const { return Vector3( x * rhs.x, -- cgit v1.2.3