Graphics Viewing kucg korea ac kr Graphics Lab

Graphics Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg. korea. ac. kr Graphics Lab @ Korea University

Contents KUCG Projections in Open. GL n Parallel viewing n n n Perspective viewing n n Perspective projection Walk through a scene n n Orthographic projection Look-at function Shadow projection kucg. korea. ac. kr Graphics Lab @ Korea University

Projections in Open. GL n Angle of view n n KUCG only objects that fit within the angle of view of the camera appear in the image View volume be clipped out of scene n frustum – truncated pyramid n kucg. korea. ac. kr Graphics Lab @ Korea University

Parallel Viewing n KUCG Orthographic viewing function gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity( ); gl. Ortho(xmin, xmax, ymin, ymax, near, far); Open. GL provides only this parallel-viewing function n near < far !! no restriction on the sign zmax = – far zmin = – near n kucg. korea. ac. kr Graphics Lab @ Korea University

Orthographic Projection (1/3) n KUCG Direction of Projection Simple camera n View frustum – a right parallelepiped y n x void gl. Ortho(GLdouble GLdouble left, right, bottom, top, near, far) z kucg. korea. ac. kr Graphics Lab @ Korea University

Orthographic Projection (2/3) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Orthographic Projection (3/3) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Perspective Viewing (1/2) n KUCG Specification of a frustum gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity( ); gl. Frustum(xmin, xmax, ymin, ymax, near, far); n near, far: positive number !! zmax = – far zmin = – near kucg. korea. ac. kr Graphics Lab @ Korea University

Perspective Viewing (2/2) n KUCG Specification using the field of view gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity( ); glu. Perspective(fovy, aspect, near, far); fovy: the angle of view in the up (y) direction n aspect ratio: width divided by height n kucg. korea. ac. kr fov: angle between top and bottom planes Graphics Lab @ Korea University

Perspective Projection (1/5) n KUCG General Viewing n Projection plane – anywhere in front of the camera void gl. Frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) kucg. korea. ac. kr Graphics Lab @ Korea University

