Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

그래픽스세미나/3주차: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair MoniWiki formatting after migration)
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
  장소 : 7층 PC실 - 세미나실
  장소 : 7층 PC실 - 세미나실
=== 내용 ===
=== 내용 ===
   PPT파일: [[:File:CGseminar3.zip|CGseminar3.zip]]
   PPT파일: CGseminar3.zip
=== 숙제 ===
=== 숙제 ===
* 벡터 클래스 만들기
* 벡터 클래스 만들기
Line 10: Line 10:
|-
|-
| 윤정수
| 윤정수
| [[:File:mathLib.zip|mathLib.zip]] 아직 제작중 역행렬은 어찌 구하징.. ㅡㅡ;;
| mathLib.zip 아직 제작중 역행렬은 어찌 구하징.. ㅡㅡ;;
|-
|-
| 강인수
| 강인수
Line 19: Line 19:
|}
|}


* 창의 프로그램(nehe OpenGL tutorial 10번정도면 괜찮을듯 하군요..^^)
* 창의 프로그램(nehe [[OpenGL]] tutorial 10번정도면 괜찮을듯 하군요..^^)
{| class="wikitable"
{| class="wikitable"
|-
|-
| 박경태
| 박경태
| [[:File:OpenGLATL03_Pkt.zip|OpenGLATL03_Pkt.zip]] ATL(??) 컴파일후 ATLTest.htm를 실행
| OpenGLATL03_Pkt.zip ATL(??) 컴파일후 ATLTest.htm를 실행
|-
|-
| 김창성
| 김창성
| [[:File:world.zip|world.zip]] 음...
| world.zip 음...
|}
|}


Line 39: Line 39:
  # define DG 4
  # define DG 4
  # define EPSILON 0.000001
  # 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 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
  # define M_PI 3.141592
   
   
