Viewing Korea Univ Computer Graphics Lab Hong Jin
Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung Korea Univ. Computer Graphics Lab.
Chapter Objectives • • View a geometric model Control the location Clip Undesired portions of the model Manipulate the appropriate matrix stacks 2 Korea Univ. Computer Graphics Lab.
Transformation • • Viewing transformation Modeling transformation Projection transformation Viewport transformation 3 Korea Univ. Computer Graphics Lab.
Transformation • Stages of Vertex Transformation • v’ = Mv 4 Korea Univ. Computer Graphics Lab.
Viewing Transformation(1/6) • Eye position의 위치와 방향을 결정 • Default 위치 : 원점, negative z-axis, y-axis up gl. Matrix. Mode(GL_MODELVIEW); gl. Load. Identity(); // 현재 행렬을 단위 행렬로 초기화 void glu. Look. At(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, Gldouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); 5 Korea Univ. Computer Graphics Lab.
Viewing Transformation(2/6) Using glu. Look. At() Default camera position 6 Korea Univ. Computer Graphics Lab.
Viewing Transformation(3/6) • Example 3 -1. void display() { gl. Clear(GL_COLOR_BUFFER_BIT); gl. Color 3 f(1. 0, 1. 0); gl. Load. Identity(); /* Viewing Transformation */ glu. Look. At(0. 0, 5. 0, 0. 0, 1. 0, 0. 0); gl. Scalef(1. 0, 2. 0, 1. 0); /* Modeling Transformation */ glut. Wire. Cube(1. 0); gl. Flush(); } 7 Korea Univ. Computer Graphics Lab.
Viewing Transformation(4/6) void gl. Translate{fd}(TYPE x, TYPE y, TYPE z); gl. Load. Identity(); gl. Color 3 f(1. 0, 1. 0); draw_triangle(); gl. Enable(GL_LINE_STIPPLE); gl. Line. Stipple(1, 0 x. F 0 F 0); gl. Translated(-1. 0, 0. 0); gl. Color 3 f(1. 0, 0. 0); draw_triangle(); gl. Disable(GL_LINE_STIPPLE); 8 Korea Univ. Computer Graphics Lab.
Viewing Transformation(5/6) void gl. Rotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z); gl. Load. Identity(); gl. Color 3 f(1. 0, 1. 0); draw_triangle(); gl. Enable(GL_LINE_STIPPLE); gl. Line. Stipple(1, 0 x 8888); gl. Rotatef(90. 0, 1. 0); gl. Color 3 f(1. 0, 0. 0); draw_triangle(); gl. Disable(GL_LINE_STIPPLE); 9 Korea Univ. Computer Graphics Lab.
Viewing Transformation(6/6) • Rotating First or Translating First 10 Korea Univ. Computer Graphics Lab.
Coordinate System (1/2) • Grand, fixed coordinate system - 변환되는 점의 좌표를 명령 순서와 반대로 계산해야 함 gl. Matrix. Mode(GL_MODELVIEW); gl. Load. Identity(); gl. Mult. Matrixf(N); // N matrix transformation gl. Mult. Matrixf(M); gl. Mult. Matrixf(L); gl. Begin(GL_POINTS); gl. Vertex 3 f(v); // draw transformed vertex v gl. End() // v’ = N(M(Lv)) 11 Korea Univ. Computer Graphics Lab.
Coordinate System (2/2) • Local coordinate system - 변환되는 점의 좌표가 명령 순서와 일치 gl. Matrix. Mode(GL_MODELVIEW); gl. Load. Identity(); gl. Mult. Matrixf(T); gl. Mult. Matrixf(R); // Translation // Rotation draw_the_object(); 예) 로봇의 운동 12 Korea Univ. Computer Graphics Lab.
Modeling Transformation(1/4) • 물체들의 위치와 방향을 결정 • World 좌표에 대한 각 물체의 좌표 값이 결정 void gl. Scale{fd}(TYPE x, TYPE y, TYPE z); -> x, y, z 축에 따른 model의 비율 결정 13 Korea Univ. Computer Graphics Lab.
Modeling Transformation(2/4) void gl. Scalef{fd}(TYPE x, TYPE y, TYPE z); gl. Load. Identity(); gl. Color 3 f(1. 0, 1. 0); draw_triangle(); gl. Enable(GL_LINE_STIPPLE); gl. Line. Stipple(1, 0 x. F 00 F); gl. Scalef(1. 5, 0. 5, 1. 0); gl. Color 3 f(0. 0, 1. 0, 0. 0); draw_triangle(); gl. Disable(GL_LINE_STIPPLE); 14 Korea Univ. Computer Graphics Lab.
Modeling Transformation(3/4) • Example 3 -1. void display() { gl. Clear(GL_COLOR_BUFFER_BIT); gl. Color 3 f(1. 0, 1. 0); gl. Load. Identity(); /* Viewing Transformation */ glu. Look. At(0. 0, 5. 0, 0. 0, 1. 0, 0. 0); gl. Scalef(1. 0, 2. 0, 1. 0); /* Modeling Transformation */ glut. Wire. Cube(1. 0); gl. Flush(); } 15 Korea Univ. Computer Graphics Lab.
Modeling Transformation(4/4) • 프로그램 명령 순서 Viewing Transformation -> Modeling Transformation • 실제 좌표 값 결정 Modeling Transformation -> Viewing Transformation 16 Korea Univ. Computer Graphics Lab.
Vertex Transformation Translate Rotate 17 Scale Korea Univ. Computer Graphics Lab.
Duality of Modelview(1/2) • Viewing Transformation – 관측자를 이동 • Modeling Transformation – 좌표계를 이동 Þ 결과적으로 같은 효과 18 Korea Univ. Computer Graphics Lab.
Duality of Modelview(2/2) • Creating a Custom Utility Routine void pilot. View(double planex, double planey, double planez, double roll, double pitch, double heading) { gl. Rotated(roll, 0. 0, 1. 0); gl. Rotated(pitch, 0. 0, 1. 0, 0. 0); gl. Rotated(heading, 1. 0, 0. 0); gl. Translated(-planex, -planey, -planez); } void polar. View(double distance, double twist, double elevation, double azimuth) { gl. Translated(0. 0, -distance); gl. Rotated(-twist, 0. 0, 1. 0); gl. Rotated(-elevation, 1. 0, 0. 0); gl. Rotated(azimuth, 0. 0, 1. 0); } 19 Korea Univ. Computer Graphics Lab.
Projection Transformation(1/6) • Projection • Define a viewing volume gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); 20 Korea Univ. Computer Graphics Lab.
Projection Transformation(2/6) • 1) Perspective Projection – foreshortening void gl. Frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); 21 Korea Univ. Computer Graphics Lab.
Projection Transformation(3/6) • Symmetric perspective-view frustum void gl. Perspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far); aspect = width / height 22 Korea Univ. Computer Graphics Lab.
Projection Transformation(4/6) • Calculating field of view – Example 3 -3. #define PI 3. 1415926535 double calculating. Angle(double size, double distance) { double radtheta, degtheta; redtheta = 2. 0 * atan 2(size/2. 0, distance); degtheta = (180. 0 * redtheta) /PI; return degtheta; // radian // degree } 23 Korea Univ. Computer Graphics Lab.
Projection Transformation(5/6) • Example 3 -1. void reshape(int w, int h) { gl. Viewport(0, 0, (GLsizei) w, (GLsizei) h); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); //gl. Frustum(-1. 0, 1. 5, 20. 0); glu. Perspective(80. 0, 1. 5, 20. 0); gl. Matrix. Mode(GL_MODELVIEW); } 24 Korea Univ. Computer Graphics Lab.
Projection Transformation(6/6) • 2) Orthographic Projection – 물체의 실제 사이즈와 각도를 유지 void gl. Ortho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); 25 Korea Univ. Computer Graphics Lab.
Manipulating the Matrix Stacks(1/3) • A stack of matrices – Useful for constructing hierarchical models • • gl. Load. Identity() gl. Matrix. Mode() gl. Mult. Matrix() gl. Load. Matrix() void gl. Push. Matrix(void); void gl. Pop. Matrix(void); 26 Korea Univ. Computer Graphics Lab.
Manipulating the Matrix Stacks(2/3) • Example 3 -4. Pushing and Pop Matrix void draw_wheel_and_bolts() { long i; draw_wheel(); for(i=0; i<5; i++) { gl. Push. Matrix(); gl. Rotatef(70. 0*i, 0. 0, 1. 0); gl. Translatef(3. 0, 0. 0); draw_bolt(); gl. Pop. Matrix(); } } 27 Korea Univ. Computer Graphics Lab.
Manipulating the Matrix Stacks(3/3) • The Modelview Matrix Stack • The Projection Matrix Stack 28 Korea Univ. Computer Graphics Lab.
Viewport Transformation(1/3) • Viewport • 3 D 모델 좌표 -> 스크린 좌표로 변환 29 Korea Univ. Computer Graphics Lab.
Viewport Transformation(2/3) void gl. Viewport(GLint x, GLint y, GLsizei width, GLsizei height); – Viewport의 aspect ratio – Viewing volume의 aspect ratio 30 => 일치해야 함 Korea Univ. Computer Graphics Lab.
Viewport Transformation(3/3) • The Transformed Depth Coordinate void gl. Depth. Range(GLclampd near, GLclampd far); – Range : [0. 0, 1. 0] – near clipping plane에서 멀어질수록 정밀도 떨어짐 31 Korea Univ. Computer Graphics Lab.
Homogeneous Coordinates System • Homogeneous Vertex (x, y, z, w) – 위치나 벡터를 나타냄 – W≠ 0일 경우 – W= 0일 경우 • point at infinity – Use only non-negative w-values 32 Korea Univ. Computer Graphics Lab.
Additional Clipping Planes • Example 3 -5. Wireframe Sphere with two Clipping Planes GLdouble eqn[4] = {0. 0, 1. 0, 0. 0}; GLdouble eqn 2[4] = {1. 0, 0. 0}; // y=0 // x=0 gl. Clip. Plane(GL_CLIP_PLANE 0, eqn); gl. Enable(GL_CLIP_PLANE 0); 33 Korea Univ. Computer Graphics Lab.
Examples of Composing Several Transformation • Example 3 -6. Planetary System 34 Korea Univ. Computer Graphics Lab.
Examples of Composing Several Transformation • Example 3 -7. Robot Arm 35 Korea Univ. Computer Graphics Lab.
Reverse and Mimicking Transformation • Example 3 -8. Take and reverse 36 Korea Univ. Computer Graphics Lab.
- Slides: 36