#ifndef SPECTRE_MATH_VECTOR3_H #define SPECTRE_MATH_VECTOR3_H #include "Vector2.h" #include namespace sp { template struct Vector3 { union { struct { T x, y, z; }; T v[3]; }; inline Vector3(); inline Vector3(T s); inline Vector3(T x, T y); inline Vector3(T x, T y, T z); template inline Vector3(const Vector3& vec); template inline Vector3(const Vector2& vec); // ----------------- // Named operations. // ----------------- inline float len() const; inline Vector3& normal(); inline Vector2 toVec2(); }; // --------- // Compare // --------- template inline bool operator==(const Vector3& a, const Vector3& b); template inline bool operator!=(const Vector3& a, const Vector3& b); template inline bool operator<(const Vector3& a, const Vector3& b); template inline bool operator<=(const Vector3& a, const Vector3& b); template inline bool operator>(const Vector3& a, const Vector3& b); template inline bool operator>=(const Vector3& a, const Vector3& b); // ------------ // Arithmetic // ------------ template inline Vector3 operator+(const Vector3& a, const Vector3& b); template inline Vector3 operator-(const Vector3& a, const Vector3& b); template inline Vector3 operator/(const Vector3& a, const Vector3& b); template inline Vector3 operator*(const Vector3& a, const Vector3& b); template inline Vector3& operator+=(Vector3& a, const Vector3& b); template inline Vector3& operator-=(Vector3& a, const Vector3& b); template inline Vector3& operator/=(Vector3& a, const Vector3& b); template inline Vector3& operator*=(Vector3& a, const Vector3& b); // ------------------- // Scalar Arithmetic // ------------------- template inline Vector3 operator+(const Vector3& v, T s); template inline Vector3 operator+(T s, const Vector3& v); template inline Vector3 operator-(const Vector3& v, T s); template inline Vector3 operator-(T s, const Vector3& v); template inline Vector3 operator/(const Vector3& v, T s); template inline Vector3 operator/(T s, const Vector3& v); template inline Vector3 operator*(const Vector3& v, T s); template inline Vector3 operator*(T s, const Vector3& v); // ---------------- // Scalar compare // ---------------- template inline bool operator<(const Vector3& v, T s); template inline bool operator<(T s, const Vector3& v); template inline bool operator<=(const Vector3& v, T s); template inline bool operator<=(T s, const Vector3& v); template inline bool operator>(const Vector3& v, T s); template inline bool operator>(T s, const Vector3& v); template inline bool operator>=(const Vector3& v, T s); template inline bool operator>=(T s, const Vector3& v); // ------------------- // Stream operations // ------------------- template inline std::ostream& operator<<(std::ostream &s, const Vector3& v); // ----------------------------- // Common specialization types // ----------------------------- typedef Vector3 Vector3f; typedef Vector3 Vector3i; typedef Vector3 Vector3u; typedef Vector3 Vector3b; typedef Vector3 vec3f; typedef Vector3 vec3i; typedef Vector3 vec3u; typedef Vector3 vec3b; } // namespace sp #include "Vector3.inl" #endif /* SPECTRE_MATH_VECTOR3_H */