Perspective Projection (2/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

What’s Wrong? kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Change Look-At Position (1/2) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Change Look-At Position (2/2) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Perspective Projection (3/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Perspective Projection (4/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Perspective Projection (5/5) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Walking Though a Scene (1/2) void keys(unsigned { if(key == ‘x’) if(key == ‘X’) if(key == ‘y’) if(key == ‘Y’) if(key == ‘z’) if(key == ‘Z’) } KUCG char key, int x, int y) viewer[0] viewer[1] viewer[2] -= += 1. 0; void display(void) { gl. Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gl. Load. Identity(); glu. Look. At(viewer[0], viewer[1], viewer[2], 0, 0, 1, 0); gl. Rotatef(theta[0], 1. 0, 0. 0); gl. Rotatef(theta[1], 0. 0, 1. 0, 0. 0); gl. Rotatef(theta[2], 0. 0, 1. 0); colorcube( ); } gl. Flush( ); glut. Swap. Buffers( ); kucg. korea. ac. kr Graphics Lab @ Korea University

Walking Though a Scene (2/2) KUCG void my. Reshape(int w, int h) { gl. Viewport(0, 0, w, h); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity( ); if( w <= h ) gl. Frustum(-2. 0, -2. 0*(GLfloat)h/(GLfloat)w, 2. 0, 20. 0); else gl. Frustum(-2. 0 *(GLfloat)w/(GLfloat)h, -2. 0, 20. 0); gl. Matrix. Mode(GL_MODELVIEW); } kucg. korea. ac. kr Graphics Lab @ Korea University

Look-At Function n KUCG Open. GL utility function glu. Look. At(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz); n VRP: eye. Point n VPN: – ( at. Point – eye. Point ) n VUP: up. Point – eye. Point look-at positioning kucg. korea. ac. kr Graphics Lab @ Korea University

Definition of Eye Position kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Initialization of Eye Position kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Modification – Draw. Scene( ) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

On. Key. Down( ) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Result – Walking Though a Scene kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Exercise 1 n KUCG Create a menu ‘projection’ and its sub menus ‘orthographic’, and ‘perspective’. If you choose one, your program must change its projection. kucg. korea. ac. kr Graphics Lab @ Korea University

Projections & Shadows (1/2) KUCG Shadow polygon n Steps n light source at (xl, yl, zl) n translation (-xl, -yl, -zl) n perspective projection through the origin n translation (xl, yl, zl) n kucg. korea. ac. kr Graphics Lab @ Korea University
![Projections & Shadows (2/2) KUCG GLfloat m[16]; /* shadow projection matrix */ for(i=0; i<16; Projections & Shadows (2/2) KUCG GLfloat m[16]; /* shadow projection matrix */ for(i=0; i<16;](http://slidetodoc.com/presentation_image/5a60994d7c08f1c39f1434dbf2d6ae97/image-28.jpg)
Projections & Shadows (2/2) KUCG GLfloat m[16]; /* shadow projection matrix */ for(i=0; i<16; i++) m[i] = 0. 0; m[0] = m[5] = m[10] = 1. 0; m[7] = -1. 0/yl; gl. Color 3 fv(polygon_color); gl. Begin(GL_POLYGON); . . . gl. End( ); gl. Matrix. Mode(GL_MODELVIEW); gl. Push. Matrix( ); gl. Translatef(xl, yl, zl); gl. Mult. Matrixf(m); gl. Translatef(-xl, -yl, -zl); gl. Colorfv(shadow_color); gl. Begin(GL_POLYGON); . . . gl. End( ); gl. Pop. Matrix( ); kucg. korea. ac. kr /* draw the polygon normally */ /* /* save state */ translate back */ project */ move light to origin */ /* draw the polygon again */ /* restore state */ Graphics Lab @ Korea University

Draw. Scene( ) (1/3) kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
![Draw. Scene( ) (2/3) KUCG GLfloat light_pos[3] = { 0. 0, 10. 0, 0. Draw. Scene( ) (2/3) KUCG GLfloat light_pos[3] = { 0. 0, 10. 0, 0.](http://slidetodoc.com/presentation_image/5a60994d7c08f1c39f1434dbf2d6ae97/image-30.jpg)
Draw. Scene( ) (2/3) KUCG GLfloat light_pos[3] = { 0. 0, 10. 0, 0. 0 }, m[16]; for(register int i=0; i<16; i++) m[i] = 0. 0; m[0] = m[5] = m[10] = 1. 0; m[7] = (GLfloat)(-1. 0/light_pos[1]); gl. Push. Matrix(); gl. Translatef(light_pos[0], light_pos[1], light_pos[2]); gl. Mult. Matrixf(m); gl. Translatef(-light_pos[0], -light_pos[1], -light_pos[2]); gl. Color 3 f(0. 5, 0. 5); gl. Begin(GL_QUADS); // quad #1 gl. Vertex 3 fv(vertices[0]); gl. Vertex 3 fv(vertices[3]); gl. Vertex 3 fv(vertices[2]); gl. Vertex 3 fv(vertices[1]); // quad #2 gl. Vertex 3 fv(vertices[2]); gl. Vertex 3 fv(vertices[3]); gl. Vertex 3 fv(vertices[7]); gl. Vertex 3 fv(vertices[6]); kucg. korea. ac. kr Graphics Lab @ Korea University
![Draw. Scene( ) (3/3) KUCG // quad #3 gl. Vertex 3 fv(vertices[3]); gl. Vertex Draw. Scene( ) (3/3) KUCG // quad #3 gl. Vertex 3 fv(vertices[3]); gl. Vertex](http://slidetodoc.com/presentation_image/5a60994d7c08f1c39f1434dbf2d6ae97/image-31.jpg)
Draw. Scene( ) (3/3) KUCG // quad #3 gl. Vertex 3 fv(vertices[3]); gl. Vertex 3 fv(vertices[0]); gl. Vertex 3 fv(vertices[4]); gl. Vertex 3 fv(vertices[7]); // quad #4 gl. Vertex 3 fv(vertices[1]); gl. Vertex 3 fv(vertices[2]); gl. Vertex 3 fv(vertices[6]); gl. Vertex 3 fv(vertices[5]); // quad #5 gl. Vertex 3 fv(vertices[4]); gl. Vertex 3 fv(vertices[5]); gl. Vertex 3 fv(vertices[6]); gl. Vertex 3 fv(vertices[7]); // quad #6 gl. Vertex 3 fv(vertices[5]); gl. Vertex 3 fv(vertices[4]); gl. Vertex 3 fv(vertices[0]); gl. Vertex 3 fv(vertices[1]); gl. End(); gl. Pop. Matrix(); kucg. korea. ac. kr Graphics Lab @ Korea University

What’s Wrong? kucg. korea. ac. kr KUCG Graphics Lab @ Korea University

Exercise 2 n KUCG Fix your program kucg. korea. ac. kr Graphics Lab @ Korea University

Result – Shadow Projection kucg. korea. ac. kr KUCG Graphics Lab @ Korea University
- Slides: 34