2009년 11월 26일 목요일

vector2D

/********************************************************************
created: 2009/05/11
created: 11:5:2009   5:34
filename: c:\Documents and Settings\심지현\My Documents\Visual Studio 2005\Projects\DarkKnight\DarkKnight\vector2d.h
file path: c:\Documents and Settings\심지현\My Documents\Visual Studio 2005\Projects\DarkKnight\DarkKnight
file base: vector2d
file ext: h
author: JIHYUN SIM

purpose:
*********************************************************************/

#ifndef VECTOR2D_H
#define VECTOR2D_H

class VECTOR2D
{
public:
FLOAT x,y;
VECTOR2D():x(0),y(0){}
VECTOR2D(FLOAT x,FLOAT y)
{
this->x=x;
this->y=y;
}

const float GetMagnitude() const;
const float GetDistance(VECTOR2D& v) const;

VECTOR2D operator = (const VECTOR2D& v);
VECTOR2D operator = (const FLOAT& v);
VECTOR2D operator += (const VECTOR2D& v);
VECTOR2D operator -= (const VECTOR2D& v);
VECTOR2D operator *= (const VECTOR2D& v);
VECTOR2D operator *= (const float f);
VECTOR2D operator /= (const VECTOR2D& v);
VECTOR2D operator /= (const float f);

bool operator == (const VECTOR2D& v) const;
bool operator != (const VECTOR2D& v) const;

protected:
private:
};

inline const float VECTOR2D::GetMagnitude() const {
return static_cast(sqrt(x*x + y*y));
}

inline const float VECTOR2D::GetDistance(VECTOR2D& v) const {
VECTOR2D tmp = *this;
tmp -= v;
return tmp.GetMagnitude();
}




inline VECTOR2D VECTOR2D::operator = (const VECTOR2D& v) {
x = v.x; y = v.y;
return *this;
}

inline VECTOR2D VECTOR2D::operator = (const FLOAT& v) {
x = v; y = v;
return *this;
}
inline VECTOR2D VECTOR2D::operator += (const VECTOR2D& v) {
x += v.x; y += v.y;
return *this;
}
inline VECTOR2D VECTOR2D::operator -= (const VECTOR2D& v) {
x -= v.x; y -= v.y;
return *this;
}
inline VECTOR2D VECTOR2D::operator *= (const VECTOR2D& v) {
x *= v.x; y *= v.y;
return *this;
}
inline VECTOR2D VECTOR2D::operator *= (const float f) {
x *= f; y *= f;
return *this;
}
inline VECTOR2D VECTOR2D::operator /= (const VECTOR2D& v) {
x /= v.x; y /= v.y;
return *this;
}
inline VECTOR2D VECTOR2D::operator /= (const float f) {
x /= f; y /= f;
return *this;
}

inline bool VECTOR2D::operator == (const VECTOR2D& v) const {
if(x != v.x) {
return false;
} else {
return y == v.y;
}
}
inline bool VECTOR2D::operator != (const VECTOR2D& v) const {
if(x != v.x) {
return true;
} else {
return y != v.y;
}
}

#endif

댓글 없음:

댓글 쓰기