360 likes | 591 Views
Viewing. Korea Univ. Computer Graphics Lab. Hong, Jin Kyung. Chapter Objectives. View a geometric model Control the location Clip Undesired portions of the model Manipulate the appropriate matrix stacks. Transformation. Viewing transformation Modeling transformation
E N D
Viewing Korea Univ. Computer Graphics Lab. Hong, Jin Kyung
Chapter Objectives • View a geometric model • Control the location • Clip Undesired portions of the model • Manipulate the appropriate matrix stacks Korea Univ. Computer Graphics Lab.
Transformation • Viewing transformation • Modeling transformation • Projection transformation • Viewport transformation Korea Univ. Computer Graphics Lab.
Transformation • Stages of Vertex Transformation • v’ = Mv Korea Univ. Computer Graphics Lab.
Viewing Transformation(1/6) • Eye position의 위치와 방향을 결정 • Default 위치 : 원점, negative z-axis, y-axis up glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // 현재 행렬을 단위 행렬로 초기화 void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, Gldouble centerz, GLdouble upx, GLdouble upy, GLdouble upz); Korea Univ. Computer Graphics Lab.
Viewing Transformation(2/6) Using gluLookAt() Default camera position Korea Univ. Computer Graphics Lab.
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(); } Korea Univ. Computer Graphics Lab.
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); Korea Univ. Computer Graphics Lab.
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); Korea Univ. Computer Graphics Lab.
Viewing Transformation(6/6) • Rotating First or Translating First Korea Univ. Computer Graphics Lab.
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)) Korea Univ. Computer Graphics Lab.
Coordinate System (2/2) • Local coordinate system • 변환되는 점의 좌표가 명령 순서와 일치 glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glMultMatrixf(T); // Translation glMultMatrixf(R); // Rotation draw_the_object(); 예) 로봇의 운동 Korea Univ. Computer Graphics Lab.
Modeling Transformation(1/4) • 물체들의 위치와 방향을 결정 • World 좌표에 대한 각 물체의 좌표 값이 결정 void glScale{fd}(TYPE x, TYPE y, TYPE z); -> x, y, z 축에 따른 model의 비율 결정 Korea Univ. Computer Graphics Lab.
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); Korea Univ. Computer Graphics Lab.
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(); } Korea Univ. Computer Graphics Lab.
Modeling Transformation(4/4) • 프로그램 명령 순서 Viewing Transformation -> Modeling Transformation • 실제 좌표 값 결정 Modeling Transformation -> Viewing Transformation Korea Univ. Computer Graphics Lab.
Vertex Transformation Scale Translate Rotate Korea Univ. Computer Graphics Lab.
Duality of Modelview(1/2) • Viewing Transformation • 관측자를 이동 • Modeling Transformation • 좌표계를 이동 • 결과적으로 같은 효과 Korea Univ. Computer Graphics Lab.
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); } Korea Univ. Computer Graphics Lab.
Projection Transformation(1/6) • Projection • Define a viewing volume glMatrixMode(GL_PROJECTION); glLoadIdentity(); Korea Univ. Computer Graphics Lab.
Projection Transformation(2/6) • 1) Perspective Projection • foreshortening void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); Korea Univ. Computer Graphics Lab.
Projection Transformation(3/6) • Symmetric perspective-view frustum void glPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far); aspect = width / height Korea Univ. Computer Graphics Lab.
Projection Transformation(4/6) • Calculating field of view • Example 3-3. #define PI 3.1415926535 double calculatingAngle(double size, double distance) { double radtheta, degtheta; redtheta = 2.0 * atan2(size/2.0, distance); // radian degtheta = (180.0 * redtheta) /PI; // degree return degtheta; } Korea Univ. Computer Graphics Lab.
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); } Korea Univ. Computer Graphics Lab.
Projection Transformation(6/6) • 2) Orthographic Projection • 물체의 실제 사이즈와 각도를 유지 void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); Korea Univ. Computer Graphics Lab.
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); 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++) { glPushMatrix(); glRotatef(70.0*i, 0.0, 0.0, 1.0); glTranslatef(3.0, 0.0, 0.0); draw_bolt(); glPopMatrix(); } } Korea Univ. Computer Graphics Lab.
Manipulating the Matrix Stacks(3/3) • The Modelview Matrix Stack • The Projection Matrix Stack Korea Univ. Computer Graphics Lab.
Viewport Transformation(1/3) • Viewport • 3D 모델 좌표 -> 스크린 좌표로 변환 Korea Univ. Computer Graphics Lab.
Viewport Transformation(2/3) • Viewport의 aspect ratio • Viewing volume의 aspect ratio void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); => 일치해야 함 Korea Univ. Computer Graphics Lab.
Viewport Transformation(3/3) • The Transformed Depth Coordinate • Range : [0.0, 1.0] • near clipping plane에서 멀어질수록 정밀도 떨어짐 void glDepthRange(GLclampd near, GLclampd far); 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 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, 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); Korea Univ. Computer Graphics Lab.
Examples of Composing Several Transformation • Example 3-6. Planetary System Korea Univ. Computer Graphics Lab.
Examples of Composing Several Transformation • Example 3-7. Robot Arm Korea Univ. Computer Graphics Lab.
Reverse and Mimicking Transformation • Example 3-8. Take and reverse Korea Univ. Computer Graphics Lab.