Dragonfly 4.20
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 /// Serialize attributes to stream.
43 /// Return 0 if ok, else -1.
44 int serialize(std::stringstream *p_ss) const;
45
46 /// Deserialize attributes from stream.
47 /// Return 0 if ok, else -1.
48 int deserialize(std::stringstream *p_ss);
49};
50
51} // end of namespace df
52#endif //__VECTOR_H__
Definition: Vector.h:12
int serialize(std::stringstream *p_ss) const
Serialize attributes to stream.
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).
int deserialize(std::stringstream *p_ss)
Deserialize attributes from stream.
void normalize()
Normalize vector.
Vector operator+(const Vector &other) const
Add Vector.
An animation for a sprite.
Definition: Animation.h:15