Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 

Similar presentations


Presentation on theme: "Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 "— Presentation transcript:

1 Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 d.england@livjm.ac.uk  http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl/Teaching/cmscd2012/ http://java.cms.livjm.ac.uk/homepage/staff/cmsdengl/Teaching/cmscd2012/  Web page includes: announcements, handouts, web links, reading hints, frequently asked questions

2 Lecture 6: 3D graphics Concepts 2 Misc Info  Misc. functions  glPostRedisplay() - forces redrawing of the screen without waiting for a window event  glPrint(x,y,string) wraps up the output() function and uses the font variable as in L:\cd2012\bitfont.cpp  Draws a string starting at x,y

3 Lecture 6: 3D graphics Concepts 3 Today’s Lecture: 3D concepts  Coursework 1: Any questions, ask me in the Lab  Today: 3D graphics concepts  Cues to the dept of a scene  Perspective  Hidden line and surface removal  3D shapes and surfaces  Viewpoints  Lighting  Shading  Texture and Materials  An example program, cube.cpp will demonstrate some of these (see code in L:\CD2012)

4 Lecture 6: 3D graphics Concepts 4 Perspective  The idea of perspective - that distant objects look proportionally smaller - was discovered by artists in the 16th Century  Perspective is used in 3D computer graphics to give an impression of depth and of distance from the viewer

5 Lecture 6: 3D graphics Concepts 5 Perspective in OpenGL  In OpenGL we can specify  Perspective viewing or  Orthographic viewing  The later is useful for architectural models with no reduction in size with depth glMatrixMode(GL_PROJECTION); gluPerspective( /* field of view in degree */ 40.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 10.0); glMatrixMode(GL_MODELVIEW);

6 Lecture 6: 3D graphics Concepts 6 Hidden Line/Surface Removal  In 2D graphics we can pretend another object is in front of another simply by drawing them in the right order  In 3D graphics we need to determine which pixels of a line or surface might be behind another - the pixels are sorted along the Z axis (Z buffering).  glEnable(GL_DEPTH_TEST) will hide hidden pixels

7 Lecture 6: 3D graphics Concepts 7 Lighting  The human vision system also uses the way light reflects off objects to work out their position and orientation  In 3D computer graphics we can set up different kinds of lighting and model the way the light is reflected off the surfaces of objects  In OpenGL and other 3D libraries we can create different kinds of lights and set their properties  Types: Ambient, Diffuse, Spotlight  Properties: Position, orientation, intensity, colour  Properties can be changed in real-time to give animation and other special effects  How is this lecture room illuminated?

8 Lecture 6: 3D graphics Concepts 8 Shading  Objects can be shaded by calculating the surface normal and then calculating the amount of light that is reflected.  Pixel colours are recalculated.  We can also specify flat shading or smooth shading

9 Lecture 6: 3D graphics Concepts 9 Shading ….  In the example program you can rotate the object to see the shading change  The program uses the keys() function to rotate the object around the x, y and Z axes  Looking at the code can you tell how each keyboard input rotates the object?

10 Lecture 6: 3D graphics Concepts 10 Viewpoints  Once we have lit an object and specified the perspective we can then position the viewpoint of the camera or human viewer  Viewpoints are specified by  The x,y,z position of the eye  Where the centre of the world is  The orientation of the eye  For example gluLookAt(0.0, 0.0, 5.0, /* eye is at (0,0,5) */ 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.); /* up is in positive Y direction */

11 Lecture 6: 3D graphics Concepts 11 Viewpoints ….  We can specify multiple viewpoints and swap between them to get different views of the scene  Or we could animate the viewpoint to give the impression that the user is moving  We could  Animate along X and Z to give a walking motion  Animate along X, Y and Z to give a flying motion  Animate around an axis to rotate the world  Animate around an object to rotate the object

12 Lecture 6: 3D graphics Concepts 12 3D shapes and surfaces  We have seen how 2D shapes can be drawn by specifying the vertices or corners of the shape  We then say how the corners are joined and the shape filled in with the argument to glBegin()  For 3D shapes we specify each vertex as a point in 3D space using the x, y and z values  Additionally GLUT has functions for drawing  Cube, Torus, Sphere, Cone, Teapot and other 3D objects

13 Lecture 6: 3D graphics Concepts 13 Cube.cpp example  The example program listed in cube.cpp (L:\cd2012\cube.cpp) draws a red 3D cube rotated slightly. It is lit by a diffuse light located in the top right of the scene  The cube is drawn by calls to glVertex3fv() which takes an array of points to define each face of the cube  The perspective is then set up  The eye is then positioned  The objected is then translated and rotated to give a better view  Finally keys() has been added to show the effect of rotation under a light.

14 Lecture 6: 3D graphics Concepts 14 Next Week  Reading week:  No lecture or lab next week  Continue with the coursework  Future weeks  More on interaction  Look more at the concepts of 3D graphics


Download ppt "Lecture 6: 3D graphics Concepts 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271 "

Similar presentations


Ads by Google