Viewing with Computers (OpenGL)

advertisement

Computer Graphics Viewing with Computers (OpenGL)

Viewing with Computers (OpenGL)

We can now return to three-dimension?', graphics from a computer perspective.

Because viewing in computer graphics is based on the synthetic-camera model, we should be able to construct any of the classical views. However, there is a fundamental difference. All the classical views were based on a particular relationship among the objects, the viewer, and the projectors. In computer graphics, we stress the independence of the object specifications and camera parameters.

In terms of the pipeline architecture, viewing consists of two fundamental operations. First, we must position and orient the camera. This operation is the job of the model-view transformation. After vertices pass through this transformation, they are represented in eye or camera coordinates. The second step is the application of the projection transformation.

OpenGL starts with the camera at the origin of the object frame, pointing in the negative z-direction. This camera is set up for orthogonal views and has a viewing volume that is a cube, centered at the origin and with sides of length 2. The default projection plane is the plane z = 0 and the direction of the projection is along the z-axis.

Thus, objects within this box are visible and projected.

Positioning of the Camera

In OpenGL, the model-view and projection matrices are concatenated together to form the matrix that applies to geometric entities such as vertices. We have seen one use of the model-view matrix—to position objects in space. The other is to convert from the object frame to the frame of the camera.

Initially, the model-view matrix is an identity matrix, so the camera frame and the object frame are identical. In OpenGL, the camera is initially pointing in the negative z-direction (Figure 9.1). In most applications, we model our objects as being located around the origin, so a camera located at the default position with the default orientation does not see all the objects in the scene. Thus, either we must move the camera away from the objects that we wish to have in our image, or the objects must be moved in front of the camera. These are equivalent operations, as either can be looked at as positioning the frame of the camera with respect to the frame of the objects.

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Computer Graphics Viewing with Computers (OpenGL)

Figure 9.1

Consider the sequence illustrated in Figure 9.2. In part (a), we have, the initial configuration. A vertex specified at p has the same representation in both frames. In part (b), we have changed the model-view matrix to C by a sequence of transformations. The two frames are no longer the same, although C contains the information to move from the camera frame to the object frame or, equivalently, contains the information that moves the camera away from its initial position at the origin of the object frame.

Figure 9.2

The next problem is how we specify the desired position of the camera through the

API and how we implement camera positioning in OpenGL.

Our first approach is to specify the position indirectly by applying a sequence of rotations and translations to the model-view matrix. This approach is a direct application of the instance transformation that we presented in Transformation lectures, but we must be careful for two reasons. First , we usually want to define the camera before we position any objects in the scene. Second , transformations on the camera may appear to be backward from what you might expect.

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Computer Graphics Viewing with Computers (OpenGL)

Orthogonal View :

Suppose that we want to look at the same object from the positive x-axis. Now, not only do we have to move away from the object, but we also have to rotate the camera about the y-axis, as shown in Figure 9.3. We must do the translation after we rotate the camera by 90 degrees about the y-axis. In the program, the calls must be in the reverse order, as we discussed in Transformation Lectures, so we expect to see code like the following:

Figure 9.3

In terms of the two frames, first we rotate the object frame relative to the camera frame, and then we move the two frames apart.

Isometric View :

Consider creating an isometric view of the cube. Suppose that again we start with a cube centered at the origin and aligned with the axes. Because the default camera is in the middle of the cube, we want to move the camera away from the cube by a translation. We obtain an isometric view when the camera is located symmetrically with respect to three adjacent faces of the cube.

Starting with the default camera, suppose that we are now looking at the cube from somewhere on the positive z-axis. We can obtain one of the eight isometric views— there is one for each vertex—by first rotating the cube about the x-axis until we see the two faces symmetrically, as shown in Figure 9.4. Clearly, we obtain this view by rotating the cube by 45 degrees. The second rotation is about the y-axis. We rotate the

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Computer Graphics Viewing with Computers (OpenGL) cube until we get the desired isometric. The required angle of rotation is 35.26 degrees about the y-axis.

Figure 9.4

However, we need a clockwise rotation, so the angle must be negative. Finally, we move the camera away from the origin. Thus, our strategy is first to rotate the frame of the camera relative to the frame of the object and then to separate the two frames; the model-view matrix is of the form

In OpenGL, the code for setting the model-view matrix is as follows:

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Computer Graphics Viewing with Computers (OpenGL)

Note that the clipping volume as set by glOrtho is relative to the camera frame.

Thus, for an orthographic view, the translation of the camera does not affect the size of the image of any object, but it can affect whether or not objects are clipped because the clipping volume is measured relative to the camera.

Trimetric Viewing :

Consider the situation illustrated in Figure 9.5 . Here a camera is located at a point e called the eye point, specified in the object frame, and it is pointed at a second point a , called the at point. The view-reference point is the eye point. Hence, we need only to add the desired up direction for the camera. The OpenGL utility function:

Figure 9.5 alters the model-view matrix for a camera pointed along this line. Thus, we usually use the sequence.

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Computer Graphics Viewing with Computers (OpenGL)

Perspective Projection :

As we saw in Viewing lecture, we can place the projection plane in front of the center of projection. If we do so for the configuration of Figure 9.6(a), we get the views shown in Figure 9.6. A point in space (x, y, z) is projected along a projector into the point (xp, yp, zp). All projectors pass through the origin and, because the projection plane is perpendicular to the z-axis,

Figure 9.6

From the top view shown in Figure 9.6(b), we see two similar triangles whose tangents must be the same. Hence,

Using the side view shown in Figure 9.6(c), we obtain a similar result for y p

These equations are nonlinear. The division by z describes non-uniform scaling The images of objects farther from the center of projection are reduced in size (diminution) compared to the images of objects closer to the COP.

In OpenGL, we have two functions for specifying perspective views and one for specifying parallel views. Alternatively, we can form the projection matrix directly, either by loading it, or by applying rotations, translations, and scaling to an initial identity matrix. We can specify a perspective camera view by the function:

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Computer Graphics Viewing with Computers (OpenGL)

These parameters are shown in Figure 9.7 in the camera frame. The near and far distances are measured from the COP (the origin in eye coordinates) to front and back clipping planes, both of which are parallel to the plane z — 0. Because the camera is pointing in the negative z-direction, the front (near) clipping plane is the plane z = — near, and the back (far) clipping plane is the plane z = —far. The left, right, top, and bottom values are measured in the near (front clipping) plane. The plane x = left is to the left of the camera as viewed from the COP in the direction the camera is pointing.

Similar statements hold for right , bottom, and top.

Although in virtually all applications far > near > 0, as long as near ≠ far, the resulting projection matrix is valid although objects behind the center of projection— the origin—will be inverted in the image if they lie between the near and far planes.

Figure 9.7

Computer Technology _ Software Dep. _ Wadhah R. Baiee _2011

Download