OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL...

17
OpenGL The Viewing Pipeline: • Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D geometry. • Processes can be broken up into four main areas: 1.The movement of the object is called a modeling transformation. 2.The movement of the camera is called a viewing transformation. 3.The conversion from 3D to 2D is called a projection

Transcript of OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL...

Page 1: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

OpenGL

The Viewing Pipeline:

• Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D geometry.

• Processes can be broken up into four main areas:

1.The movement of the object is called a modeling transformation.

2.The movement of the camera is called a viewing transformation.

3.The conversion from 3D to 2D is called a projection transformation.

4.The 2D picture plane, which is mapped to the screen viewport, called a viewport transformation.

Page 2: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

The Camera Analogy

Modeling: positionmodel

positionmodel

Viewing: position camera

positionviewing volume

Projection: chooselens

choosevv shape

Viewport: choose photo size

chooseportion of screen

Camera OpenGL

Page 3: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Viewing Pipeline & OpenGL

• Can also be thought of as a production line.

• Matrix operations are foundation of pipeline.

• Pipeline transforms vertices (coordinates).

Page 4: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Viewing Pipeline & Coordinates

Pipeline transforms vertices (coordinates)

object eye clip ndc window

modelviewmatrix

projectionmatrix

perspectivedivision

viewport

Coordinate systems are key to computer graphics!

Page 5: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

The Model Coordinates and Transformations

• The coordinates we specify using the glVertex* commands are the model coordinates.

• The glRotate, glTranslate and glScale commands are used to transform the model into the desired orientation and size.

• These operations are applied to the modelview matrix.

• We did these matrix transformations as an exercise and in test 1.

• OpenGL does them for us using one-liners (thank goodness).

• After applying the modeling transformations to the model coordinates what we get are world coordinates.

Page 6: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

The Model Coordinates and Transformations

To begin transformation of this matrix, we need to specify it in the matrix mode function, then initialize the matrix to the Identity matrix, and perform your transformations thereafter:

Page 7: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Overview

Page 8: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

The Camera Coordinates and Viewing Transformation

• The next step is to convert the world coordinates into camera coordinates.

• For this we use: gluLookAt(eyeX, eyeY, eyeZ, referX, referY, referZ, upX, upY, upZ);

• This performs translations and rotations to transform a point from world coordinates to camera coordinates. So the matrix generated is a combination of translation and rotation matrices.

• The default OpenGL viewpoint is located at the origin, looking down the negative Z axis.

• Two options: The geometry that we wish to view must either be moved to a position from which it can be seen from the default viewpoint, or the viewpoint must be moved so that it can see the geometry.

• eyeX, eyeY, eyeZ represents the viewpoint.• referX, referY, referZ represents a point along the desired line of sight.• upX, upY, upZ represents the view up vector.

Page 9: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

The Camera Coordinates and Viewing Transformation

Note that although the modeling and viewing transformations can be considered logically separateoperations, OpenGL concatenates all of the modeling and viewing transformations into a single matrix(i.e. the ModelView Matrix)

• Panning or Tilting: move reference point horizontally or vertically.

Page 10: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Overview

Page 11: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Projection Transformation• After applying the modelview matrix OpenGL must now take the camera coordinates

to the image space. This is done using the projection transformation.

• Two types of projection: Orthographic and Perspective

• Each of these transformations defines a volume of space called a frustum.

• Only geometry that is inside of the frustum is displayed on the screen. Any portion of geometry that is outside of the frustum is clipped.

Page 12: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Projection Transformation

Orthographic:

• Maps objects directly onto the screen without

affecting their relative size.

• Given by: glOrtho(left, right, bottom, top, near, far);

• Defines a rectangular parallelepiped frustum (a box).

• Creates a matrix for an orthographic parallel viewing volume and multiplies the current matrix by it. (left, bottom, -near) and (right, top, -near) are points on the near plane that are mapped to the lower-left and upper-right corners of the viewport window, respectively. (left, bottom, -far) and (right, top, -far) are points on the far plane that are mapped to the same respective corners of the viewport. Both near and far can be positive or negative. The direction of projection is parallel to the z-axis, and the viewpoint faces toward the negative z-axis.

Page 13: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Projection TransformationPerspective:

• Makes objects that are farther away appear smaller.

• Given by: gluPerspective(fov, aspect, near, far);

• Creates a matrix for a symmetric perspective-view frustum and multiplies the current matrix by it. fovy is the angle of the field of view in the x-z plane; its value must be in the range [0.0,180.0]. aspect is the aspect ratio of the frustum, its width divided by its height. Near and far values are the distances between the viewpoint and the clipping planes, along the negative z-axis.

Page 14: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Overview

Page 15: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Clipping and Perspective Divison

• Steven’s section

Page 16: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Viewport Transformation• Determines the size of the rendered image.

• By default the viewport is set to the entire pixel rectangle of the window.

• The glViewport(GLint x, GLint y, GLsizei width, GLsizei height); command can be used to choose a smaller drawing region.

• The viewport aspect ratio should be the same as that of the view frustum or the image appears distorted.

• The 2D picture plane from the previous transformation forms the world coordinate window, which can be mapped to the screen viewport, which ends up on our screen.

Page 17: OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.

Code Execution OrderSince the order of the transformations is significant, we want to invoke the

OpenGL functions in the proper order, i.e. in the reverse order in which they

will be applied: