Viewing
Viewing Process first part : model-view in Chapter 4 second part : projection in Chapter 5 world frame glmatrimode(gl_modelveiw) glmatrimode(gl_projection) camera frame camera 방향 object frame
5. Classical and Computer Viewing
Viewing classical viewing hand drawing 에서발전 basic components object a viewer (COP) projector projection plane COP : center of projection 3
Viewing perspective viewing finite COP center of projection parallel viewing infinite COP DOP direction of projection 4
Classical Viewings hand drawing 에서발전 5
Orthographic Projection parallel projection 의일종 also known as orthogonal projection projector 가 projection plane에수직 projection plane은 object에수직 multi-view orthographic projection 개의 parallel projection 은정보전달에한계 건축용도면에서많이사용 length and angle preserving 6
Aonometric Projections parallel projection 의일종 projector 가 projection plane에수직 그러나, projection plane 자체가기울어짐 단점 : distortion 발생가능 7
Aonometric Projections isometric view : 3 개 ais 에 smmetric dimetric view : 2 개 ais 에 smmetric trimetric view : general case 8
Oblique Projection parallel projection 의일종 projector 와 projection plane 이서로기울어진각도 distortion 발생 9
Perspective Projection 르네상스시대에사실주의화풍에서유래 vanishing point ( 소실점 ) projector 들이모이는점 classical viewing 에서는 three-point perspective two-point perspective one-point perspective computer graphics 에도입
5.2 Positioning of the Camera
3D Viewing camera 를흉내낸다 film displa screen 물체 바늘구멍사진기 2
Camera Positioning initial camera position in OpenGL at the origin of the world frame, to direction camera movement reverse movement of the objects gltranslatef(.,., ); 3
Camera Positioning another eample : rotated camera glmatrimode(gl_modelview); glloadidentit( ); gltranslatef(.,., ); glrotatef( 9.,.,.,.); object 입장 : -9도회전, - 이동 camera 입장 : 이동, 9도회전 4
Viewing API s general viewing API : PHIGS, GKS-3D approach PHIGS, GKS-3D : famous graphics librar camera를어떻게설정할것인가? VRP (view reference point) : 3D point. camera 의위치 VPN (view plane normal) : view plane 의방향을결정 VUP (view up vector) : camera film 의윗방향을결정 view reference point view-up vector V view-plane normal vector N 5
Viewing Coordinate world frame 과 camera frame 의관계 w w v View Plane w v V v world coordinate sstem N U view coordinate sstem View Reference Point 6
Viewing Matri 의계산 V : viewing matri world frame 의점 q 를 camera frame 으로변환 p : VRP, n : (normalied) VPN, v : (normalied) VUP view q world q V 7 p : VRP, n : (normalied) VPN, v : (normalied) VUP in world frame p 2 2 2 + + n n n n n n n 2 2 2 + + v v v v v v v
Viewing Matri 의계산 제약조건들 u n world world v world (,,) view V p (,,) view V n view (,,) view V v (,,) view V u world world world world v V v U View Plane v N View Reference Point view coordinate sstem 8
Viewing Matri 의계산 정리하면, T 9 world view q R T q R n n n v v v u u u world view q V q V n n n v v v u u u
Look-At Function OpenGL approach 직접 viewing matri 설정도가능 V 계산후, glloadmatri( ) 다른방법 : glulookat( ) 함수 점 (ee, ee, ee ) 에서, 점 (at,at, at ) 를본다 (look at). 필름의윗방향은 (up, up, up ) 와유사 2
Look-At Function glulookat(gldouble ee, ee, ee, GLdouble at, at, at, GLdouble up, up, up); 모두 world frame 기준으로좌표입력 VRP (ee, ee, ee) VPN (at, at, at) (ee, ee, ee) VUP : (up, up, up) 의방향보정 normalie는자동으로수행 2
Roll-Pitch-Yaw Approach 주로 flight simulator 에서사용 roll : 좌우동, 축기준의회전각 pitch : 상하동, 축기준의회전각 aw : 편요각, 축기준의회전각 3 개의 rotation 으로 viewing matri 설정 필요하면, 개의 translation 추가 ( 비행기위치 ) 22
Polar Coordinate Approach 주로지상관측모델에서사용 예 : 게임의대공포사격 aimuth ( 방위각 ) : 평면에서의회전각 elevation ( 양각 ) : 위로올라간각도 2 개의 rotation matri 로구현가능 23
5.3 Simple Projections
Parallel & Perspective Projection parallel projection vector 에평행한 projection A A perspective projection B B point 를향한 projection projection plane A center of projection A B B projection plane 25
Perspective Projection perspective projection 의구현방법? (,, ) ( p, p, p ) 비례관계에따라, : p : d : p : d <, d < 계산하면, Projection Plane d d (,,) Center of Projection p p p / d / d d 26
Perspective Projection homogeneous coordinate 에의한계산 w d w d p p / / 27 d d w d w w d p p p / / / / d d d homogeneous coordinate 이므로,
Perspective Devision perspective projection 의경우는 OpenGL pipeline 의끝에서처리 homogeneous coordinate 의 w 값을 로만듬 자동계산! 28 / d d / / d d d transform 들을수행
Orthogonal Projections parallel projection 들중에서, orthogonal projection 은구현이쉬움 p 29 p p p p p
5.4 Projections in OpenGL
Perspective Projection in OpenGL perspective projection 을설정하는방법? angle of view (field of view, FOV) : 보이는각도 view volume, view frustum : 실제로보이는공간 3
Perspective Projection in OpenGL glfrustum(gldouble min, ma, GLdouble min, ma, GLdouble near, far); 주의 : near, far 는 positive 여야함 min near, ma far ( ma, ma, near ) ( min, min, near ) 32
Perspective Projection in OpenGL gluperspective(gldouble fov, aspect, near, far) fov : field of view in -direction, in degree aspect : width / height 33
Parallel Projection in OpenGL glortho(gldouble min, ma, min, ma, min, ma); ( ma, ma, ma ) ( min, min, min ) 34
5.5 Hidden-Surface Removal
Hidden Surface Removal remove surfaces that should not be visible to the viewer object-space approaches 기본아이디어 : sort the polgons image-space approaches 기본아이디어 : piel 단위처리 -buffer algorithm visible surface algorithm, visible surface detection find which surfaces are visible 결국같은 algorithm. 결과만반대로해석 36
Hidden Surface Removal Z-buffer algorithm OpenGL의기본적인 hidden surface removal 방법 구현이쉽고, video card 에서지원하는경우가많다 glutinitdisplamode(glut_rgb GLUT_DEPTH); glenable(gl_depth_test); glclear(gl_depth_buffer_bit); 겹치는부분에서, < 2 이므로, 더가까운원이출력된다. 37
5.6 Walking through a scene
Eample : cubeview.c chap 4. 의 cube program 에기능추가 camera 위치 : GLdouble viewer[3]; glulookat( ) 사용 keboard callback 추가,, 키에따라, camera 위치이동 perspective view 지원 glfrustum( ) 사용 39
Eample : cubeview.c keboard callback void kes(unsigned char ke, int, int ) { /* Use, X,, Y,, and Z kes to move viewer */ if (ke '') viewer[].; } if (ke 'X') viewer[] +.; if (ke '') viewer[].; if (ke 'Y') viewer[] +.; if (ke '') viewer[2].; if (ke 'Z') viewer[2] +.; displa( ); 4
Eample : cubeview.c displa callback 수정 void displa(void) { glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glloadidentit(); glulookat(viewer[],viewer[],viewer[2],.,.,.,.,.,.); } glrotatef(theta[],.,.,.); glrotatef(theta[],.,.,.); glrotatef(theta[2],.,.,.); colorcube(); glflush(); glutswapbuffers(); 4
Eample : cubeview.c reshape callback : perspective projection setting 필요 void mreshape(int w, int h) { glviewport(,, w, h); glmatrimode(gl_projection); glloadidentit(); if (w<h) glfrustum(-2., 2., -2. * (GLfloat) h/ (GLfloat) w, 2.* (GLfloat) h / (GLfloat) w, 2., 2.); else glfrustum(-2., 2., -2. * (GLfloat) w/ (GLfloat) h, 2.* (GLfloat) w / (GLfloat) h, 2., 2.); glmatrimode(gl_modelview); } 42
5.7 Parallel Projection Matrices
Projection Normaliation orthogonal projection 은계산이가장간단 다른 projection 을처리할때, 물체자체를 distortion 한후, orthogonal projection 하면같은결과가나온다 transform pipeline 에서, 이런방법도사용 단, distortion matri 는계산해야! 44
Canonical View Volume orthogonal projection 의기준형태 6 개의 plane 으로정의 ±, ±, ± 왜사용하나? algorithm 개발, video card 구현시에편리 OpenGL 에서도 projection 의마지막단계는 canonical view volume 45
glortho( ) 의구현 OpenGL 의내부구현관점에서는 우선 canonical view volume 으로바꾼후에알고리즘들을적용해야 glortho(min, ma, min, ma, near, far); 비례관계에의한계산필요! (,, ) (,,) 46
glortho( ) 의구현 2 step approach 중심을원점으로 translate 전체길이를 2 로 scaling ma+ min ma+ min ma+ min T(,, ) 2 2 2 2 2 2 S(,, ) ma P S T min ma ma 2 min min ma ma 2 min min ma 2 min ma ma ma + 2 + 2 + 2 min min min 47
Oblique Projections projector 가 projection plane에 orthogonal 하지않음 문제점 : 대부분의 graphics package가지원하지않음 해결책 : 계산방법을따로주어야! 보통, shearing H + orthogonal P 로구현 48
Oblique Projections projection 각도를계산 θ : 축과의각도 φ : 축과의각도 θ φ tan θ 49 shearing matri H(θ, φ) cot cot p p p p φ θ cot cot ), ( φ θ φ Hθ
Oblique Projections 전체과정 5 cot cot ), ( orth φ θ φ Hθ P P
5.8 Perspective Projection Matrices
Perspective Normaliation perspective projection 에서도 normaliation projection plane : min, ma 경계평면 : ±, ± (,, min ) (,, min ) 52
Perspective Normaliation perspective normaliation matri N 최종결과 : P P orth N 53 P orth N P N β α
Perspective Normaliation P orth N 에의한 transform 결과 see Tet for more details ± ± min ma ± ± β ( α+ min β ( α+ ma ) ) α β ma ma 2 ma + ma min min min min 54
OpenGL Perspective Transform glfrustum( ) : asmmetric frustum 가능! shearing H(cot θ,cot φ) and scaling 으로해결 H(cotθ,cotφ) H( S( 2 ma min P NS H min 2 see Tet for more details, ma min 2 min + min min ma,, ) min min + 2 min ma ) 55
5.9 Projections and Shadows
Shadow Generation shadow : realistic image 를위해필수적 제대로생성하기는까다롭다 a simple approach projection onto a plane film 에 projection 하는과정과유사 light source ( 광원 ) 평면에의 projection 57
Shadow Generation ( l, l, l ) : 광원의위치 : shadow 가맺힐평면 step : translate( l, l, l ) step 2: projection matri M 원점이 COP 로 projection M step 3: draw the polgon step 4: translate( l, l, l ) l 58