Overview of Projections: From a 3D world to a 2D screen. Lecturer: Dr Dan Cornford d.cornford@aston.ac.uk http://wiki.aston.ac.uk/dancornford CS2150, Computer Graphics, Aston University, Birmingham, UK http://wiki.aston.ac.uk/c2150 October 26, 2009 Dan Cornford 3D to 2D 1/18
Outline: 3D to 2D Projection in computer graphics. Types of projection. Viewing in OpenGL. Dan Cornford 3D to 2D 2/18
Projection Gets a bit mathematical (but not for a while). Central to computer graphics. 3D world coordinate output primitives Clip against view volume Project onto projection plane Transform to 2D device coordinates 2D device coordinates For now we will focus on the 3D to 2D part - transforming to device coordinates is relatively simple! Dan Cornford 3D to 2D 3/18
General projections projection plane A projection plane C A* B C* D projectors B* projectors D* centre of projection to infinity Perspective foreshortening is important to realism but results in distortion of angles, distances and parallel lines. Parallel projections also distort angles, but maintain parallelism and distances. Dan Cornford 3D to 2D 4/18
General projections Convert an nd coordinate system into a md coordinate system: in computer graphics 3D 2D. We consider planar geometric projections we project onto a plane. Projections can be visualised using projectors which emanate from the centre of the projection. The centre of projection is generally at a finite distance from the projection plane but is sometimes defined at infinity (parallel projections). Easy to implement (if not understand) using homogeneous coordinates. Dan Cornford 3D to 2D 5/18
Defining a plane? We need to define the projection plane how can this be done? projection plane A projection plane C A* B C* D projectors B* projectors D* centre of projection to infinity Dan Cornford 3D to 2D 6/18
Defining a plane? Most simple: define a point in the projection plane, and then two vectors, one for up and one for across. This allows us to define any (all) points in the plane. For computer graphics we normally give a point, a vector to define up and a normal vector to the plane (which is the cross product of the up and across vectors). Concept of normal vectors is very important in computer graphics. From Wikipedia Dan Cornford 3D to 2D 7/18
Perspective projections y Projection plane Center of projection z x Projection plane normal In a perspective projection all parallel lines that are not parallel to the projection plane appear to go to a vanishing point. Dan Cornford 3D to 2D 8/18
2 point perspective projections y Projection plane z x x-axis vanishing point z-axis vanishing point Center of projection The number of axis vanishing points will depend on the number of axes cut by the projection plane two point projections look realistic. Dan Cornford 3D to 2D 9/18
Parallel projections Parallel orthographic projections have the direction of the projection parallel to the normal to the projection plane: Projectors for top view Projection plane (top view) Projectors for side view Projection plane (front view) Projectors for front view Projection plane (side view) Dan Cornford 3D to 2D 10/18
Parallel projections Axonometric orthographic projections are parallel projections that use projection planes that are not normal to the principal axes. Projection plane y Projector Projectionplane normal x z Dan Cornford 3D to 2D 11/18
Parallel projections In oblique projection the projection plane normal and direction of projection differ. Projection plane y z Projector x Projection-plane normal This is quite unrealistic and not often used. Dan Cornford 3D to 2D 12/18
Viewing in OpenGL OpenGL viewing definition uses the camera analogy. Two matrices define the total projection: GL PROJECTION defines the projection using the matrices: MS per H par as given in the notes. Define the viewing window (x min, y min and x max, y max ), and the near and far clipping planes. Think of this like the lens of a camera. From glprogramming.com Use the command glfrustum to set the viewing / projection parameters. Dan Cornford 3D to 2D 13/18
Viewing in OpenGL The other matrix to set is the GL MODELVIEW matrix which controls both the objects and the view. This is like the matrices S par T par as given in the notes. Think of this like aiming the camera. From glprogramming.com Use glulookat with the eye, location to look at and up vectors to define the camera. Dan Cornford 3D to 2D 14/18
Practical viewing in OpenGL Easy to get lost in space: keep the far clipping plane to a large value changing the near clipping plane changes the degree of perspective distortion. Use asymmetric (x min, y min and x max, y max ) to achieve false perspective make VPN non-parallel to DOP. Start with a large front clipping plane: (x min, y min and x max, y max ) then focus in on the object. Set the viewport using glviewport and give the origin and width / height (keep the same as the aspect ratio of the front clipping plane. If it ain t broke don t fix it! Dan Cornford 3D to 2D 15/18
Viewing in OpenGL The OpenGL viewing pipeline looks like: x y z w World Coordinates model view matrix Eye Coordinates projection matrix perspective division /w Clip Coordinates Canonical View Volume window to viewport x y Screen Coordinates For both projection and model view matrices use glmatrixmode to define which to use and then don t forget to initialise them using glloadidentity. In the labs most of this is handled for you by the graphicslab class. From OpenGL tutors Dan Cornford 3D to 2D 16/18
Viewing in OpenGL Can also use parallel projections: use glortho to set the projection matrix. The model view matrix is set in the same way as before. Use glloadmatrix to define our own projection matrices (masochists only). Beware the difference between modelling and viewing transformations there is none in the code! Viewing transformations are always set first in the code, since they are applied last to all objects in the animated models. Dan Cornford 3D to 2D 17/18
Summary Having finished this lecture you should: understand what projection is in computer graphics; compare perspective and parallel projections; understand the applications of the different types of projections; define appropriate projections in OpenGL. We will look next at how projection is handled mathematically! Dan Cornford 3D to 2D 18/18