I've removed the top seven lines from both files as that contains identifying information
AmVector2.h:
Code:
#ifndef _AM_VECTOR_2_H
#define _AM_VECTOR_2_H
namespace AmberMaths
{
class AmVector2
{
public:
AmVector2();
AmVector2(float x, float y);
~AmVector2();
void Set(float x, float y);
AmVector2 AmVector2::operator+(AmVector2& rVec);
AmVector2 AmVector2::operator-(AmVector2& rVec);
void AmVector2::operator+=(AmVector2& rVec);
void AmVector2::operator-=(AmVector2& rVec);
AmVector2 AmVector2::operator*(float fVal);
void AmVector2::operator*=(float fVal);
void Normalise();
float GetLength();
float GetX() { return x; }
float GetY() { return y; }
private:
float x;
float y;
};
}
#endif //_AM_VECTOR_2_H
AmVector2.cpp:
Code:
#include "AmberMaths.h"
#include "AmVector2.h"
using namespace AmberMaths;
AmVector2::AmVector2()
{
Set(0.0f, 0.0f);
}
AmVector2::AmVector2(float x, float y)
{
Set(x, y);
}
AmVector2::~AmVector2()
{
}
void AmVector2::Set(float x, float y)
{
this->x = x;
this->y = y;
}
AmVector2 AmVector2::operator+(AmberMaths::AmVector2 &rVec)
{
AmVector2 vec;
vec.Set(x + rVec.x, y + rVec.y);
return vec;
}
AmVector2 AmVector2::operator-(AmberMaths::AmVector2 &rVec)
{
AmVector2 vec;
vec.Set(x - rVec.x, y - rVec.y);
return vec;
}
void AmVector2::operator+=(AmberMaths::AmVector2 &rVec)
{
Set(x + rVec.x, y + rVec.y);
}
void AmVector2::operator-=(AmberMaths::AmVector2 &rVec)
{
Set(x - rVec.x, y - rVec.y);
}
AmVector2 AmVector2::operator*(float fVal)
{
AmVector2 vec;
vec.Set(x * fVal, y * fVal);
return vec;
}
void AmVector2::operator*=(float fVal)
{
Set(x * fVal, y * fVal);
}
void AmVector2::Normalise()
{
float fLength = GetLength();
x /= fLength;
y /= fLength;
}
float AmVector2::GetLength()
{
return sqrt((x*x) + (y*y));
}
Originally Posted by
kmdv
Try:
Code:
AmVector2 operator+(AmVector2& rVec);
Actually, yeah. Makes sense. There was absolutely no requirement to have AmVector2:: on any of those. I wish I knew why I put that there. This is code I wrote years ago which I'm attempting to bring up to date