1
0
Fork 0
spectre/include/Spectre/Math/Vector4.h

162 lines
3.5 KiB
C++

#ifndef SPECTRE_MATH_VECTOR4_H
#define SPECTRE_MATH_VECTOR4_H
#include <iostream>
namespace sp {
template <typename T>
struct Vector4
{
union {
struct {
T x, y, z, w;
};
T v[4];
};
inline Vector4();
inline Vector4(T s);
inline Vector4(T x, T y, T z);
inline Vector4(T x, T y, T z, T w);
template <typename U>
inline Vector4(const Vector4<U>& vec);
// Named operations
inline float length() const;
inline Vector4<T>& normalize();
};
// ---------
// Compare
// ---------
template <typename T>
inline bool operator==(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline bool operator!=(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline bool operator<(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline bool operator<=(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline bool operator>(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline bool operator>=(const Vector4<T>& a, const Vector4<T>& b);
// ------------
// Arithmetic
// ------------
template <typename T>
inline Vector4<T> operator+(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T> operator-(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T> operator/(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T> operator*(const Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T>& operator+=(Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T>& operator-=(Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T>& operator/=(Vector4<T>& a, const Vector4<T>& b);
template <typename T>
inline Vector4<T>& operator*=(Vector4<T>& a, const Vector4<T>& b);
// -------------------
// Scalar Arithmetic
// -------------------
template <typename T>
inline Vector4<T> operator+(const Vector4<T>& v, T s);
template <typename T>
inline Vector4<T> operator+(T s, const Vector4<T>& v);
template <typename T>
inline Vector4<T> operator-(const Vector4<T>& v, T s);
template <typename T>
inline Vector4<T> operator-(T s, const Vector4<T>& v);
template <typename T>
inline Vector4<T> operator/(const Vector4<T>& v, T s);
template <typename T>
inline Vector4<T> operator/(T s, const Vector4<T>& v);
template <typename T>
inline Vector4<T> operator*(const Vector4<T>& v, T s);
template <typename T>
inline Vector4<T> operator*(T s, const Vector4<T>& v);
// ----------------
// Scalar compare
// ----------------
template <typename T>
inline bool operator<(const Vector4<T>& v, T s);
template <typename T>
inline bool operator<(T s, const Vector4<T>& v);
template <typename T>
inline bool operator<=(const Vector4<T>& v, T s);
template <typename T>
inline bool operator<=(T s, const Vector4<T>& v);
template <typename T>
inline bool operator>(const Vector4<T>& v, T s);
template <typename T>
inline bool operator>(T s, const Vector4<T>& v);
template <typename T>
inline bool operator>=(const Vector4<T>& v, T s);
template <typename T>
inline bool operator>=(T s, const Vector4<T>& v);
// Stream
template <typename T>
inline std::ostream& operator<<(std::ostream &s, const Vector4<T>& v);
typedef Vector4<float> Vector4f;
typedef Vector4<int> Vector4i;
typedef Vector4<unsigned> Vector4u;
typedef Vector4<unsigned char> Vector4b;
typedef Vector4<float> vec4f;
typedef Vector4<int> vec4i;
typedef Vector4<unsigned> vec4u;
typedef Vector4<unsigned char> vec4b;
} // namespace sp
#include "Vector4.inl"
#endif /* SPECTRE_MATH_VECTOR4_H */