U E D R , A S I H C RSS

그래픽스세미나/3주차


1. 개요

일시 : 2003년 3월 17일 월요일 8시
장소 : 7층 PC실 - 세미나실

2. 내용

PPT파일: Upload:CGseminar3.zip

3. 숙제

  • 벡터 클래스 만들기
    윤정수 Upload:mathLib.zip아직 제작중 역행렬은 어찌 구하징.. ㅡㅡ;;
    강인수 옛날에 만들어놓은거
    박경태 기권. C# struct형으로 만들어보려다가 생고생만 함. 해보기는 했어엽..

  • 창의 프로그램(nehe OpenGL tutorial 10번정도면 괜찮을듯 하군요..^^)
    박경태 Upload:OpenGLATL03_Pkt.zip ATL(??) 컴파일후 ATLTest.htm를 실행
    김창성 Upload:world.zip음...

4. 참고

최태호의 벡터 클래스 입니다. 참고 하세요.
~cpp 

# include "math.h"

///////////////////////////////////////////////////////////////////////
//CGX_Vector

# define DG	4
# define EPSILON 0.000001
# define GX_V_E_MULT(AA,B,C){AA[0]=B[0]*C[0];		AA[1]=B[1]*C[1];		AA[2]=B[2]*C[2]; AA[3]=1;}
# define M_PI	3.141592

template <class T>
class CGX_Vector
{
public:
	T e[DG];
public:
	CGX_Vector();
	CGX_Vector<T> operator+(CGX_Vector<T> in);
	CGX_Vector<T> operator+(T* in);
	CGX_Vector<T> operator-(CGX_Vector<T> in);
	CGX_Vector<T> operator-(T* in);	
	CGX_Vector<T> operator*(T in);
	CGX_Vector<T> operator/(T in);
	void operator=(CGX_Vector<T> in);
	void operator=(T* in);

	T& operator[](int in);

	CGX_Vector<T> operator*(CGX_Vector<T> in);//cross product
	T operator^(CGX_Vector<T> in);//dot product

	CGX_Vector<T> Normalize();
	CGX_Vector<T> Clip(T v);
	T Max();
	BOOL equal(CGX_Vector<T> b);
	T* GetElement();
	float Length();
	
	friend CGX_Vector<T> operator-(CGX_Vector<T> in);
};
//////////////////////////////////////////////////////////////////////////////
//implement

template<class T> 
BOOL CGX_Vector<T>::equal( CGX_Vector<T> b)
{
	for(int i=0;i<3;i++) if (e[i]- b[i] > EPSILON) return FALSE;
	return TRUE;
}
template<class T> 
T* CGX_Vector<T>::GetElement()
{
	return e;
}

template<class T> 
CGX_Vector<T>::CGX_Vector()
{
	for (int i=0;i<DG;i++) e[i]=0;
}


template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator+(CGX_Vector<T> in)
{
	CGX_Vector<T> temp;
	for(int count=0;count<DG;count++){
		temp.e[count]=e[count] + in.e[count];
	}
	return temp;
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator+(T* in)
{
	CGX_Vector<T> temp;
	for(int count=0;count<DG;count++){
		temp.e[count]=e[count] + in[count];
	}
	return temp;
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator-(CGX_Vector<T> in)
{
	CGX_Vector<T> temp;
	for(int count=0;count<DG;count++){
		temp.e[count]=e[count] - in.e[count];
	}
	return temp;
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator-(T* in)
{
	CGX_Vector<T> temp;
	for(int count=0;count<DG;count++){
		temp.e[count]=e[count] - in[count];
	}
	return temp;
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator*(T in)
{
	CGX_Vector<T> temp;
	for (int i=0;i<DG;i++) temp.e[i]= e[i]*in;
	return temp;
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator/(T in)
{
	CGX_Vector<T> temp;
	for (int i=0;i<DG;i++) temp.e[i]= e[i]/in;
	return temp;
}

template<class T> 
void CGX_Vector<T>::operator=(CGX_Vector<T> in)
{
	for(int count=0;count<DG;count++){
		e[count] = in.e[count];
	}

}
template<class T> 
void CGX_Vector<T>::operator=(T* in)
{
	for(int count=0;count<DG;count++){
		e[count] = in[count];
	}

}

template<class T> 
T& CGX_Vector<T>::operator[](int in)
{
	return e[in];
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::operator*(CGX_Vector<T> in)
{
	CGX_Vector<T> temp;
	temp.e[0]=e[1]*in.e[2] - e[2]*in.e[1];
	temp.e[1]=e[2]*in.e[0] - e[0]*in.e[2];
	temp.e[2]=e[0]*in.e[1] - e[1]*in.e[0];
	return temp;
}

///도트 프로덕트..
template<class T> 
T CGX_Vector<T>::operator^(CGX_Vector<T> in)
{
	T total=0;
	for (int i =0;i<DG-1;i++)//homogenious coordinate system 이므로..
		total= total + ( e[i] * in.e[i] );
	return total;
}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::Normalize()
{
	CGX_Vector<T> temp;
	float length = (float)Length();
	for (int i=0;i<DG-1;i++) {
		temp.e[i]= e[i]/length;
		e[i] = e[i]/length;
		
	}
	temp.e[3]=1.0f;
	e[3]=1.0f;
	return temp;

}

template<class T> 
CGX_Vector<T> CGX_Vector<T>::Clip(T v)
{
	CGX_Vector<T> temp;
	for (int i=0;i<DG-1;i++) {
		if (e[i] > v) temp.e[i]=v;
		else temp.e[i]=e[i];
	}
	return temp;

}

template<class T>
T CGX_Vector<T>::Max()
{
	T max=-9999999.0f;
	for(int i=0;i<DG-1;i++){
		if (e[i]>max) max= e[i];
	}
	return max;
}

template<class T> 
float CGX_Vector<T>::Length()
{
	return (float)sqrt(e[0]*e[0] +e[1]*e[1]+ e[2]*e[2] );
}
/////////////////////////////////
//많은 define들의 집합..

typedef CGX_Vector<float> GX_V;

래픽스세미나
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:46
Processing time 0.0154 sec