first commit
This commit is contained in:
122
src/game/Vector2D.cpp
Normal file
122
src/game/Vector2D.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Vector2D.cpp
|
||||
*
|
||||
* Created on: Mar 1, 2020
|
||||
* Author: ayoungblood
|
||||
*/
|
||||
|
||||
#include "Vector2D.h"
|
||||
|
||||
Vector2D::Vector2D()
|
||||
{
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
r = 0.0f;
|
||||
t = 0.0f;
|
||||
}
|
||||
|
||||
Vector2D::Vector2D(float x, float y)
|
||||
{
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->r = sqrt(pow(x,2.0)+pow(y,2.0));
|
||||
this->t = atan(y/x);
|
||||
}
|
||||
|
||||
Vector2D::Vector2D(float r, float t, bool isPolar)
|
||||
{
|
||||
this->x = r*(cos(t));
|
||||
this->y = r*(sin(t));
|
||||
this->r = r;
|
||||
this->t = t;
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::Add(const Vector2D& vec)
|
||||
{
|
||||
this->x += vec.x;
|
||||
this->y += vec.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::Subtract(const Vector2D& vec)
|
||||
{
|
||||
this->x -= vec.x;
|
||||
this->y -= vec.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::Multiply(const Vector2D& vec)
|
||||
{
|
||||
this->x *= vec.x;
|
||||
this->y *= vec.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::Divide(const Vector2D& vec)
|
||||
{
|
||||
this->x /= vec.x;
|
||||
this->y /= vec.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2D& operator+(Vector2D& v1, const Vector2D& v2)
|
||||
{
|
||||
return v1.Add(v2);
|
||||
}
|
||||
|
||||
Vector2D& operator-(Vector2D& v1, const Vector2D& v2)
|
||||
{
|
||||
return v1.Subtract(v2);
|
||||
}
|
||||
|
||||
Vector2D& operator*(Vector2D& v1, const Vector2D& v2)
|
||||
{
|
||||
return v1.Multiply(v2);
|
||||
}
|
||||
|
||||
Vector2D& operator/(Vector2D& v1, const Vector2D& v2)
|
||||
{
|
||||
return v1.Divide(v2);
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::operator +=(const Vector2D& vec)
|
||||
{
|
||||
return this->Add(vec);
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::operator -=(const Vector2D& vec)
|
||||
{
|
||||
return this->Subtract(vec);
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::operator *=(const Vector2D& vec)
|
||||
{
|
||||
return this->Multiply(vec);
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::operator /=(const Vector2D& vec)
|
||||
{
|
||||
return this->Divide(vec);
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::operator *(const int& i)
|
||||
{
|
||||
this->x *= i;
|
||||
this->y *= i;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vector2D& Vector2D::Zero()
|
||||
{
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Vector2D& vec)
|
||||
{
|
||||
stream << "(" << vec.x << "," << vec.y << ")";
|
||||
return stream;
|
||||
}
|
Reference in New Issue
Block a user