Vec4.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef VEC4_H
  2. #define VEC4_H
  3. #include "Common.h"
  4. namespace M {
  5. /// 4D vector
  6. class Vec4
  7. {
  8. public:
  9. /// @name Constructors
  10. /// @{
  11. explicit Vec4();
  12. explicit Vec4(float x, float y, float z, float w);
  13. explicit Vec4(float f);
  14. explicit Vec4(float arr[]);
  15. explicit Vec4(const Vec2& v2, float z, float w);
  16. explicit Vec4(const Vec3& v3, float w);
  17. Vec4(const Vec4& b);
  18. explicit Vec4(const Quat& q);
  19. #if defined(MATH_INTEL_SIMD)
  20. explicit Vec4(const __m128& mm);
  21. #endif
  22. /// @}
  23. /// @name Accessors
  24. /// @{
  25. float& x();
  26. float x() const;
  27. float& y();
  28. float y() const;
  29. float& z();
  30. float z() const;
  31. float& w();
  32. float w() const;
  33. float& operator[](uint i);
  34. float operator[](uint i) const;
  35. #if defined(MATH_INTEL_SIMD)
  36. __m128& getMm();
  37. const __m128& getMm() const;
  38. #endif
  39. /// @}
  40. /// @name Operators with same
  41. /// @{
  42. Vec4& operator=(const Vec4& b);
  43. Vec4 operator+(const Vec4& b) const;
  44. Vec4& operator+=(const Vec4& b);
  45. Vec4 operator-(const Vec4& b) const;
  46. Vec4& operator-=(const Vec4& b);
  47. Vec4 operator*(const Vec4& b) const;
  48. Vec4& operator*=(const Vec4& b);
  49. Vec4 operator/(const Vec4& b) const;
  50. Vec4& operator/=(const Vec4& b);
  51. Vec4 operator-() const;
  52. bool operator==(const Vec4& b) const;
  53. bool operator!=(const Vec4& b) const;
  54. /// @}
  55. /// @name Operators with float
  56. /// @{
  57. Vec4 operator+(float f) const;
  58. Vec4& operator+=(float f);
  59. Vec4 operator-(float f) const;
  60. Vec4& operator-=(float f);
  61. Vec4 operator*(float f) const;
  62. Vec4& operator*=(float f);
  63. Vec4 operator/(float f) const;
  64. Vec4& operator/=(float f);
  65. /// @}
  66. /// @name Operators with other
  67. /// @{
  68. Vec4 operator*(const Mat4& m4) const;
  69. /// @}
  70. /// @name Misc methods
  71. /// @{
  72. float getLength() const;
  73. Vec4 getNormalized() const;
  74. void normalize();
  75. float dot(const Vec4& b) const;
  76. /// @}
  77. private:
  78. /// @name Data
  79. /// @{
  80. union
  81. {
  82. struct
  83. {
  84. float x, y, z, w;
  85. } vec;
  86. boost::array<float, 4> arr;
  87. #if defined(MATH_INTEL_SIMD)
  88. __m128 mm;
  89. #endif
  90. };
  91. /// @}
  92. };
  93. /// @name Global operators with Vec4 and float
  94. /// @{
  95. extern Vec4 operator+(float f, const Vec4& v4);
  96. extern Vec4 operator-(float f, const Vec4& v4);
  97. extern Vec4 operator*(float f, const Vec4& v4);
  98. extern Vec4 operator/(float f, const Vec4& v4);
  99. /// @}
  100. extern std::ostream& operator<<(std::ostream& s, const Vec4& v);
  101. } // end namespace
  102. #include "Vec4.inl.h"
  103. #endif