블로그는 나의 힘!
[ Programing ]/C++2010. 1. 31. 07:04
/* 
  OpenGL 사용할 때 VECTOR 관련 구조체가 없었다. 아무래도 OpenGL은 3D를 만들기 위한 프로그램이 아니고, 3D 제작을 지원하는 유틸리티 관련 툴이라 그런지 Render 부분 외엔 많이 미흡하다. 그 대표적으로 DirtectX에서 흔히 볼 수 있는 VECTOR도 보이지 않는다. 그래서 심심풀이로 하나 만들어 봤다.
*/

struct VECTOR
{
float fPosX, fPosY, fPosZ;

VECTOR() : fPosX( 0.0f ), fPosY( 0.0f ), fPosZ( 0.0f )
{}

VECTOR( const VECTOR& rhsVector )
{
this->fPosX = rhsVector.fPosX;
this->fPosY = rhsVector.fPosY;
this->fPosZ = rhsVector.fPosZ;
}

VECTOR( float x, float y, float z )
{
this->fPosX = x;
this->fPosY = y;
this->fPosZ = z;
}

VECTOR &operator+=( const VECTOR& rhsVector )
{
this->fPosX = this->fPosX +rhsVector.fPosX;
this->fPosY = this->fPosY +rhsVector.fPosY;
this->fPosZ = this->fPosZ +rhsVector.fPosZ;

return *this;
} // >>> END operator+=

VECTOR &operator-=( const VECTOR& rhsVector )
{
this->fPosX = this->fPosX -rhsVector.fPosX;
this->fPosY = this->fPosY -rhsVector.fPosY;
this->fPosZ = this->fPosZ -rhsVector.fPosZ;

return *this;
} // >>> END operator-=

VECTOR &operator*=( const VECTOR& rhsVector )
{
this->fPosX = this->fPosX *rhsVector.fPosX;
this->fPosY = this->fPosY *rhsVector.fPosY;
this->fPosZ = this->fPosZ *rhsVector.fPosZ;

return *this;
} // >>> END operator*=

VECTOR &operator/=( const VECTOR& rhsVector )
{
this->fPosX = this->fPosX /rhsVector.fPosX;
this->fPosY = this->fPosY /rhsVector.fPosY;
this->fPosZ = this->fPosZ /rhsVector.fPosZ;

return *this;
} // >>> END operator/=

VECTOR &operator=( const VECTOR& rhsVector )
{
this->fPosX = rhsVector.fPosX;
this->fPosY = rhsVector.fPosY;
this->fPosZ = rhsVector.fPosZ;

return *this;
} // >>> END operator=

VECTOR operator-( const VECTOR& rhsVector )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX -rhsVector.fPosX;
vTemp.fPosY = this->fPosY -rhsVector.fPosY;
vTemp.fPosZ = this->fPosZ -rhsVector.fPosZ;

return vTemp;
} // >>> END operator-

VECTOR operator+( const VECTOR& rhsVector )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX +rhsVector.fPosX;
vTemp.fPosY = this->fPosY +rhsVector.fPosY;
vTemp.fPosZ = this->fPosZ +rhsVector.fPosZ;

return vTemp;
} // >>> END operator+

VECTOR operator*( const VECTOR& rhsVector )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX *rhsVector.fPosX;
vTemp.fPosY = this->fPosY *rhsVector.fPosY;
vTemp.fPosZ = this->fPosZ *rhsVector.fPosZ;

return vTemp;
} // >>> END operator*

VECTOR operator/( const VECTOR& rhsVector )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX /rhsVector.fPosX;
vTemp.fPosY = this->fPosY /rhsVector.fPosY;
vTemp.fPosZ = this->fPosZ /rhsVector.fPosZ;

return vTemp;
} // >>> END operator/

VECTOR operator-( float fData )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX -fData;
vTemp.fPosY = this->fPosY -fData;
vTemp.fPosZ = this->fPosZ -fData;

return vTemp;
} // >>> END operator-

VECTOR operator+( float fData )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX +fData;
vTemp.fPosY = this->fPosY +fData;
vTemp.fPosZ = this->fPosZ +fData;

return vTemp;
} // >>> END operator+

VECTOR operator*( float fData )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX *fData;
vTemp.fPosY = this->fPosY *fData;
vTemp.fPosZ = this->fPosZ *fData;

return vTemp;
} // >>> END operator*

VECTOR operator/( float fData )
{
VECTOR vTemp;

vTemp.fPosX = this->fPosX /fData;
vTemp.fPosY = this->fPosY /fData;
vTemp.fPosZ = this->fPosZ /fData;

return vTemp;
} // >>> END operator/

};
Posted by Mister_Q