Dragonfly 4.20
A text-based game engine
Public Member Functions | Private Attributes | List of all members
df::Vector Class Reference

Public Member Functions

 Vector (float init_x, float init_y)
 
 Vector ()
 
float getX () const
 
void setX (float new_x)
 
float getY () const
 
void setY (float new_y)
 
void setXY (float new_x, float new_y)
 
void normalize ()
 
void scale (float s)
 
float getMagnitude () const
 
bool operator== (const Vector &other) const
 
bool operator!= (const Vector &other) const
 
Vectoroperator+= (const Vector &other)
 
Vector operator+ (const Vector &other) const
 
Vector operator- (const Vector &other) const
 
bool operator! () const
 
std::string toString () const
 
int serialize (std::stringstream *p_ss) const
 
int deserialize (std::stringstream *p_ss)
 

Private Attributes

float m_x
 
float m_y
 

Constructor & Destructor Documentation

◆ Vector() [1/2]

df::Vector::Vector ( float  init_x,
float  init_y 
)

Create Vector with (x,y).

◆ Vector() [2/2]

df::Vector::Vector ( )

Default is (0,0).

Member Function Documentation

◆ deserialize()

int df::Vector::deserialize ( std::stringstream *  p_ss)

Deserialize attributes from stream.

Return 0 if ok, else -1.

◆ getMagnitude()

float df::Vector::getMagnitude ( ) const

Return magnitude.

◆ getX()

float df::Vector::getX ( ) const

Get horizontal component.

◆ getY()

float df::Vector::getY ( ) const

Get vertical component.

◆ normalize()

void df::Vector::normalize ( )

Normalize vector.

◆ operator!()

bool df::Vector::operator! ( ) const

Test if (0,0).

◆ operator!=()

bool df::Vector::operator!= ( const Vector other) const

Compare Vector.

◆ operator+()

Vector df::Vector::operator+ ( const Vector other) const

Add Vector.

◆ operator+=()

Vector & df::Vector::operator+= ( const Vector other)

Add other Vector to this one.

◆ operator-()

Vector df::Vector::operator- ( const Vector other) const

Subtract Vector.

◆ operator==()

bool df::Vector::operator== ( const Vector other) const

Compare Vector.

◆ scale()

void df::Vector::scale ( float  s)

Scale vector.

◆ serialize()

int df::Vector::serialize ( std::stringstream *  p_ss) const

Serialize attributes to stream.

Return 0 if ok, else -1.

◆ setX()

void df::Vector::setX ( float  new_x)

Set horizontal component.

◆ setXY()

void df::Vector::setXY ( float  new_x,
float  new_y 
)

Set horizizontal & vertical.

◆ setY()

void df::Vector::setY ( float  new_y)

Set vertical component.

◆ toString()

std::string df::Vector::toString ( ) const

Return attributes as string.

Member Data Documentation

◆ m_x

float df::Vector::m_x
private

Horizontal component.

◆ m_y

float df::Vector::m_y
private

Vertical component.