From 01422022c33f064b3add3d935e1cdda7a621ac9c Mon Sep 17 00:00:00 2001 From: Akiko Date: Wed, 16 Oct 2013 12:44:07 +0200 Subject: [PATCH] - switched to correct member variable name scheme in the Vector and BaseObject class --- common/BaseObject.hxx | 50 ++--- engine/Vector.hxx | 530 +++++++++++++++++++++++++------------------------- 2 files changed, 286 insertions(+), 294 deletions(-) diff --git a/common/BaseObject.hxx b/common/BaseObject.hxx index aac6b25..01ec912 100644 --- a/common/BaseObject.hxx +++ b/common/BaseObject.hxx @@ -6,27 +6,32 @@ template class BaseObject { -private: +public: + // --- internal typedefs --- + using HRC = std::chrono::high_resolution_clock; using TP = std::chrono::time_point; - const TP _pcid; // parent class id - const TP _cid; // class id - const std::type_index _cidx; // unique identifier + // --- data structures --- + + const TP pcid; // parent class id + const TP cid; // class id + const std::type_index cindex; + + // --- constructors and deconstructors --- -public: BaseObject() - : _pcid(TP::duration::zero()), _cid(HRC::now()), _cidx(typeid (Class)) + : pcid(TP::duration::zero()), cid(HRC::now()), cindex(typeid (Class)) { } BaseObject(const BaseObject& rhs) - : _pcid(rhs._cid), _cid(HRC::now()), _cidx(rhs._cidx) + : pcid(rhs.cid), cid(HRC::now()), cidx(rhs.cindex) { } BaseObject(const BaseObject&& rhs) - : _pcid(std::move(rhs._pcid)), _cid(std::move(rhs._cid)), _cidx(rhs._cidx) + : pcid(std::move(rhs.pcid)), cid(std::move(rhs.cid)), cidx(std::move(rhs.cindex)) { } @@ -34,36 +39,23 @@ public: { } + // --- default operators --- + BaseObject& operator=(const BaseObject& rhs) { - _pcid = rhs._cid; - _cid = HRC::now(); - _cidx = rhs._cidx; + pcid = rhs.cid; + cid = HRC::now(); + cindex = rhs.cindex; return *this; } BaseObject& operator=(const BaseObject&& rhs) { - _pcid = std::move(rhs._pcid); - _cid = std::move(rhs._cid); - _cidx = std::move(rhs._cidx); + pcid = std::move(rhs.pcid); + cid = std::move(rhs.cid); + cindex = std::move(rhs.cindex); return *this; } - - size_t pcid() const - { - return _pcid; - } - - size_t cid() const - { - return _cid; - } - - std::type_index cindex() const - { - return _cidx; - } }; diff --git a/engine/Vector.hxx b/engine/Vector.hxx index e9b2731..e2c9193 100644 --- a/engine/Vector.hxx +++ b/engine/Vector.hxx @@ -29,46 +29,46 @@ public: union { struct { - MT X; - MT Y; + MT x; + MT y; }; - MT XY[2]; + MT xy[2]; } __attribute__((packed)); // --- constructors and deconstructors --- Vector2() - : XY{0, 0} + : xy{0, 0} { } Vector2(const MT& val) - : XY{val, val} + : xy{val, val} { } Vector2(const MT& x, const MT& y) - : XY{x, y} + : xy{x, y} { } Vector2(const Vector3& vec) - : XY{vec.X, vec.Y} + : xy{vec.x, vec.y} { } Vector2(const Vector4& vec) - : XY{vec.X, vec.Y} + : xy{vec.x, vec.y} { } Vector2(const Vector2& rhs) - : XY{rhs.X, rhs.Y} + : xy{rhs.x, rhs.y} { } Vector2(const Vector2&& rhs) - : XY{std::move(rhs.X), std::move(rhs.Y)} + : xy{std::move(rhs.x), std::move(rhs.y)} { } @@ -82,8 +82,8 @@ public: { if (this != &rhs) { - X = rhs.X; - Y = rhs.Y; + x = rhs.x; + y = rhs.y; } return *this; @@ -93,8 +93,8 @@ public: { if (this != &rhs) { - X = std::move(rhs.X); - Y = std::move(rhs.Y); + x = std::move(rhs.x); + y = std::move(rhs.y); } return *this; @@ -102,7 +102,7 @@ public: bool operator==(const Vector2& rhs) { - return X == rhs.X && Y == rhs.Y; + return x == rhs.x && y == rhs.y; } bool operator!=(const Vector2& rhs) @@ -112,33 +112,33 @@ public: const MT operator[](const size_t& index) const { - return XY[index]; + return xy[index]; } MT& operator[](const size_t& index) { - return XY[index]; + return xy[index]; } Vector2& operator~() { - X = -X; - Y = -Y; + x = -x; + y = -y; return *this; } Vector2 operator-() const { - return {-X, -Y}; + return {-x, -y}; } // --- other operators --- Vector2& operator+=(const Vector2& rhs) { - X += rhs.X; - Y += rhs.Y; + x += rhs.x; + y += rhs.y; return *this; } @@ -149,15 +149,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X += val; - Y += val; + x += val; + y += val; return *this; } Vector2 operator+(const Vector2& rhs) const { - return {X + rhs.X, Y + rhs.Y}; + return {x + rhs.x, y + rhs.y}; } template @@ -166,15 +166,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X + val, Y + val}; + return {x + val, y + val}; } // --- Vector2& operator-=(const Vector2& rhs) { - X -= rhs.X; - Y -= rhs.Y; + x -= rhs.x; + y -= rhs.y; return *this; } @@ -185,15 +185,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X -= val; - Y -= val; + x -= val; + y -= val; return *this; } Vector2 operator-(const Vector2& rhs) const { - return {X - rhs.X, Y - rhs.Y}; + return {x - rhs.x, y - rhs.y}; } template @@ -202,15 +202,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X - val, Y - val}; + return {x - val, y - val}; } // --- Vector2& operator*=(const Vector2& rhs) { - X *= rhs.X; - Y *= rhs.Y; + x *= rhs.x; + y *= rhs.y; return *this; } @@ -221,15 +221,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X *= val; - Y *= val; + x *= val; + y *= val; return *this; } Vector2 operator*(const Vector2& rhs) const { - return {X * rhs.X, Y * rhs.Y}; + return {x * rhs.x, y * rhs.y}; } template @@ -238,15 +238,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X * val, Y * val}; + return {x * val, y * val}; } // --- Vector2& operator/=(const Vector2& rhs) { - X /= rhs.X; - Y /= rhs.Y; + x /= rhs.x; + y /= rhs.y; return *this; } @@ -257,15 +257,15 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X /= val; - Y /= val; + x /= val; + y /= val; return *this; } Vector2 operator/(const Vector2& rhs) const { - return {X / rhs.X, Y / rhs.Y}; + return {x / rhs.x, y / rhs.y}; } template @@ -274,7 +274,7 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X / val, Y / val}; + return {x / val, y / val}; } // --- public methods --- @@ -304,79 +304,79 @@ public: MT dotProduct(const Vector2& vec) const { - return X * vec.X + Y * vec.Y; + return x * vec.x + y * vec.y; } bool isNull() const { - return X == 0 && Y == 0; + return x == 0 && y == 0; } MT length() const { - return std::sqrt(X * X + Y * Y); + return std::sqrt(x * x + y * y); } MT lengthSquared() const { - return X * X + Y * Y; + return x * x + y * y; } void normalize() { - *this /= std::sqrt(X * X + Y * Y); + *this /= std::sqrt(x * x + y * y); } Vector2 normalized() const { - const MT len = std::sqrt(X * X + Y * Y); + const MT len = std::sqrt(x * x + y * y); - return {X / len, Y / len}; + return {x / len, y / len}; } std::string string() const { std::stringstream result; - result << X << ", " << Y; + result << x << ", " << y; return result.str(); } Vector3 vector3() const { - return {X, Y, 0}; + return {x, y, 0}; } Vector4 vector4() const { - return {X, Y, 0, 0}; + return {x, y, 0, 0}; } // --- static methods --- static MT toDotProduct(const Vector2& vec1, const Vector2& vec2) { - return vec1.X * vec2.X + vec1.Y * vec2.Y; + return vec1.x * vec2.x + vec1.y * vec2.y; } static std::string toString(const Vector2& vec) { std::stringstream result; - result << vec.X << ", " << vec.Y; + result << vec.x << ", " << vec.y; return result.str(); } static Vector3 toVector3(const Vector2& vec) { - return {vec.X, vec.Y, 0}; + return {vec.x, vec.y, 0}; } static Vector4 toVector4(const Vector2& vec) { - return {vec.X, vec.Y, 0, 0}; + return {vec.x, vec.y, 0, 0}; } }; @@ -388,7 +388,7 @@ bool operator==(const Vector2& lhs, const Vector2& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return lhs.X == rhs.X && lhs.Y == rhs.Y; + return lhs.x == rhs.x && lhs.y == rhs.y; } template @@ -406,7 +406,7 @@ std::ostream& operator<<(std::ostream& lhs, const Vector2& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - lhs << rhs.X << rhs.Y; + lhs << rhs.x << rhs.y; return lhs; } @@ -417,7 +417,7 @@ std::istream& operator>>(std::istream& lhs, Vector2& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - lhs >> rhs.X >> rhs.Y; + lhs >> rhs.x >> rhs.y; return lhs; } @@ -430,7 +430,7 @@ Vector2 operator+(const Vector2& vec1, const Vector2& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X + vec2.X, vec1.Y + vec2.Y}; + return {vec1.x + vec2.x, vec1.y + vec2.y}; } template @@ -440,7 +440,7 @@ Vector2 operator+(const Vector2& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X + val, vec.Y + val}; + return {vec.x + val, vec.y + val}; } template @@ -450,7 +450,7 @@ Vector2 operator+(const Val& val, const Vector2& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val + vec.X, val + vec.Y}; + return {val + vec.x, val + vec.y}; } // --- @@ -461,7 +461,7 @@ Vector2 operator-(const Vector2& vec1, const Vector2& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X - vec2.X, vec1.Y - vec2.Y}; + return {vec1.x - vec2.x, vec1.y - vec2.y}; } template @@ -471,7 +471,7 @@ Vector2 operator-(const Vector2& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X - val, vec.Y - val}; + return {vec.x - val, vec.y - val}; } template @@ -481,7 +481,7 @@ Vector2 operator-(const Val& val, const Vector2& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val - vec.X, val - vec.Y}; + return {val - vec.x, val - vec.y}; } template @@ -490,7 +490,7 @@ Vector2 operator-(const Vector2& vec) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {-vec.X, -vec.Y}; + return {-vec.x, -vec.y}; } // --- @@ -501,7 +501,7 @@ Vector2 operator*(const Vector2& vec1, const Vector2& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X * vec2.X, vec1.Y * vec2.Y}; + return {vec1.x * vec2.x, vec1.y * vec2.y}; } template @@ -511,7 +511,7 @@ Vector2 operator*(const Vector2& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X * val, vec.Y * val}; + return {vec.x * val, vec.y * val}; } template @@ -521,7 +521,7 @@ Vector2 operator*(const Val& val, const Vector2& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val * vec.X, val + vec.Y}; + return {val * vec.x, val + vec.y}; } // --- @@ -532,7 +532,7 @@ Vector2 operator/(const Vector2& vec1, const Vector2& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X / vec2.X, vec1.Y / vec2.Y}; + return {vec1.x / vec2.x, vec1.y / vec2.y}; } template @@ -542,7 +542,7 @@ Vector2 operator/(const Vector2& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X / val, vec.Y / val}; + return {vec.x / val, vec.y / val}; } template @@ -552,7 +552,7 @@ Vector2 operator/(const Val& val, const Vector2 vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val / vec.X, val / vec.Y}; + return {val / vec.x, val / vec.y}; } // ****************************************************************************************************************** // @@ -566,52 +566,52 @@ public: union { struct { - MT X; - MT Y; - MT Z; + MT x; + MT y; + MT z; }; - MT XYZ[3]; + MT xyz[3]; } __attribute__((packed)); // --- constructors and deconstructors --- Vector3() - : XYZ{0, 0, 0} + : xyz{0, 0, 0} { } Vector3(const MT& val) - : XYZ{val, val, val} + : xyz{val, val, val} { } Vector3(const MT& x, const MT& y, const MT& z) - : XYZ{x, y, z} + : xyz{x, y, z} { } Vector3(const Vector2& vec) - : XYZ{vec.X, vec.Y, 0} + : xyz{vec.x, vec.y, 0} { } Vector3(const Vector2& vec, const MT& val) - : XYZ{vec.X, vec.Y, val} + : xyz{vec.x, vec.y, val} { } Vector3(const Vector4& vec) - : XYZ{vec.X, vec.Y, vec.Z} + : xyz{vec.x, vec.y, vec.z} { } Vector3(const Vector3& rhs) - : XYZ{rhs.X, rhs.Y, rhs.Z} + : xyz{rhs.x, rhs.y, rhs.z} { } Vector3(const Vector3&& rhs) - : XYZ{std::move(rhs.X), std::move(rhs.Y), std::move(rhs.Z)} + : xyz{std::move(rhs.x), std::move(rhs.y), std::move(rhs.z)} { } @@ -625,9 +625,9 @@ public: { if (this != &rhs) { - X = rhs.X; - Y = rhs.Y; - Z = rhs.Z; + x = rhs.x; + y = rhs.y; + z = rhs.z; } return *this; @@ -637,9 +637,9 @@ public: { if (this != &rhs) { - X = std::move(rhs.X); - Y = std::move(rhs.Y); - Z = std::move(rhs.Z); + x = std::move(rhs.x); + y = std::move(rhs.y); + z = std::move(rhs.z); } return *this; @@ -647,7 +647,7 @@ public: bool operator==(const Vector3& rhs) const { - return X == rhs.X && Y == rhs.Y && Z == rhs.Z; + return x == rhs.x && y == rhs.y && z == rhs.z; } bool operator!=(const Vector3& rhs) const @@ -657,35 +657,35 @@ public: const MT operator[](const size_t& index) const { - return XYZ[index]; + return xyz[index]; } MT& operator[](const size_t& index) { - return XYZ[index]; + return xyz[index]; } Vector3& operator~() { - X = -X; - Y = -Y; - Z = -Z; + x = -x; + y = -y; + z = -z; return *this; } Vector3 operator-() const { - return {-X, -Y, -Z}; + return {-x, -y, -z}; } // --- other operators --- Vector3& operator+=(const Vector3& rhs) { - X += rhs.X; - Y += rhs.Y; - Z += rhs.Z; + x += rhs.x; + y += rhs.y; + z += rhs.z; return *this; } @@ -696,16 +696,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X += val; - Y += val; - Z += val; + x += val; + y += val; + z += val; return *this; } Vector3 operator+(const Vector3& rhs) const { - return {X + rhs.X, Y + rhs.Y, Z + rhs.Z}; + return {x + rhs.x, y + rhs.y, z + rhs.z}; } template @@ -714,16 +714,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X + val, Y + val, Z + val}; + return {x + val, y + val, z + val}; } // --- Vector3& operator-=(const Vector3& rhs) { - X -= rhs.X; - Y -= rhs.Y; - Z -= rhs.Z; + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; return *this; } @@ -734,16 +734,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X -= val; - Y -= val; - Z -= val; + x -= val; + y -= val; + z -= val; return *this; } Vector3 operator-(const Vector3& rhs) const { - return {X - rhs.X, Y - rhs.Y, Z - rhs.Z}; + return {x - rhs.x, y - rhs.y, z - rhs.z}; } template @@ -752,16 +752,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X - val, Y - val, Z - val}; + return {x - val, y - val, z - val}; } // --- Vector3& operator*=(const Vector3& rhs) { - X *= rhs.X; - Y *= rhs.Y; - Z *= rhs.Z; + x *= rhs.x; + y *= rhs.y; + z *= rhs.z; return *this; } @@ -772,16 +772,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X *= val; - Y *= val; - Z *= val; + x *= val; + y *= val; + z *= val; return *this; } Vector3 operator*(const Vector3& rhs) const { - return {X * rhs.X, Y * rhs.Y, Z * rhs.Z}; + return {x * rhs.x, y * rhs.y, z * rhs.z}; } template @@ -790,16 +790,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X * val, Y * val, Z * val}; + return {x * val, y * val, z * val}; } // --- Vector3& operator/=(const Vector3& rhs) { - X /= rhs.X; - Y /= rhs.Y; - Z /= rhs.Z; + x /= rhs.x; + y /= rhs.y; + z /= rhs.z; return *this; } @@ -810,16 +810,16 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X /= val; - Y /= val; - Z /= val; + x /= val; + y /= val; + z /= val; return *this; } Vector3 operator/(const Vector3& rhs) const { - return {X / rhs.X, Y / rhs.Y, Z / rhs.Z}; + return {x / rhs.x, y / rhs.y, z / rhs.z}; } template @@ -828,14 +828,14 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X / val, Y / val, Z / val}; + return {x / val, y / val, z / val}; } // --- public methods --- Vector3 crossProduct(const Vector3& vec) const { - return {Y * vec.Z - Z * vec.Y, Z * vec.X - X * vec.Z, X * vec.Y - Y * vec.X}; + return {y * vec.z - z * vec.y, z * vec.x - x * vec.z, x * vec.y - y * vec.x}; } MT distanceToLine(const Vector3& origin, const Vector3& direction) const @@ -873,22 +873,22 @@ public: MT dotProduct(const Vector3& vec) const { - return X * vec.X + Y * vec.Y + Z * vec.Z; + return x * vec.x + y * vec.y + z * vec.z; } bool isNull() const { - return X == 0 && Y == 0 && Z == 0; + return x == 0 && y == 0 && z == 0; } MT length() const { - return std::sqrt(X * X + Y * Y + Z * Z); + return std::sqrt(x * x + y * y + z * z); } MT lengthSquared() const { - return X * X + Y * Y + Z * Z; + return x * x + y * y + z * z; } Vector3 normal(const Vector3& vec) const @@ -903,47 +903,47 @@ public: void normalize() { - *this /= std::sqrt(X * X + Y * Y + Z * Z); + *this /= std::sqrt(x * x + y * y + z * z); } Vector3 normalized() const { - const MT len = std::sqrt(X * X + Y * Y + Z * Z); + const MT len = std::sqrt(x * x + y * y + z * z); - return {X / len, Y / len, Z / len}; + return {x / len, y / len, z / len}; } std::string string() const { std::stringstream result; - result << X << ", " << Y << ", " << Z; + result << x << ", " << y << ", " << z; return result.str(); } Vector2 vector2() const { - return {X, Y}; + return {x, y}; } Vector4 vector4() const { - return {X, Y, Z, 0}; + return {x, y, z, 0}; } // --- static methods --- static Vector3 toCrossProduct(const Vector3& vec1, const Vector3& vec2) { - return {vec1.Y * vec2.Z - vec1.Z * vec2.Y, - vec1.Z * vec2.X - vec1.X * vec2.Z, - vec1.X * vec2.Y - vec1.Y * vec2.X}; + return {vec1.y * vec2.z - vec1.z * vec2.y, + vec1.z * vec2.x - vec1.x * vec2.z, + vec1.x * vec2.y - vec1.y * vec2.x}; } static MT toDotProduct(const Vector3& vec1, const Vector3& vec2) { - return vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z; + return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z; } static Vector3 toNormal(const Vector3& vec1, const Vector3& vec2) @@ -960,19 +960,19 @@ public: { std::stringstream result; - result << vec.X << ", " << vec.Y << ", " << vec.Z; + result << vec.x << ", " << vec.y << ", " << vec.z; return result.str(); } static Vector2 toVector2(const Vector3& vec) { - return {vec.X, vec.Y}; + return {vec.x, vec.y}; } static Vector4 toVector4(const Vector3& vec) { - return {vec.X, vec.Y, vec.Z, 0}; + return {vec.x, vec.y, vec.z, 0}; } }; @@ -984,7 +984,7 @@ bool operator==(const Vector3& lhs, const Vector3& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return lhs.X == rhs.X && lhs.Y == rhs.Y && lhs.Z == rhs.Z; + return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z; } template @@ -1002,7 +1002,7 @@ std::ostream& operator<<(std::ostream& lhs, const Vector3& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - lhs << rhs.X << rhs.Y << rhs.Z; + lhs << rhs.x << rhs.y << rhs.z; return lhs; } @@ -1013,7 +1013,7 @@ std::istream& operator>>(std::istream& lhs, Vector3& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - lhs >> rhs.X >> rhs.Y >> rhs.Z; + lhs >> rhs.x >> rhs.y >> rhs.z; return lhs; } @@ -1026,7 +1026,7 @@ Vector3 operator+(const Vector3& vec1, const Vector3& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X + vec2.X, vec1.Y + vec2.Y, vec1.Z + vec2.Z}; + return {vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z}; } template @@ -1036,7 +1036,7 @@ Vector3 operator+(const Vector3& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X + val, vec.Y + val, vec.Z + val}; + return {vec.x + val, vec.y + val, vec.z + val}; } template @@ -1046,7 +1046,7 @@ Vector3 operator+(const Val& val, const Vector3& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val + vec.X, val + vec.Y, val + vec.Z}; + return {val + vec.x, val + vec.y, val + vec.z}; } // --- @@ -1057,7 +1057,7 @@ Vector3 operator-(const Vector3& vec1, const Vector3& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X - vec2.X, vec1.Y - vec2.Y, vec1.Z - vec2.Z}; + return {vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z}; } template @@ -1067,7 +1067,7 @@ Vector3 operator-(const Vector3& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X - val, vec.Y - val, vec.Z - val}; + return {vec.x - val, vec.y - val, vec.z - val}; } template @@ -1077,7 +1077,7 @@ Vector3 operator-(const Val& val, const Vector3& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val - vec.X, val - vec.Y, val - vec.Z}; + return {val - vec.x, val - vec.y, val - vec.z}; } template @@ -1086,7 +1086,7 @@ Vector3 operator-(const Vector3& vec) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {-vec.X, -vec.Y, -vec.Z}; + return {-vec.x, -vec.y, -vec.z}; } // --- @@ -1097,7 +1097,7 @@ Vector3 operator*(const Vector3& vec1, const Vector3& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X * vec2.X, vec1.Y * vec2.Y, vec1.Z * vec2.Z}; + return {vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z}; } template @@ -1107,7 +1107,7 @@ Vector3 operator*(const Vector3& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X * val, vec.Y * val, vec.Z * val}; + return {vec.x * val, vec.y * val, vec.z * val}; } template @@ -1117,7 +1117,7 @@ Vector3 operator*(const Val& val, const Vector3& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val * vec.X, val + vec.Y, val * vec.Z}; + return {val * vec.x, val + vec.y, val * vec.z}; } // --- @@ -1128,7 +1128,7 @@ Vector3 operator/(const Vector3& vec1, const Vector3& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X / vec2.X, vec1.Y / vec2.Y, vec1.Z / vec2.Z}; + return {vec1.x / vec2.x, vec1.y / vec2.y, vec1.z / vec2.z}; } template @@ -1138,7 +1138,7 @@ Vector3 operator/(const Vector3& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X / val, vec.Y / val, vec.Z / val}; + return {vec.x / val, vec.y / val, vec.z / val}; } template @@ -1148,7 +1148,7 @@ Vector3 operator/(const Val& val, const Vector3 vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val / vec.X, val / vec.Y, val / vec.Z}; + return {val / vec.x, val / vec.y, val / vec.z}; } // ****************************************************************************************************************** // @@ -1162,63 +1162,63 @@ public: union { struct { - MT X; - MT Y; - MT Z; - MT W; + MT x; + MT y; + MT z; + MT w; }; - MT XYZW[4]; + MT xyzw[4]; } __attribute__((packed)); // --- constructors and deconstructors --- Vector4() - : XYZW{0, 0, 0, 0} + : xyzw{0, 0, 0, 0} { } Vector4(const MT& val) - : XYZW{val, val, val, val} + : xyzw{val, val, val, val} { } Vector4(const MT& x, const MT& y, const MT& z, const MT& w) - : XYZW{x, y, z, w} + : xyzw{x, y, z, w} { } Vector4(const Vector2& vec) - : XYZW{vec.X, vec.Y, 0, 0} + : xyzw{vec.x, vec.y, 0, 0} { } Vector4(const Vector2& vec, const MT& val1, const MT& val2) - : XYZW{vec.X, vec.Y, val1, val2} + : xyzw{vec.x, vec.y, val1, val2} { } Vector4(const Vector2& vec1, const Vector2& vec2) - : XYZW{vec1.X, vec1.Y, vec2.X, vec2.Y} + : xyzw{vec1.x, vec1.y, vec2.x, vec2.y} { } Vector4(const Vector3& vec) - : XYZW{vec.X, vec.Y, vec.Z, 0} + : xyzw{vec.x, vec.y, vec.z, 0} { } Vector4(const Vector3& vec, const MT& val) - : XYZW{vec.X, vec.Y, vec.Z, val} + : xyzw{vec.x, vec.y, vec.z, val} { } Vector4(const Vector4& rhs) - : XYZW{rhs.X, rhs.Y, rhs.Z, rhs.W} + : xyzw{rhs.x, rhs.y, rhs.z, rhs.w} { } Vector4(const Vector4&& rhs) - : XYZW{std::move(rhs.X), std::move(rhs.Y), std::move(rhs.Z), std::move(rhs.W)} + : xyzw{std::move(rhs.x), std::move(rhs.y), std::move(rhs.z), std::move(rhs.w)} { } @@ -1232,10 +1232,10 @@ public: { if (this != &rhs) { - X = rhs.X; - Y = rhs.Y; - Z = rhs.Z; - W = rhs.W; + x = rhs.x; + y = rhs.y; + z = rhs.z; + w = rhs.w; } return *this; @@ -1245,10 +1245,10 @@ public: { if (this != &rhs) { - X = std::move(rhs.X); - Y = std::move(rhs.Y); - Z = std::move(rhs.Z); - W = std::move(rhs.W); + x = std::move(rhs.x); + y = std::move(rhs.y); + z = std::move(rhs.z); + w = std::move(rhs.w); } return *this; @@ -1256,7 +1256,7 @@ public: bool operator==(const Vector4& rhs) const { - return X == rhs.X && Y == rhs.Y && Z == rhs.Z && W == rhs.W; + return x == rhs.x && y == rhs.y && z == rhs.z && w == rhs.w; } bool operator!=(const Vector4& rhs) const @@ -1266,36 +1266,36 @@ public: const MT operator[](const size_t& index) const { - return XYZW[index]; + return xyzw[index]; } MT& operator[](const size_t& index) { - return XYZW[index]; + return xyzw[index]; } Vector4& operator~() { - X = -X; - Y = -Y; - Z = -Z; - W = -W; + x = -x; + y = -y; + z = -z; + w = -w; return *this; } Vector4 operator-() const { - return {-X, -Y, -Z, -W}; + return {-x, -y, -z, -w}; } // --- other operators --- Vector4& operator+=(const Vector4& rhs) { - X += rhs.X; - Y += rhs.Y; - Z += rhs.Z; + x += rhs.x; + y += rhs.y; + z += rhs.z; return *this; } @@ -1306,17 +1306,17 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X += val; - Y += val; - Z += val; - W += val; + x += val; + y += val; + z += val; + w += val; return *this; } Vector4 operator+(const Vector4& rhs) const { - return {X + rhs.X, Y + rhs.Y, Z + rhs.Z, W + rhs.W}; + return {x + rhs.x, y + rhs.y, z + rhs.z, w + rhs.w}; } template @@ -1325,17 +1325,17 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X + val, Y + val, Z + val, W + val}; + return {x + val, y + val, z + val, w + val}; } // --- Vector4& operator-=(const Vector4& rhs) { - X -= rhs.X; - Y -= rhs.Y; - Z -= rhs.Z; - W -= rhs.W; + x -= rhs.x; + y -= rhs.y; + z -= rhs.z; + w -= rhs.w; return *this; } @@ -1346,17 +1346,17 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X -= val; - Y -= val; - Z -= val; - W -= val; + x -= val; + y -= val; + z -= val; + w -= val; return *this; } Vector4 operator-(const Vector4& rhs) const { - return {X - rhs.X, Y - rhs.Y, Z - rhs.Z, W - rhs.W}; + return {x - rhs.x, y - rhs.y, z - rhs.z, w - rhs.w}; } template @@ -1365,7 +1365,7 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X - val, Y - val, Z - val, W - val}; + return {x - val, y - val, z - val, w - val}; } @@ -1373,10 +1373,10 @@ public: Vector4& operator*=(const Vector4& rhs) { - X *= rhs.X; - Y *= rhs.Y; - Z *= rhs.Z; - W *= rhs.W; + x *= rhs.x; + y *= rhs.y; + z *= rhs.z; + w *= rhs.w; return *this; } @@ -1387,17 +1387,17 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X *= val; - Y *= val; - Z *= val; - W *= val; + x *= val; + y *= val; + z *= val; + w *= val; return *this; } Vector4 operator*(const Vector4& rhs) const { - return {X * rhs.X, Y * rhs.Y, Z * rhs.Z, W * rhs.W}; + return {x * rhs.x, y * rhs.y, z * rhs.z, w * rhs.w}; } template @@ -1406,17 +1406,17 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X * val, Y * val, Z * val, W * val}; + return {x * val, y * val, z * val, w * val}; } // --- Vector4& operator/=(const Vector4& rhs) { - X /= rhs.X; - Y /= rhs.Y; - Z /= rhs.Z; - W /= rhs.W; + x /= rhs.x; + y /= rhs.y; + z /= rhs.z; + w /= rhs.w; return *this; } @@ -1427,17 +1427,17 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - X /= val; - Y /= val; - Z /= val; - W /= val; + x /= val; + y /= val; + z /= val; + w /= val; return *this; } Vector4 operator/(const Vector4& rhs) const { - return {X / rhs.X, Y / rhs.Y, Z / rhs.Z, W / rhs.W}; + return {x / rhs.x, y / rhs.y, z / rhs.z, w / rhs.w}; } template @@ -1446,86 +1446,86 @@ public: static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {X / val, Y / val, Z / val, W / val}; + return {x / val, y / val, z / val, w / val}; } // --- public methods --- MT dotProduct(const Vector4& vec) const { - return X * vec.X + Y * vec.Y + Z * vec.Z + W * vec.W; + return x * vec.x + y * vec.y + z * vec.z + w * vec.w; } bool isNull() const { - return X == 0 && Y == 0 && Z == 0 && W == 0; + return x == 0 && y == 0 && z == 0 && w == 0; } MT length() const { - return std::sqrt(X * X + Y * Y + Z * Z + W * W); + return std::sqrt(x * x + y * y + z * z + w * w); } MT lengthSquared() const { - return X * X + Y * Y + Z * Z + W * W; + return x * x + y * y + z * z + w * w; } void normalize() { - *this /= std::sqrt(X * X + Y * Y + Z * Z + W * W); + *this /= std::sqrt(x * x + y * y + z * z + w * w); } Vector4 normalized() const { - const MT len = std::sqrt(X * X + Y * Y + Z * Z + W * W); + const MT len = std::sqrt(x * x + y * y + z * z + w * w); - return {X / len, Y / len, Z / len, W / len}; + return {x / len, y / len, z / len, w / len}; } std::string string() const { std::stringstream result; - result << X << ", " << Y << ", " << Z << ", " << W; + result << x << ", " << y << ", " << z << ", " << w; return result.str(); } Vector2 vector2() const { - return {X, Y}; + return {x, y}; } Vector3 vector3() const { - return {X, Y, Z}; + return {x, y, z}; } // --- static methods --- static MT toDotProduct(const Vector4& vec1, const Vector4& vec2) { - return vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z + vec1.W * vec2.W; + return vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z + vec1.w * vec2.w; } static std::string toString(const Vector4& vec) { std::stringstream result; - result << vec.X << ", " << vec.Y << ", " << vec.Z << ", " << vec.W; + result << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w; return result.str(); } static Vector2 toVector2(const Vector4& vec) { - return {vec.X, vec.Y}; + return {vec.x, vec.y}; } static Vector3 toVector3(const Vector4& vec) { - return {vec.X, vec.X, vec.Z}; + return {vec.x, vec.x, vec.z}; } }; @@ -1537,7 +1537,7 @@ bool operator==(const Vector4& lhs, const Vector4& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return lhs.X == rhs.X && lhs.Y == rhs.Y && lhs.Z == rhs.Z && lhs.W == rhs.W; + return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.w == rhs.w; } template @@ -1555,7 +1555,7 @@ std::ostream& operator<<(std::ostream& lhs, const Vector4& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - lhs << rhs.X << rhs.Y << rhs.Z << rhs.W; + lhs << rhs.x << rhs.y << rhs.z << rhs.w; return lhs; } @@ -1566,7 +1566,7 @@ std::istream& operator>>(std::istream& lhs, Vector4& rhs) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - lhs >> rhs.X >> rhs.Y >> rhs.Z >> rhs.W; + lhs >> rhs.x >> rhs.y >> rhs.z >> rhs.w; return lhs; } @@ -1579,7 +1579,7 @@ Vector4 operator+(const Vector4& vec1, const Vector4& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X + vec2.X, vec1.Y + vec2.Y, vec1.Z + vec2.Z, vec1.W + vec2.W}; + return {vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z, vec1.w + vec2.w}; } template @@ -1589,7 +1589,7 @@ Vector4 operator+(const Vector4& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X + val, vec.Y + val, vec.Z + val, vec.W + val}; + return {vec.x + val, vec.y + val, vec.z + val, vec.w + val}; } template @@ -1599,7 +1599,7 @@ Vector4 operator+(const Val& val, const Vector4& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val + vec.X, val + vec.Y, val + vec.Z, val + vec.W}; + return {val + vec.x, val + vec.y, val + vec.z, val + vec.w}; } // --- @@ -1610,7 +1610,7 @@ Vector4 operator-(const Vector4& vec1, const Vector4& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X - vec2.X, vec1.Y - vec2.Y, vec1.Z - vec2.Z, vec1.W - vec2.W}; + return {vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z, vec1.w - vec2.w}; } template @@ -1620,7 +1620,7 @@ Vector4 operator-(const Vector4& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X - val, vec.Y - val, vec.Z - val, vec.W - val}; + return {vec.x - val, vec.y - val, vec.z - val, vec.w - val}; } template @@ -1630,7 +1630,7 @@ Vector4 operator-(const Val& val, const Vector4& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val - vec.X, val - vec.Y, val - vec.Z, val - vec.W}; + return {val - vec.x, val - vec.y, val - vec.z, val - vec.w}; } template @@ -1639,7 +1639,7 @@ Vector4 operator-(const Vector4& vec) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {-vec.X, -vec.Y, -vec.Z, -vec.W}; + return {-vec.x, -vec.y, -vec.z, -vec.w}; } // --- @@ -1650,7 +1650,7 @@ Vector4 operator*(const Vector4& vec1, const Vector4& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X * vec2.X, vec1.Y * vec2.Y, vec1.Z * vec2.Z, vec1.W * vec2.W}; + return {vec1.x * vec2.x, vec1.y * vec2.y, vec1.z * vec2.z, vec1.w * vec2.w}; } template @@ -1660,7 +1660,7 @@ Vector4 operator*(const Vector4& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X * val, vec.Y * val, vec.Z * val, vec.W * val}; + return {vec.x * val, vec.y * val, vec.z * val, vec.w * val}; } template @@ -1670,7 +1670,7 @@ Vector4 operator*(const Val& val, const Vector4& vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val * vec.X, val + vec.Y, val * vec.Z, val * vec.W}; + return {val * vec.x, val + vec.y, val * vec.z, val * vec.w}; } // --- @@ -1681,7 +1681,7 @@ Vector4 operator/(const Vector4& vec1, const Vector4& vec2) static_assert (std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec1.X / vec2.X, vec1.Y / vec2.Y, vec1.Z / vec2.Z, vec1.W / vec2.W}; + return {vec1.x / vec2.x, vec1.y / vec2.y, vec1.z / vec2.z, vec1.w / vec2.w}; } template @@ -1691,7 +1691,7 @@ Vector4 operator/(const Vector4& vec, const Val& val) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {vec.X / val, vec.Y / val, vec.Z / val, vec.W / val}; + return {vec.x / val, vec.y / val, vec.z / val, vec.w / val}; } template @@ -1701,5 +1701,5 @@ Vector4 operator/(const Val& val, const Vector4 vec) std::is_integral::value || std::is_floating_point::value, "ERROR: template parameter is not an integral or floating point type"); - return {val / vec.X, val / vec.Y, val / vec.Z, val / vec.W}; + return {val / vec.x, val / vec.y, val / vec.z, val / vec.w}; } -- 2.15.1