Viewing
description
Transcript of Viewing
![Page 1: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/1.jpg)
ViewingViewingKorea Univ.Korea Univ.
Computer Graphics Lab.Computer Graphics Lab.Hong, Jin KyungHong, Jin Kyung
![Page 2: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/2.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.22
Chapter ObjectivesChapter Objectives• View a geometric model• Control the location• Clip Undesired portions of the model• Manipulate the appropriate matrix
stacks
![Page 3: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/3.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.33
TransformationTransformation• Viewing transformation• Modeling transformation• Projection transformation• Viewport transformation
![Page 4: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/4.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.44
TransformationTransformation• Stages of Vertex Transformation
• v’ = Mv
![Page 5: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/5.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.55
Viewing Transformation(1/6)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(); // 현재 행렬을 단위 행렬로 초기화
![Page 6: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/6.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.66
Viewing Transformation(2/6)Viewing Transformation(2/6)
Default camera position Using gluLookAt()
![Page 7: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/7.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.77
Viewing Transformation(3/6)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();
}
![Page 8: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/8.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.88
Viewing Transformation(4/6)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);
![Page 9: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/9.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.99
Viewing Transformation(5/6)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);
![Page 10: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/10.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1010
Viewing Transformation(6/6)Viewing Transformation(6/6)• Rotating First or Translating First
![Page 11: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/11.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1111
Coordinate System (1/2)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))
- 변환되는 점의 좌표를 명령 순서와 반대로 계산해야 함
![Page 12: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/12.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1212
Coordinate System (2/2)Coordinate System (2/2)• Local coordinate system
glMatrixMode(GL_MODELVIEW);glLoadIdentity();glMultMatrixf(T); // TranslationglMultMatrixf(R); // Rotation
draw_the_object();
- 변환되는 점의 좌표가 명령 순서와 일치
예 ) 로봇의 운동
![Page 13: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/13.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1313
Modeling Modeling Transformation(1/4)Transformation(1/4)
• 물체들의 위치와 방향을 결정• World 좌표에 대한 각 물체의 좌표 값이 결정
-> x, y, z 축에 따른 model 의 비율 결정void glScale{fd}(TYPE x, TYPE y, TYPE z);
![Page 14: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/14.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1414
Modeling Modeling Transformation(2/4)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);
![Page 15: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/15.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1515
Modeling Modeling Transformation(3/4)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();
}
![Page 16: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/16.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1616
Modeling Modeling Transformation(4/4)Transformation(4/4)
• 프로그램 명령 순서 Viewing Transformation -> Modeling
Transformation
• 실제 좌표 값 결정 Modeling Transformation -> Viewing
Transformation
![Page 17: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/17.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1717
Vertex TransformationVertex Transformation
Translate
Rotate Scale
![Page 18: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/18.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1818
Duality of Modelview(1/2)Duality of Modelview(1/2)• Viewing Transformation
– 관측자를 이동
• Modeling Transformation– 좌표계를 이동
결과적으로 같은 효과
![Page 19: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/19.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.1919
Duality of Modelview(2/2)Duality of Modelview(2/2)• Creating a Custom Utility Routinevoid 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);
}
![Page 20: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/20.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2020
Projection Projection Transformation(1/6)Transformation(1/6)
• Projection• Define a viewing volume
glMatrixMode(GL_PROJECTION);glLoadIdentity();
![Page 21: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/21.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2121
Projection Projection Transformation(2/6)Transformation(2/6)
• 1) Perspective Projection– foreshortening
void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
![Page 22: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/22.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2222
Projection Projection Transformation(3/6)Transformation(3/6)
void glPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far);
aspect = width / height
• Symmetric perspective-view frustum
![Page 23: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/23.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2323
Projection Projection Transformation(4/6)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); // radiandegtheta = (180.0 * redtheta) /PI; // degreereturn degtheta;
}
![Page 24: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/24.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2424
Projection Projection Transformation(5/6)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);
}
![Page 25: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/25.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2525
Projection Projection Transformation(6/6)Transformation(6/6)
• 2) Orthographic Projection– 물체의 실제 사이즈와 각도를 유지
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far);
![Page 26: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/26.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2626
Manipulating the Matrix Manipulating the Matrix Stacks(1/3)Stacks(1/3)
• A stack of matrices– Useful for constructing hierarchical models
• glLoadIdentity()• glMatrixMode()• glMultMatrix()• glLoadMatrix()
void glPushMatrix(void);
void glPopMatrix(void);
![Page 27: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/27.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2727
Manipulating the Matrix Manipulating the Matrix Stacks(2/3)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
![Page 28: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/28.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2828
Manipulating the Matrix Manipulating the Matrix Stacks(3/3)Stacks(3/3)
• The Modelview Matrix Stack• The Projection Matrix Stack
![Page 29: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/29.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.2929
Viewport Viewport Transformation(1/3)Transformation(1/3)
• Viewport • 3D 모델 좌표 -> 스크린 좌표로 변환
![Page 30: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/30.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3030
Viewport Viewport Transformation(2/3)Transformation(2/3)
– Viewport 의 aspect ratio– Viewing volume 의 aspect ratio
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
=> 일치해야 함
![Page 31: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/31.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3131
Viewport Viewport Transformation(3/3)Transformation(3/3)
• The Transformed Depth Coordinate
– Range : [0.0, 1.0]– near clipping plane 에서 멀어질수록 정밀도 떨어짐
void glDepthRange(GLclampd near, GLclampd far);
![Page 32: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/32.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3232
Homogeneous Coordinates Homogeneous Coordinates SystemSystem
• Homogeneous Vertex (x, y, z, w)– 위치나 벡터를 나타냄– W≠0 일 경우– W = 0 일 경우
• point at infinity
– Use only non-negative w-values
![Page 33: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/33.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3333
Additional Clipping PlanesAdditional 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=0glClipPlane(GL_CLIP_PLANE0, eqn);glEnable(GL_CLIP_PLANE0);
![Page 34: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/34.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3434
Examples of Composing Examples of Composing Several TransformationSeveral Transformation
• Example 3-6. Planetary System
![Page 35: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/35.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3535
Examples of Composing Examples of Composing Several TransformationSeveral Transformation
• Example 3-7. Robot Arm
![Page 36: Viewing](https://reader034.fdocuments.us/reader034/viewer/2022051317/56815e01550346895dcc4624/html5/thumbnails/36.jpg)
Korea Univ. Computer Graphics Lab.Korea Univ. Computer Graphics Lab.3636
Reverse and Mimicking Reverse and Mimicking TransformationTransformation
• Example 3-8. Take and reverse