Presentation is loading. Please wait.

Presentation is loading. Please wait.

Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung.

Similar presentations


Presentation on theme: "Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung."— Presentation transcript:

1 Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung

2 Korea Univ. Computer Graphics Lab.2 Chapter Objectives View a geometric model Control the location Clip Undesired portions of the model Manipulate the appropriate matrix stacks

3 Korea Univ. Computer Graphics Lab.3 Transformation Viewing transformation Modeling transformation Projection transformation Viewport transformation

4 Korea Univ. Computer Graphics Lab.4 Transformation Stages of Vertex Transformation v’ = Mv

5 Korea Univ. Computer Graphics Lab.5 Viewing Transformation(1/6) Eye position 의 위치와 방향을 결정 Default 위치 : 원점, negative z-axis, y-axis up void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, Gldouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // 현재 행렬을 단위 행렬로 초기화

6 Korea Univ. Computer Graphics Lab.6 Viewing Transformation(2/6) Default camera position Using gluLookAt()

7 Korea Univ. Computer Graphics Lab.7 Viewing Transformation(3/6) Example 3-1. void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glLoadIdentity(); /* Viewing Transformation */ gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glScalef(1.0, 2.0, 1.0); /* Modeling Transformation */ glutWireCube(1.0); glFlush(); }

8 Korea Univ. Computer Graphics Lab.8 Viewing Transformation(4/6) void glTranslate{fd}(TYPE x, TYPE y, TYPE z); glLoadIdentity(); glColor3f(1.0, 1.0, 1.0); draw_triangle(); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0xF0F0); glTranslated(-1.0, 0.0, 0.0); glColor3f(1.0, 0.0, 0.0); draw_triangle(); glDisable(GL_LINE_STIPPLE);

9 Korea Univ. Computer Graphics Lab.9 Viewing Transformation(5/6) void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); glLoadIdentity(); glColor3f(1.0, 1.0, 1.0); draw_triangle(); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0x8888); glRotatef(90.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 0.0); draw_triangle(); glDisable(GL_LINE_STIPPLE);

10 Korea Univ. Computer Graphics Lab.10 Viewing Transformation(6/6) Rotating First or Translating First

11 Korea Univ. Computer Graphics Lab.11 Coordinate System (1/2) Grand, fixed coordinate system glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(N); // N matrix transformation glMultMatrixf(M); glMultMatrixf(L); glBegin(GL_POINTS); glVertex3f(v);// draw transformed vertex v glEnd() // v’ = N(M(Lv)) - 변환되는 점의 좌표를 명령 순서와 반대로 계산해야 함

12 Korea Univ. Computer Graphics Lab.12 Coordinate System (2/2) Local coordinate system glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(T);// Translation glMultMatrixf(R);// Rotation draw_the_object(); - 변환되는 점의 좌표가 명령 순서와 일치 예 ) 로봇의 운동

13 Korea Univ. Computer Graphics Lab.13 Modeling Transformation(1/4) 물체들의 위치와 방향을 결정 World 좌표에 대한 각 물체의 좌표 값이 결정 -> x, y, z 축에 따른 model 의 비율 결정 void glScale{fd}(TYPE x, TYPE y, TYPE z);

14 Korea Univ. Computer Graphics Lab.14 Modeling Transformation(2/4) void glScalef{fd}(TYPE x, TYPE y, TYPE z); glLoadIdentity(); glColor3f(1.0, 1.0, 1.0); draw_triangle(); glEnable(GL_LINE_STIPPLE); glLineStipple(1, 0xF00F); glScalef(1.5, 0.5, 1.0); glColor3f(0.0, 1.0, 0.0); draw_triangle(); glDisable(GL_LINE_STIPPLE);

15 Korea Univ. Computer Graphics Lab.15 Modeling Transformation(3/4) Example 3-1. void display() { glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glLoadIdentity(); /* Viewing Transformation */ gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glScalef(1.0, 2.0, 1.0); /* Modeling Transformation */ glutWireCube(1.0); glFlush(); }

16 Korea Univ. Computer Graphics Lab.16 Modeling Transformation(4/4) 프로그램 명령 순서 Viewing Transformation -> Modeling Transformation 실제 좌표 값 결정 Modeling Transformation -> Viewing Transformation

17 Korea Univ. Computer Graphics Lab.17 Vertex Transformation TranslateRotate Scale

18 Korea Univ. Computer Graphics Lab.18 Duality of Modelview(1/2) Viewing Transformation – 관측자를 이동 Modeling Transformation – 좌표계를 이동  결과적으로 같은 효과

