Vector2D 클래스 제작


//// 최종 수정일 : 2014년 3월 1일

//// 최종 작정자 : 캠캡

//// 소스 설명          : 2차원 벡터의 클래스화 및 인공지능 공부에 필요한 연산 구현

//// 에러         : 현재까지 없음.



#pragma once



template <typename T = float>

class Vector2D

{

private:

T x;

T y;


public:

explicit Vector2D();

explicit Vector2D(T _x, T _y);

template <typename Y>

explicit Vector2D(const Vector2D<Y>& other);

virtual ~Vector2D(void);


inline void Zero();                 

//벡터의 요소를 0으로 설정


inline bool isZeor() const;

//벡터의 요소가 모두 0인지 확인


inline double Length() const;

//벡터의 길이를 반환


inline double LengthSq() const;

//벡터의 길이를 제곱으로 반환 


inline void Normalize();

//정규화 벡터를 반환


inline double dot(const Vector2D& v2) const;        

 //내적



//내적을 이용하여 매개변수 벡터의 방향을 판별

//시계 방향에 있으면 양의 값을 반환

//시계 반대방향에 있으면 음의 값을 반환

inline int sign(const Vector2D& v2) const;


inline Vector2D& Perp() const;

//현재 벡터에 수직인 벡터를 반환


inline void Truncate(T max);

//벡터 길이가 최대값을 넘지 않도록 x,y를 조정

inline double Distance(const Vector2D& v2) const;

//두 벡터의 길이를 반환

inline double DistanceSq(const Vector2D& v2) const;    

//두 벡터의 길이를 제곱하여 반환


inline Vector2D& GetReverse() const;

//두 벡터의 반대 방향을 반환

const Vector2D& operator+= (const Vector2D& rhs);

const Vector2D& operator-= (const Vector2D& rhs);

template <typename Y>

const Vector2D& operator*= (const T& ths);

template <typename Y>

const Vector2D& operator/= (const T& ths);

bool operator== (const Vector2D& rhs);

bool operator!= (const Vector2D& rhs);


T GetX() const;

T GetY() const;

};



더보기

댓글,

Lowpoly

게임 서버 프로그래머 지망생