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