Line 46: Line 46:
  {
  {
  public:
  public:
  T e[DG];
  T e[DG];
  public:
  public:
  CGX_Vector();
  CGX_Vector();
Line 58: Line 58:
  void operator=(T* in);
  void operator=(T* in);
   
   
  T& operator[](int in);
  T& operator[](int in);
   
   
  CGX_Vector<T> operator*(CGX_Vector<T> in);//cross product
  CGX_Vector<T> operator*(CGX_Vector<T> in);//cross product
Line 78: Line 78:
  BOOL CGX_Vector<T>::equal( CGX_Vector<T> b)
  BOOL CGX_Vector<T>::equal( CGX_Vector<T> b)
  {
  {
  for(int i=0;i<3;i++) if (e[i]- b[i] > EPSILON) return FALSE;
  for(int i=0;i<3;i++) if (e[i]- b[i] > EPSILON) return FALSE;
  return TRUE;
  return TRUE;
  }
  }
Line 90: Line 90:
  CGX_Vector<T>::CGX_Vector()
  CGX_Vector<T>::CGX_Vector()
  {
  {
  for (int i=0;i<DG;i++) e[i]=0;
  for (int i=0;i<DG;i++) e[i]=0;
  }
  }
   
   
Line 99: Line 99:
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for(int count=0;count<DG;count++){
  for(int count=0;count<DG;count++){
  temp.e[count]=e[count] + in.e[count];
  temp.e[count]=e[count] + in.e[count];
  }
  }
  return temp;
  return temp;
Line 109: Line 109:
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for(int count=0;count<DG;count++){
  for(int count=0;count<DG;count++){
  temp.e[count]=e[count] + in[count];
  temp.e[count]=e[count] + in[count];
  }
  }
  return temp;
  return temp;
Line 119: Line 119:
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for(int count=0;count<DG;count++){
  for(int count=0;count<DG;count++){
  temp.e[count]=e[count] - in.e[count];
  temp.e[count]=e[count] - in.e[count];
  }
  }
  return temp;
  return temp;
Line 129: Line 129:
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for(int count=0;count<DG;count++){
  for(int count=0;count<DG;count++){
  temp.e[count]=e[count] - in[count];
  temp.e[count]=e[count] - in[count];
  }
  }
  return temp;
  return temp;
Line 138: Line 138:
  {
  {
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for (int i=0;i<DG;i++) temp.e[i]= e[i]*in;
  for (int i=0;i<DG;i++) temp.e[i]= e[i]*in;
  return temp;
  return temp;
  }
  }
Line 146: Line 146:
  {
  {
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for (int i=0;i<DG;i++) temp.e[i]= e[i]/in;
  for (int i=0;i<DG;i++) temp.e[i]= e[i]/in;
  return temp;
  return temp;
  }
  }
Line 154: Line 154:
  {
  {
  for(int count=0;count<DG;count++){
  for(int count=0;count<DG;count++){
  e[count] = in.e[count];
  e[count] = in.e[count];
  }
  }
   
   
Line 162: Line 162:
  {
  {
  for(int count=0;count<DG;count++){
  for(int count=0;count<DG;count++){
  e[count] = in[count];
  e[count] = in[count];
  }
  }
   
   
Line 168: Line 168:
   
   
  template<class T>  
  template<class T>  
  T& CGX_Vector<T>::operator[](int in)
  T& CGX_Vector<T>::operator[](int in)
  {
  {
  return e[in];
  return e[in];
  }
  }
   
   
Line 177: Line 177:
  {
  {
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  temp.e[0]=e[1]*in.e[2] - e[2]*in.e[1];
  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[1]=e[2]*in.e[0] - e[0]*in.e[2];
  temp.e[2]=e[0]*in.e[1] - e[1]*in.e[0];
  temp.e[2]=e[0]*in.e[1] - e[1]*in.e[0];
  return temp;
  return temp;
  }
  }
Line 189: Line 189:
  T total=0;
  T total=0;
  for (int i =0;i<DG-1;i++)//homogenious coordinate system 이므로..
  for (int i =0;i<DG-1;i++)//homogenious coordinate system 이므로..
  total= total + ( e[i] * in.e[i] );
  total= total + ( e[i] * in.e[i] );
  return total;
  return total;
  }
  }
Line 199: Line 199:
  float length = (float)Length();
  float length = (float)Length();
  for (int i=0;i<DG-1;i++) {
  for (int i=0;i<DG-1;i++) {
  temp.e[i]= e[i]/length;
  temp.e[i]= e[i]/length;
  e[i] = e[i]/length;
  e[i] = e[i]/length;
 
 
  }
  }
  temp.e[3]=1.0f;
  temp.e[3]=1.0f;
  e[3]=1.0f;
  e[3]=1.0f;
  return temp;
  return temp;
   
   
Line 214: Line 214:
  CGX_Vector<T> temp;
  CGX_Vector<T> temp;
  for (int i=0;i<DG-1;i++) {
  for (int i=0;i<DG-1;i++) {
  if (e[i] > v) temp.e[i]=v;
  if (e[i] > v) temp.e[i]=v;
  else temp.e[i]=e[i];
  else temp.e[i]=e[i];
  }
  }
  return temp;
  return temp;
Line 226: Line 226:
  T max=-9999999.0f;
  T max=-9999999.0f;
  for(int i=0;i<DG-1;i++){
  for(int i=0;i<DG-1;i++){
  if (e[i]>max) max= e[i];
  if (e[i]>max) max= e[i];
  }
  }
  return max;
  return max;
Line 234: Line 234:
  float CGX_Vector<T>::Length()
  float CGX_Vector<T>::Length()
  {
  {
  return (float)sqrt(e[0]*e[0] +e[1]*e[1]+ e[2]*e[2] );
  return (float)sqrt(e[0]*e[0] +e[1]*e[1]+ e[2]*e[2] );
  }
  }
  /////////////////////////////////
  /////////////////////////////////
Line 241: Line 241:
  typedef CGX_Vector<float> GX_V;
  typedef CGX_Vector<float> GX_V;
----
----
[[그래픽스세미나]]
그래픽스세미나
 

Latest revision as of 00:34, 29 March 2026

개요

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

내용

 PPT파일: CGseminar3.zip

숙제

  • 벡터 클래스 만들기
윤정수 mathLib.zip 아직 제작중 역행렬은 어찌 구하징.. ㅡㅡ;;
강인수 옛날에 만들어놓은거
박경태 기권. C# struct형으로 만들어보려다가 생고생만 함. 해보기는 했어엽..
  • 창의 프로그램(nehe OpenGL tutorial 10번정도면 괜찮을듯 하군요..^^)
박경태 OpenGLATL03_Pkt.zip ATL(??) 컴파일후 ATLTest.htm를 실행
김창성 world.zip 음...

참고

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

# 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;

그래픽스세미나