|
#pragma once
#include <math.h>
namespace oag
{
class OAGVector2f
{
public:
OAGVector2f(void): m_X(0.f), m_Y(0.f) {};
OAGVector2f(const float &fx, const float &fy): m_X(fx), m_Y(fy) {};
OAGVector2f(const OAGVector2f& vec): m_X(vec.m_X), m_Y(vec.m_Y) {};
~OAGVector2f(void){};
//Attributes:
public:
float m_X, m_Y;
//Operations
public:
oag::OAGVector2f operator = (const oag::OAGVector2f& vec );
oag::OAGVector2f operator + (const oag::OAGVector2f& vec );
oag::OAGVector2f operator += (const oag::OAGVector2f& vec );
oag::OAGVector2f operator - (const oag::OAGVector2f& vec );
oag::OAGVector2f operator - ();
oag::OAGVector2f operator -= (const oag::OAGVector2f& vec );
oag::OAGVector2f operator * (const oag::OAGVector2f& vec );
oag::OAGVector2f operator * (const float& scalar );
oag::OAGVector2f operator *= (const float& scalar );
oag::OAGVector2f operator / (const oag::OAGVector2f& vec );
oag::OAGVector2f operator / (const float& num);
oag::OAGVector2f operator /= (const float& scalar );
float SquareLength();
float Length();
void Scalar( float scale );
void SetVertex(float x, float y);
void SetVertex(oag::OAGVector2f vec);
oag::OAGVector2f UnitVector();
//oag::OAGVector2f CrossProduct(oag::OAGVector2f& vec);
void Normalize();
float Angle(const oag::OAGVector2f& normal);
float VectorDot(const oag::OAGVector2f vec);
float* fv();
};
inline oag::OAGVector2f oag::OAGVector2f::operator =(const oag::OAGVector2f& vec)
{
m_X = vec.m_X; m_Y = vec.m_Y;
return *this;
}
inline oag::OAGVector2f oag::OAGVector2f::operator +(const oag::OAGVector2f& vec)
{
oag::OAGVector2f vector;
vector.m_X = ( m_X + vec.m_X ); vector.m_Y = ( m_Y + vec.m_Y );
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator +=(const oag::OAGVector2f& vec)
{
m_X += vec.m_X; m_Y += vec.m_Y;
return *this;
}
inline oag::OAGVector2f oag::OAGVector2f::operator -(const oag::OAGVector2f& vec)
{
oag::OAGVector2f vector;
vector.m_X = ( m_X - vec.m_X ); vector.m_Y = ( m_Y - vec.m_Y );
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator -()
{
oag::OAGVector2f vector(- m_X, -m_Y);
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator -=(const oag::OAGVector2f& vec)
{
m_X -= vec.m_X; m_Y -= vec.m_Y;
return *this;
}
inline oag::OAGVector2f oag::OAGVector2f::operator *(const oag::OAGVector2f& vec)
{
oag::OAGVector2f vector;
vector.m_X = ( m_X * vec.m_X ); vector.m_Y = ( m_Y * vec.m_Y );
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator *(const float& scalar)
{
oag::OAGVector2f vector;
vector.m_X = ( m_X * scalar ); vector.m_Y = ( m_Y * scalar );
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator *=(const float& scalar)
{
m_X *= scalar; m_Y *= scalar;
return *this;
}
inline oag::OAGVector2f oag::OAGVector2f::operator /(const oag::OAGVector2f& vec)
{
oag::OAGVector2f vector;
vector.m_X = ( m_X / vec.m_X ); vector.m_Y = ( m_Y / vec.m_Y );
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator/(const float& num)
{
oag::OAGVector2f vector;
vector.m_X = (m_X / num); vector.m_Y = (m_Y / num);
return vector;
}
inline oag::OAGVector2f oag::OAGVector2f::operator /=(const float& scalar)
{
const float recip = 1/scalar;
m_X *= recip; m_Y *= recip;
return *this;
}
inline float oag::OAGVector2f::SquareLength()
{
return ( ( m_X * m_X ) + ( m_Y * m_Y ) );
}
inline float oag::OAGVector2f::Length()
{
return sqrt( ( m_X * m_X ) + ( m_Y * m_Y ) );
}
inline void oag::OAGVector2f::Scalar(float scale)
{
m_X *= scale; m_Y *= scale;
}
inline void oag::OAGVector2f::SetVertex(float x, float y)
{
m_X = x;
m_Y = y;
}
inline void oag::OAGVector2f::SetVertex(oag::OAGVector2f vec)
{
m_X = vec.m_X;
m_Y = vec.m_Y;
}
inline oag::OAGVector2f oag::OAGVector2f::UnitVector()
{
oag::OAGVector2f vec;
vec = (*this) / Length();
return vec;
}
//inline oag::OAGVector2f oag::OAGVector2f::CrossProduct(oag::OAGVector2f& vec)
//{
// oag::OAGVector2f v;
// v.m_X = ( ( m_Y * vec.m_Z ) - ( m_Z * vec.m_Y ) );
// v.m_Y = ( ( m_Z * vec.m_X ) - ( m_X * vec.m_Z ) );
// v.m_Z = ( ( m_X * vec.m_Y ) - ( m_Y * vec.m_X ) );
// return vec;
//}
inline void oag::OAGVector2f::Normalize()
{
m_X /= Length();
m_Y /= Length();
}
inline float oag::OAGVector2f::Angle(const oag::OAGVector2f& normal)
{
return acosf( VectorDot(normal) );
}
inline float oag::OAGVector2f::VectorDot(const oag::OAGVector2f vec)
{
return ( m_X * vec.m_X ) + ( m_Y * vec.m_Y );
}
inline float VectorDot(const rgl::CVectorFloat& vec1, const rgl::CVectorFloat& vec2)
{
return ( vec1.m_X * vec2.m_X ) + ( vec1.m_Y * vec2.m_Y );
}
inline float* oag::OAGVector2f::fv()
{
static float values[2];
values[0] = m_X; values[1] = m_Y;
return values;
}
};
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I live in Matão, a small city in Brazil. I studied as Programmer in a College for Software Development in Database.
After finishing the College I have been working with java, c# and Computer Graphics with searches for OpenGL.