Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics 3Practical Lesson

Similar presentations


Presentation on theme: "Computer Graphics 3Practical Lesson"— Presentation transcript:

1 Computer Graphics 3Practical Lesson
Viewing and Projection Ayal Stein

2 The Camera Analogy The transformation process to produce a scene for viewing is analogous to taking a photograph with a camera. 1. Setting the camera position is like viewing transformation

3 The Camera Analogy 2. Arrange the scene to be photographed is like modeling transformation. 3. Choose a camera lens or adjust the zoom (Projection transformation). 4. Determine final photograph size - for example, you might want it enlarged (Viewport transformation).

4 Viewing Transformations
Setting the position of the “camera”. In openGL, we use the command: void gluLookAt( GLdouble eyeX, GLouble eyeY,   Gldouble eyeZ,   GLdouble   centerX,   GLdouble   centerY,   GLdouble   centerZ,   GLdouble   upX,   GLdouble   upY,   GLdouble   upZ);

5 Viewing Transformations
This is the default status of the camera in OpenGL: 1. The eye vector is aimed at the negative z direction. 2. The position of the camera is at the beginning of the axis 3. The up vector is to the y axis.

6 Modeling Transformation
We discussed this process on the previous presentation. We will review the matrix stack again in this presentation.

7 The matrix stack The stack contains matrices of transformation on the model ( translate , rotate , resize ). In addition , there is current matrix which all transformation operations are applied on it. On each shape drawn – all the transformation of shapes in matrix and current matrix are applied on it.

8 The matrix stack(cont’)
glPushMatrix() pushes the current matrix into the queue. glPopMatrix() Extract matrix from the stack

9 Drawing Robot Example First we rotate the entire model according to user rotation. Before starting drawing any component, we call the glPushMatrix() to save the previous transformation. When we finish drawing the component, we call glPopMatrix() to restore previous transformations.

10 Projection transformation
There are 2 modes for projection: 1. Orthographic projection – the viewing area of the model is a cubic region. Each object will appear at the same size, regardless to its distance to the camera. 2. Perspective view – more realistic, like the human vision- the closer the object to the camera, the larger it will appear.

11 Orthographic projection
Used in CAD designing and 2d games/graphics. The viewing area of the model is a cubic region described in the following image:

12 Orthographic projection(cont’)
Setting orthographic projection: void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); The function receives 6 parameters Near and far is the distance from the camera.

13 Perspective projection
There are 2 function to create this projection. glFrustum: void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far); Show thing that exists in the pyramid between the plains near and far.

14 cont’))Perspective projection
gluPerspective: void gluPerspective( GLdouble   fovy, GLdouble   aspect, GLdouble   zNear, GLdouble   zFar); Fovy is the angle of the camera. Aspect is the ratio between x and y axis

15 cont’))Perspective projection
Both functions has the same effect. glFrustum is part of OpenGL gluPerspective is part of the extension library GLUT. glFrustum requires explicit dimension while gluPerspective requires angle and aspect ratio only. gluPerspective allows create asymmetric viewing area, which can be useful to some cases.

16 Viewport Transformation
Viewport transformation maps the view plane onto an area of the screen. void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); x,y specifies the lower left corner of the viewport. width and height are the size of the viewport rectangle


Download ppt "Computer Graphics 3Practical Lesson"

Similar presentations


Ads by Google