#pragma once #include "vector2.h" #include template class Vector3 { public: Vector3() = default; Vector3(T x, T y, T z) : m_x(x), m_y(y), m_z(z) {} template Vector3(X x, Y y, Z z) : m_x(static_cast(x)), m_y(static_cast(y)), m_z(static_cast(z)) {} template Vector3(Vector2 xy, B z) : m_x(static_cast(xy[0])), m_y(static_cast(xy[1])), m_z(static_cast(z)) {} template Vector3(A x, Vector2 yz) : m_x(static_cast(x)), m_y(static_cast(yz[0])), m_z(static_cast(yz[1])) {} Vector3(const Vector3 &other) = default; template Vector3(const Vector3 &other) : m_x(static_cast(other[0])), m_y(static_cast(other[1])), m_z(static_cast(other[2])) {} T x() { return m_x; } T y() { return m_y; } T z() { return m_z; } void set_x(T x) { m_x = x; } void set_y(T y) { m_y = y; } void set_z(T z) { m_z = z; } void set(T x, T y, T z) { m_x = x; m_y = y; m_z = z; } Vector3 operator-() const { return Vector3(-m_x, -m_y, -m_z); } Vector3 &operator=(const Vector3 &other) { m_x = other.m_x; m_y = other.m_y; m_z = other.m_z; return *this; } Vector3 operator+(const Vector3 &other) const { return Vector3(m_x + other.m_x, m_y + other.m_y, m_z + other.m_z); } Vector3 &operator+=(const Vector3 &other) { m_x += other.m_x; m_y += other.m_y; m_z += other.m_z; return *this; } Vector3 operator-(const Vector3 &other) const { return Vector3(m_x - other.m_x, m_y - other.m_y, m_z - other.m_z); } Vector3 &operator-=(const Vector3 &other) { m_x -= other.m_x; m_y -= other.m_y; m_z -= other.m_z; return *this; } Vector3 operator*(const Vector3 &other) const { return Vector3(m_x * other.m_x, m_y * other.m_y, m_z * other.m_z); } Vector3 &operator*=(const Vector3 &other) { m_x *= other.m_x; m_y *= other.m_y; m_z *= other.m_z; return *this; } Vector3 operator*(const T &s) const { return Vector3(m_x * s, m_y * s, m_z * s); } Vector3 &operator*=(const T &s) { m_x *= s; m_y *= s; m_z *= s; return *this; } Vector3 operator/(const Vector3 &other) const { return Vector3(m_x / other.m_x, m_y / other.m_y, m_z / other.m_z); } Vector3 &operator/=(const Vector3 &other) { m_x /= other.m_x; m_y /= other.m_y; m_z /= other.m_z; return *this; } Vector3 operator/(const T &s) const { return Vector3(m_x / s, m_y / s, m_z / s); } Vector3 &operator/=(const T &s) { m_x /= s; m_y /= s; m_z /= s; return *this; } bool operator==(const Vector3 &other) const { return m_x == other.m_x && m_y == other.m_y && m_z == other.m_z; } bool operator!=(const Vector3 &other) const { return m_x == other.m_x || m_y != other.m_y || m_z != other.m_z; } T &operator[](const int idx) { switch(idx) { default: case 0: return m_x; case 1: return m_y; case 2: return m_z; } } const T &operator[](const int idx) const { switch(idx) { default: case 0: return m_x; case 1: return m_y; case 2: return m_z; } } friend std::ostream &operator<<(std::ostream &os, const Vector3 &vec) { os << "Vector3(" << vec.m_x << ", " << vec.m_y << ", " << vec.m_z << ")"; return os; } private: T m_x = 0; T m_y = 0; T m_z = 0; };