#include #include "Vector4.h" namespace sp { template Vector4::Vector4() { x = y = z = w = T(0); } template Vector4::Vector4(T s) { x = y = z = w = s; } template Vector4::Vector4(T _x, T _y, T _z) { x = _x; y = _y; z = _z; w = T(1); } template Vector4::Vector4(T _x, T _y, T _z, T _w) { x = _x; y = _y; z = _z; w = _w; } template template Vector4::Vector4(const Vector4& vec) { x = T(vec.x); y = T(vec.y); z = T(vec.z); w = T(vec.w); } template float Vector4::length() const { return std::sqrt((x * x) + (y * y) + (z * z) + (w * w)); } template Vector4& Vector4::normalize() { float il = 1.0f / length(); x *= il; y *= il; z *= il; w *= il; return *this; } // --------- // Compare // --------- template bool operator==(const Vector4& a, const Vector4& b) { return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w; } template bool operator!=(const Vector4& a, const Vector4& b) { return !(a == b); } template bool operator<(const Vector4& a, const Vector4& b) { return a.x < b.x && a.y < b.y && a.z < b.z && a.w < b.w; } template bool operator<=(const Vector4& a, const Vector4& b) { return !(a > b); } template bool operator>(const Vector4& a, const Vector4& b) { return a.x > b.x && a.y > b.y && a.z > b.z && a.w > b.w; } template bool operator>=(const Vector4& a, const Vector4& b) { return !(a < b); } // ------------ // Arithmetic // ------------ template inline Vector4 operator+(const Vector4& a, const Vector4& b) { return Vector4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); } template inline Vector4 operator-(const Vector4& a, const Vector4& b) { return Vector4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w); } template inline Vector4 operator/(const Vector4& a, const Vector4& b) { return Vector4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w); } template inline Vector4 operator*(const Vector4& a, const Vector4& b) { return Vector4(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w); } template inline Vector4& operator+=(Vector4& a, const Vector4& b) { a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w; return a; } template inline Vector4& operator-=(Vector4& a, const Vector4& b) { a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w; return a; } template inline Vector4& operator/=(Vector4& a, const Vector4& b) { a.x /= b.x; a.y /= b.y; a.z /= b.z; a.w /= b.w; return a; } template inline Vector4& operator*=(Vector4& a, const Vector4& b) { a.x *= b.x; a.y *= b.y; a.z *= b.z; a.w *= b.w; return a; } // ------------------- // Scalar Arithmetic // ------------------- template inline Vector4 operator+(const Vector4& v, T s) { return Vector4(v.x + s, v.y + s, v.z + s, v.w + s); } template inline Vector4 operator+(T s, const Vector4& v) { return v + s; } template inline Vector4 operator-(const Vector4& v, T s) { return Vector4(v.x - s, v.y - s, v.z - s, v.w - s); } template inline Vector4 operator-(T s, const Vector4& v) { return Vector4(s - v.x, s - v.y, s - v.z, s - v.w); } template inline Vector4 operator/(const Vector4& v, T s) { return Vector4(v.x / s, v.y / s, v.z / s, v.w / s); } template inline Vector4 operator/(T s, const Vector4& v) { return Vector4(s / v.x, s / v.y, s / v.z, s / v.w); } template inline Vector4 operator*(const Vector4& v, T s) { return Vector4(v.x * s, v.y * s, v.z * s, v.w * s); } template inline Vector4 operator*(T s, const Vector4& v) { return v * s; } // ---------------- // Scalar compare // ---------------- template inline bool operator<(const Vector4& v, T s) { return v.x < s && v.y < s && v.z < s && v.w < s; } template inline bool operator<(T s, const Vector4& v) { return s < v.x && s < v.y && s < v.z && s < v.w; } template inline bool operator<=(const Vector4& v, T s) { return v.x <= s && v.y <= s && v.z <= s && v.w <= s; } template inline bool operator<=(T s, const Vector4& v) { return s <= v.x && s <= v.y && s <= v.z && s <= v.w; } template inline bool operator>(const Vector4& v, T s) { return v.x > s && v.y > s && v.z > s && v.w > s; } template inline bool operator>(T s, const Vector4& v) { return s > v.x && s > v.y && s > v.z && s > v.w; } template inline bool operator>=(const Vector4& v, T s) { return v.x >= s && v.y >= s && v.z >= s && v.w >= s; } template inline bool operator>=(T s, const Vector4& v) { return s >= v.x && s >= v.y && s >= v.z && s >= v.w; } template inline std::ostream& operator<<(std::ostream &s, const Vector4& v) { return s << "(" << v.x << "," << v.y << "," << v.z << "," << v.w << ")"; } } // namespace sp