Computer Graphics Basic 3D Programming September 21, 2005 Sun-Jeong Kim 1 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Contents Cameras and objects Perspective projections Orthographic projections Viewing a cube Locating the camera Building objects Hidden surface removal Rotating a color cube Exercise Sun-Jeong Kim 2 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Cameras and Objects (1/3) Projection synthetic camera model projectors, center of projection, projection plane Sun-Jeong Kim 3 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Cameras and Objects (2/3) Projection plane moved in front of the camera Sun-Jeong Kim 4 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Cameras and Objects (3/3) View frustum degree of freedom six parameters truncated pyramid clipping volume Sun-Jeong Kim 5 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Perspective Projections General viewing projection plane anywhere in front of the camera void glfrustum(gldouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) Sun-Jeong Kim 6 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Orthographic Projections (1/2) Direction of projection simple camera view frustum a right parallelepiped y x void glortho(gldouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) z Sun-Jeong Kim 7 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Orthographic Projections (2/2) Sun-Jeong Kim 8 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Viewing a Cube (1/3) GLUT Library glut.h (include), glut32.lib (lib), glut32.dll (system32) void glutwirecube(gldouble size) void glutsoildcube(gldouble size) Sun-Jeong Kim 9 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Viewing a Cube (2/3) Sun-Jeong Kim 10 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Viewing a Cube (3/3) Sun-Jeong Kim 11 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Result Viewing a Cube Sun-Jeong Kim 12 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Locating Camera (1/2) Setting position and orient of the camera within the world coordinate system eye point, at point, up vector void glulookat(gldouble eyex, GLdouble eyey, GLdouble eyez, GLdouble atx, GLdouble aty, GLdouble atz, GLdouble upx, GLdouble upy, GLdouble upz) Sun-Jeong Kim 13 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Locating Camera (2/2) Sun-Jeong Kim 14 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Result Locating Camera Sun-Jeong Kim 15 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Building Objects (1/5) Using arrays typedef Glfloat point3[3]; point3 vertices[8][3] = { { -1, -1, 1 }, { -1, 1, 1 }, { 1, 1, 1 }, { 1, -1, 1 }, { -1, -1, -1 }, { -1, 1, -1 }, { 1, 1, -1 }, { 1, -1, -1 } }; GLfloat colors[8][3] = { { 0, 0, 1 }, { 0, 1, 1 }, { 1, 1, 1 }, { 1, 0, 1 }, { 0, 0, 0 }, { 0, 1, 0 }, { 1, 1, 0 }, { 1, 0, 0 } }; 5 6 1 2 Quad(0, 3, 2, 1); Quad(1, 2, 6, 5); Quad(2, 3, 7, 6); Quad(3, 0, 4, 7); Quad(4, 5, 6, 7); Quad(5, 4, 0, 1); 4 7 0 3 Sun-Jeong Kim 16 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Building Objects (2/5) Sun-Jeong Kim 17 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Building Objects (3/5) Sun-Jeong Kim 18 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Building Objects (4/5) Sun-Jeong Kim 19 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Result Building Objects (1) Sun-Jeong Kim 20 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Building Objects (5/5) Sun-Jeong Kim 21 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Result Building Objects (2) Sun-Jeong Kim 22 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Note Display List (1/2) Immediate mode: standard in OpenGL primitives are no longer in the system after passing through the OpenGL pipeline when redrawing the screen, we have to regenerate the primitives time consuming Retained mode display lists in OpenGL collections of primitives and other information can be stored avoiding costly regeneration problem Sun-Jeong Kim 23 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Note Display List (2/2) Steps creating a new display list void glnewlist(gluint name, GLenum mode); void glendlist(); mode: GL_COMPILE, GL_COMPILE_AND_EXECUTE executing a display list void glcalllist(gluint name); deleting a display list display list cannot be changed!! void gldeletelists(gluint first, GLsizei number); Sun-Jeong Kim 24 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Hidden Surface Removal (1/2) Z-Buffer Algorithm depth buffer extra storage to store depth information Sun-Jeong Kim 25 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Hidden Surface Removal (2/2) Sun-Jeong Kim 26 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Rotating a Cube Sun-Jeong Kim 27 http://www.hallym.ac.kr/~sunkim/teach/2005/cga Result Rotating a Cube Sun-Jeong Kim 28 http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Exercise Rotate a cube in the reverse direction when the left button of a mouse is clicked Change the axis of the rotation when the following keys are pressed: x or X : the x-axis rotation y or Y : the y-axis rotation z or Z : the z-axis rotation Sun-Jeong Kim 29 http://www.hallym.ac.kr/~sunkim/teach/2005/cga