Transformation Pipeline Local (Object) Space Modeling World Space Clip Space Projection Eye Space Viewing Perspective divide NDC space Normalized l d Device Coordinatesd Viewport mapping Screen space
Coordinate system A coordinate system is used to unambiguously represent a point It contains a reference point (the origin) and three linearly independent vectors (the basis) v3 v2 O v1
Screen Coordinate System Glut OpenGL (0,0) 0)
Screen Coordinate System - 2D Regular Cartesian Grid - Origin (0,0) at lower left corner (OpenGL convention) - Horizontal axis x Vertical axis y - Pixels are defined at the grid intersections (0,0) - This coordinate system is defined relative to the display window origin (OpenGL: the lower left corner of the window) (2,2) y x
Local Coordinate System Screen coordinate system is not very useful for displaying 3D objects You also do not necessarily know where the object is going to be placed in the end in the 3D world Solution: define the positions of the vertices relative to its own center Local coordinate system z y z y x x
Simple OpenGL code OpenGL 1.1 convention, the goal here is to show you the idea void display() { glclearcolor(0,0,1,1);,, glclear(gl_color_buffer_bit); glcolor4f(1,1,0,1); //glcolor* have been deprecated in OpenGL 3 glbegin(gl_triangles); //glbegin/end have been deprecated in OpenGL 3 glcolor4f(1,1,0,1); l 4f(1101) glvertex4f(vertices[0], vertices[1], vertices[2], vertices[3]); glvertex4f(vertices[4], vertices[5], vertices[6], vertices[7]); glvertex4f(vertices[8], vertices[9], vertices[10], vertices[11]); glcolor4f(1,0,0,1); glvertex4f(vertices[12], vertices[13], vertices[14], vertices[15]); glvertex4f(vertices[16], vertices[17], vertices[18], vertices[19]); glvertex4f(vertices[20], vertices[21], vertices[22], vertices[23]); glend(); float vertices[] = {-0.5, -0.5, 0.0, 1.0, // first triangle -0.5, 0.5, 0.0, 1.0, 05 0.5, 0.5, 05 0.0, 00 1.0, 10 0.5, 0.5, 0.0, 1.0, // second triangle 0.5, -0.5, 0.0, 1.0, -0.5, -0.5, 0.0, 1.0}; glutswapbuffers(); }
World Coordinate System Local coordinates along do not allow you to specify where the object will be placed position, size, orientation Transformations need to be performed to position the object in the world coordinate system This is done through an arbitrary number of affine s (translation, rotation, scaling) applied to each vertex or =
Modeling Transformation The from local to world coordinates The matrix used is called modeling matrix A modeling is a sequence of translations, rotations, scalings (in arbitrary order) matrices multiplied together More detail to come in the next lecture
Transformation Pipeline Local (Object) Space Modeling World Space Clip Space Projection Eye Space Viewing Perspective divide NDC space Normalized l d Device Coordinatesd Viewport mapping Screen space
Simple OpenGL code void display() { glclearcolor(0,0,1,1); OpenGL 1.1 convention, the goal here is to show you the idea glclear(gl_color_buffer_bit); glcolor4f(1,1,0,1); //glcolor* have been deprecated in OpenGL 3 glmatrixmode(gl_modelview); glloadidentity(); glrotatef(45, 0,0,1); float vertices[] = {-0.5, -0.5, 0.0, 1.0, // first triangle -0.5, 0.5, 0.0, 1.0, 05 0.5, 0.5, 05 0.0, 00 1.0, 10 0.5, 0.5, 0.0, 1.0, // second triangle 0.5, -0.5, 0.0, 1.0, -0.5, -0.5, 0.0, 1.0}; More detail about what happens behind the scene will be explained glbegin(gl_triangles); //glbegin/end have been deprecated in OpenGL 3 glcolor4f(1,1,0,1); glvertex4f(vertices[0], vertices[1], vertices[2], vertices[3]); glvertex4f(vertices[4], e ti e vertices[5], e vertices[6], e vertices[7]); e glvertex4f(vertices[8], vertices[9], vertices[10], vertices[11]); glcolor4f(1,0,0,1); glvertex4f(vertices[12], vertices[13], vertices[14], vertices[15]); glvertex4f(vertices[16], vertices[17], vertices[18], vertices[19]); glvertex4f(vertices[20], vertices[21], vertices[22], vertices[23]); glend(); glutswapbuffers(); }
Viewing Local (Object) Space Modeling World Space Clip Space Projection Eye Space Viewing Perspective divide NDC space Normalized l d Device Coordinatesd Viewport mapping Screen space
Viewing Transformation Convert from the world coordinate system to the camera (eye) coordinate system The camera position is the origin i Derive the basis from the direction and orientation of fthe camera This makes the later s easier y world z v coi x u n Eye coordinate frame
Viewing Transformation Head tilt: Rotate your head by Just rotate the object about the eye space z axis - Mw2e = y v u n (ex,ey,ez) ey ez) x z
ModelView Transformation Modeling and Viewing s concatenated together M L2E (or, GL_MODELVIEW matrix) = void display() { glclear(gl_color_buffer_bit); glmatrixmode(gl_modelview); glloadidentity(); glulookat(0,0,1,0,0,0,0,1,0); display_all(); // your display routine } = M glloadidentity(); L2E fixed function pipeline OpenGL
Viewing Local (Object) Space Modeling World Space Clip Space Projection Eye Space Viewing Perspective divide NDC space Normalized l d Device Coordinatesd Viewport mapping Screen space
Projection Transformation Projection map the object from 3D space to 2D screen z y z y x x Perspective: gluperspective() Parallel: glortho()
Projection Transformation Maps (projects) everything in the visible volume into a canonical view volume (xmax, ymax, -far) (1, 1, -1) (xmin, ymin, -near) glortho(xmin, xmax, ymin, ymax, near, far) (-1, -1, 1) Canonical View Volume
Projection Transformation Maps (projects) everything in the visible volume into a canonical view volume (1, 1, -1) y z x (-1, -1, 1) (-1, -1) Z=1 z= -1 Canonical View Volume gluperspective(fovy, aspect, near, far)
Projection Transformation Projection Matrix glfrustum(xmin, xmax, ymin, ymax, N, F) N = near plane, F = far plane
Viewing Local (Object) Space Modeling World Space Clip Space Projection Eye Space Viewing Perspective divide NDC space Normalized l d Device Coordinatesd Viewport mapping Screen space
Viewport The rectangular region in the screen for displaying the graphical objects defined in the world window Defined in the screen coordinate system V_T glviewport(int left, int bottom, int (right-left), int (top-bottom)); V_B call this function before drawing V_L V_R (calling glbegin() and glend() )