19 Korea Univ. Computer Graphics Lab.19 Duality of Modelview(2/2) Creating a Custom Utility Routine void pilotView(double planex, double planey, double planez, double roll, double pitch, double heading) { glRotated(roll, 0.0, 0.0, 1.0); glRotated(pitch, 0.0, 1.0, 0.0); glRotated(heading, 1.0, 0.0, 0.0); glTranslated(-planex, -planey, -planez); } void polarView(double distance, double twist, double elevation, double azimuth) { glTranslated(0.0, 0.0, -distance); glRotated(-twist, 0.0, 0.0, 1.0); glRotated(-elevation, 1.0, 0.0, 0.0); glRotated(azimuth, 0.0, 0.0, 1.0); }

20 Korea Univ. Computer Graphics Lab.20 Projection Transformation(1/6) Projection Define a viewing volume glMatrixMode(GL_PROJECTION); glLoadIdentity();

21 Korea Univ. Computer Graphics Lab.21 Projection Transformation(2/6) 1) Perspective Projection –foreshortening void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);

22 Korea Univ. Computer Graphics Lab.22 Projection Transformation(3/6) void glPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far); aspect = width / height Symmetric perspective-view frustum

23 Korea Univ. Computer Graphics Lab.23 Projection Transformation(4/6) Calculating field of view – Example 3-3. #define PI 3.1415926535 double calculatingAngle(double size, double distance) { doubleradtheta, degtheta; redtheta = 2.0 * atan2(size/2.0, distance); // radian degtheta = (180.0 * redtheta) /PI; // degree return degtheta; }

24 Korea Univ. Computer Graphics Lab.24 Projection Transformation(5/6) Example 3-1. void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); gluPerspective(80.0, 1.0, 1.5, 20.0); glMatrixMode(GL_MODELVIEW); }

25 Korea Univ. Computer Graphics Lab.25 Projection Transformation(6/6) 2) Orthographic Projection – 물체의 실제 사이즈와 각도를 유지 void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);

26 Korea Univ. Computer Graphics Lab.26 Manipulating the Matrix Stacks(1/3) A stack of matrices –Useful for constructing hierarchical models glLoadIdentity() glMatrixMode() glMultMatrix() glLoadMatrix() void glPushMatrix(void); void glPopMatrix(void);

27 Korea Univ. Computer Graphics Lab.27 Manipulating the Matrix Stacks(2/3) void draw_wheel_and_bolts() { long i; draw_wheel(); for(i=0; i<5; i++) { glPushMatrix(); glRotatef(70.0*i, 0.0, 0.0, 1.0); glTranslatef(3.0, 0.0, 0.0); draw_bolt(); glPopMatrix(); } Example 3-4. Pushing and Pop Matrix

28 Korea Univ. Computer Graphics Lab.28 Manipulating the Matrix Stacks(3/3) The Modelview Matrix Stack The Projection Matrix Stack

29 Korea Univ. Computer Graphics Lab.29 Viewport Transformation(1/3) Viewport 3D 모델 좌표 -> 스크린 좌표로 변환

30 Korea Univ. Computer Graphics Lab.30 Viewport Transformation(2/3) –Viewport 의 aspect ratio –Viewing volume 의 aspect ratio void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); => 일치해야 함

31 Korea Univ. Computer Graphics Lab.31 Viewport Transformation(3/3) The Transformed Depth Coordinate –Range : [0.0, 1.0] –near clipping plane 에서 멀어질수록 정밀도 떨어짐 void glDepthRange(GLclampd near, GLclampd far);

32 Korea Univ. Computer Graphics Lab.32 Homogeneous Coordinates System Homogeneous Vertex (x, y, z, w) – 위치나 벡터를 나타냄 –W≠0 일 경우 –W = 0 일 경우 point at infinity –Use only non-negative w-values

33 Korea Univ. Computer Graphics Lab.33 Additional Clipping Planes Example 3-5. Wireframe Sphere with two Clipping Planes GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0}; // y=0 GLdouble eqn2[4] = {1.0, 0.0, 0.0, 0.0}; // x=0 glClipPlane(GL_CLIP_PLANE0, eqn); glEnable(GL_CLIP_PLANE0);

34 Korea Univ. Computer Graphics Lab.34 Examples of Composing Several Transformation Example 3-6. Planetary System

35 Korea Univ. Computer Graphics Lab.35 Examples of Composing Several Transformation Example 3-7. Robot Arm

36 Korea Univ. Computer Graphics Lab.36 Reverse and Mimicking Transformation Example 3-8. Take and reverse


Download ppt "Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung."

Similar presentations


Ads by Google