| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #ifndef VEC2_H
- #define VEC2_H
- #include "Common.h"
- namespace M {
- /// 2D vector
- class Vec2
- {
- public:
- /// @name Constructors & distructors
- /// @{
- explicit Vec2();
- explicit Vec2(float x, float y);
- explicit Vec2(float f);
- explicit Vec2(float arr[]);
- Vec2(const Vec2& b);
- explicit Vec2(const Vec3& v3);
- explicit Vec2(const Vec4& v4);
- /// @}
- /// @name Accessors
- /// @{
- float& x();
- float x() const;
- float& y();
- float y() const;
- float& operator[](uint i);
- float operator[](uint i) const;
- /// @}
- /// @name Operators with same type
- /// @{
- Vec2& operator=(const Vec2& b);
- Vec2 operator+(const Vec2& b) const;
- Vec2& operator+=(const Vec2& b);
- Vec2 operator-(const Vec2& b) const;
- Vec2& operator-=(const Vec2& b);
- Vec2 operator*(const Vec2& b) const;
- Vec2& operator*=(const Vec2& b);
- Vec2 operator/(const Vec2& b) const;
- Vec2& operator/=(const Vec2& b);
- Vec2 operator-() const;
- bool operator==(const Vec2& b) const;
- bool operator!=(const Vec2& b) const;
- /// @}
- /// @name Operators with float
- /// @{
- Vec2 operator+(float f) const;
- Vec2& operator+=(float f);
- Vec2 operator-(float f) const;
- Vec2& operator-=(float f);
- Vec2 operator*(float f) const;
- Vec2& operator*=(float f);
- Vec2 operator/(float f) const;
- Vec2& operator/=(float f);
- /// @}
- /// @name Other
- /// @{
- float getLength() const;
- Vec2 getNormalized() const;
- void normalize();
- float dot(const Vec2& b) const;
- /// @}
- private:
- /// @name Data members
- /// @{
- union
- {
- struct
- {
- float x, y;
- } vec;
- boost::array<float, 2> arr;
- };
- /// @}
- };
- /// @name Other operators
- /// @{
- extern Vec2 operator+(float f, const Vec2& v2);
- extern Vec2 operator-(float f, const Vec2& v2);
- extern Vec2 operator*(float f, const Vec2& v2);
- extern Vec2 operator/(float f, const Vec2& v2);
- extern std::ostream& operator<<(std::ostream& s, const Vec2& v);
- /// @}
- } // end namespace
- #include "Vec2.inl.h"
- #endif
|