summaryrefslogtreecommitdiffstats
path: root/src/Vector.hpp
diff options
context:
space:
mode:
authorElisey Puzko <puzko.e02@gmail.com>2018-02-23 11:04:42 +0100
committerElisey Puzko <puzko.e02@gmail.com>2018-02-23 11:04:42 +0100
commit411acb1fbae60e5ee6feefd417632d6128dcf4ce (patch)
tree51fbd6ddbd517d6e3f22fcd7a4dd3284fd68307a /src/Vector.hpp
parentMouse capture fix (diff)
downloadAltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.tar
AltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.tar.gz
AltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.tar.bz2
AltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.tar.lz
AltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.tar.xz
AltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.tar.zst
AltCraft-411acb1fbae60e5ee6feefd417632d6128dcf4ce.zip
Diffstat (limited to '')
-rw-r--r--src/Vector.hpp236
1 files changed, 118 insertions, 118 deletions
diff --git a/src/Vector.hpp b/src/Vector.hpp
index aa79ef0..03b1ec4 100644
--- a/src/Vector.hpp
+++ b/src/Vector.hpp
@@ -7,134 +7,134 @@
template<class T>
struct Vector3 {
- T x, y, z;
+ T x, y, z;
- Vector3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
+ Vector3(T X = 0, T Y = 0, T Z = 0) : x(X), y(Y), z(Z) {}
- Vector3(const Vector3 &rhs) : x(rhs.x), y(rhs.y), z(rhs.z) {}
+ Vector3(const Vector3 &rhs) : x(rhs.x), y(rhs.y), z(rhs.z) {}
- ~Vector3() = default;
+ ~Vector3() = default;
- double GetLength() const { return std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); }
+ double GetLength() const { return std::sqrt(std::pow(x, 2) + std::pow(y, 2) + std::pow(z, 2)); }
- operator glm::vec3() const {
- return glm::vec3(x, y, z);
- }
+ operator glm::vec3() const {
+ return glm::vec3(x, y, z);
+ }
glm::vec3 glm() const {
return (glm::vec3)(*this);
}
- void swap(Vector3 &rhs) noexcept {
- std::swap(x, rhs.x);
- std::swap(y, rhs.y);
- 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;
- }
-
- Vector3 operator*(T rhs) const {
- return Vector3<T>(
- x * rhs,
- y * rhs,
- z * rhs
- );
- }
-
- Vector3 operator/(T rhs) const {
- return Vector3<T>(
- x / rhs,
- y / rhs,
- z / rhs
- );
- }
-
- Vector3 operator+(const Vector3 &rhs) const {
- return Vector3<T>(
- x + rhs.x,
- y + rhs.y,
- z + rhs.z
- );
- }
-
- Vector3 operator-(const Vector3 &rhs) const {
- return Vector3<T>(
- x - rhs.x,
- y - rhs.y,
- z - rhs.z
- );
- }
-
- Vector3 operator-() const {
- return Vector3<T> (
- -x,
- -y,
- -z
- );
- }
-
- Vector3 operator*(const Vector3 &rhs) const {
- return Vector3<T>(
- x * rhs.x,
- y * rhs.y,
- z * rhs.z
- );
- }
-
- Vector3 operator/(const Vector3 &rhs) const {
- return Vector3<T>(
- x / rhs.x,
- y / rhs.y,
- z / rhs.z
- );
- }
-
- bool operator==(const Vector3 &rhs) const {
- return (x == rhs.x && y == rhs.y && z == rhs.z);
- }
-
- bool operator!=(const Vector3 &rhs) const {
- return !(*this == rhs);
- }
-
- bool operator<(const Vector3 &rhs) const {
- if (x < rhs.x)
- return true;
- if (rhs.x < x)
- return false;
- if (y < rhs.y)
- return true;
- if (rhs.y < y)
- return false;
- return z < rhs.z;
- }
-
-
- friend std::ostream &operator<<(std::ostream &os, const Vector3 &vector3) {
- os << vector3.x << ", " << vector3.y << ", " << vector3.z;
- return os;
- }
+ void swap(Vector3 &rhs) noexcept {
+ std::swap(x, rhs.x);
+ std::swap(y, rhs.y);
+ 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;
+ }
+
+ Vector3 operator*(T rhs) const {
+ return Vector3<T>(
+ x * rhs,
+ y * rhs,
+ z * rhs
+ );
+ }
+
+ Vector3 operator/(T rhs) const {
+ return Vector3<T>(
+ x / rhs,
+ y / rhs,
+ z / rhs
+ );
+ }
+
+ Vector3 operator+(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x + rhs.x,
+ y + rhs.y,
+ z + rhs.z
+ );
+ }
+
+ Vector3 operator-(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x - rhs.x,
+ y - rhs.y,
+ z - rhs.z
+ );
+ }
+
+ Vector3 operator-() const {
+ return Vector3<T> (
+ -x,
+ -y,
+ -z
+ );
+ }
+
+ Vector3 operator*(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x * rhs.x,
+ y * rhs.y,
+ z * rhs.z
+ );
+ }
+
+ Vector3 operator/(const Vector3 &rhs) const {
+ return Vector3<T>(
+ x / rhs.x,
+ y / rhs.y,
+ z / rhs.z
+ );
+ }
+
+ bool operator==(const Vector3 &rhs) const {
+ return (x == rhs.x && y == rhs.y && z == rhs.z);
+ }
+
+ bool operator!=(const Vector3 &rhs) const {
+ return !(*this == rhs);
+ }
+
+ bool operator<(const Vector3 &rhs) const {
+ if (x < rhs.x)
+ return true;
+ if (rhs.x < x)
+ return false;
+ if (y < rhs.y)
+ return true;
+ if (rhs.y < y)
+ return false;
+ return z < rhs.z;
+ }
+
+
+ friend std::ostream &operator<<(std::ostream &os, const Vector3 &vector3) {
+ os << vector3.x << ", " << vector3.y << ", " << vector3.z;
+ return os;
+ }
};
using VectorF = Vector3<double>;