Dragonfly  4.3
A text-based game engine
Vector.h
1 ///
2 /// A 2d (x,y) vector
3 ///
4 
5 #ifndef __DF_VECTOR_H__
6 #define __DF_VECTOR_H__
7 
8 namespace df {
9 
10 class Vector {
11 
12  private:
13  float m_x; ///< Horizontal component.
14  float m_y; ///< Vertical component.
15 
16  public:
17 
18  /// Create Vector with (x,y).
19  Vector(float init_x, float init_y);
20 
21  /// Default is (0,0).
22  Vector();
23 
24  float getX() const; ///< Get horizontal component.
25  void setX(float new_x); ///< Set horizontal component.
26  float getY()const; ///< Get vertical component.
27  void setY(float new_y); ///< Set vertical component.
28  void setXY(float new_x, float new_y); ///< Set horizizontal & vertical.
29  void normalize(); ///< Normalize vector.
30  void scale(float s); ///< Scale vector.
31  float getMagnitude() const; ///< Return magnitude.
32  bool operator==(const Vector &other) const; ///< Compare Vector.
33  bool operator!=(const Vector &other) const; ///< Compare Vector.
34  Vector &operator+=(const Vector &other); ///< Add other Vector to this one.
35  Vector operator+(const Vector &other) const; ///< Add Vector.
36  Vector operator-(const Vector &other) const; ///< Subtract Vector.
37  bool operator!() const; ///< Test if (0,0).
38 };
39 
40 } // end of namespace df
41 #endif //__DF_VECTOR_H__
void normalize()
Normalize vector.
void scale(float s)
Scale vector.
Vector operator+(const Vector &other) const
Add Vector.
float m_x
Horizontal component.
Definition: Vector.h:13
float getX() const
Get horizontal component.
A 2-d bounding box.
Definition: Box.h:10
bool operator==(const Vector &other) const
Compare Vector.
bool operator!=(const Vector &other) const
Compare Vector.
void setY(float new_y)
Set vertical component.
float m_y
Vertical component.
Definition: Vector.h:14
Vector()
Default is (0,0).
float getY() const
Get vertical component.
void setX(float new_x)
Set horizontal component.
float getMagnitude() const
Return magnitude.
bool operator!() const
Test if (0,0).
Vector & operator+=(const Vector &other)
Add other Vector to this one.
Vector operator-(const Vector &other) const
Subtract Vector.
Definition: Vector.h:10
void setXY(float new_x, float new_y)
Set horizizontal & vertical.