<opengl>viewing

Source: Internet
Author: User
Tags in degrees

I. Overview:the Camera Analogy

The transformation process used to produce, the desired scene for viewing are analogous to taking a photograph with a camera . As shown in Figure 3-1, the steps with a camera (or a computer) might is the following:

1. Set up your tripod and point the camera at the scene (viewing transformation).

2. Arrange the scene to being photographed into the desired composition (modeling transformation).

3. Choose A camera lens or adjust the zoom (projection transformation).

4. Determine How large-want the final photograph to Be-for example, you might want it enlarged (viewport Tran sformation).

After these steps has been performed, the picture can is snapped or the scene can be drawn.

Note that these steps correspond to the order in which you specify the desired transformations in your program, n OT necessarily the order in which the relevant mathematical operations is performed on an object ' s vertices. The viewing transformations must precede the modeling transformations in your code, but can specify the projection and Viewport transformations at any point before drawing occurs. Figure 3-2 shows the order in which these operations occur on your computer.

Figure 3-1 the Camera analogy

Figure 3-2 Stages of Vertex transformation

To specify viewing, modeling, and projection transformations, you construct a 4 x 4 matrix M, which are then multiplied by The coordinates of each vertex v in the scene to accomplish the transformation:

(Remember that vertices always has four coordinates (x, Y, Z, W), although in the most cases w are 1, and for two-dimensional Data, Z is 0.) Note that viewing and modeling transformations is automatically applied to surface normal vectors, in addition to Vertice S. (Normal vectors is used only in the eye coordinates.) This ensures, the normal vector ' s relationship to the vertex data is properly preserved.

The viewing and modeling transformations you specify be combined to form the Modelview matrix, which was applied to the Coming object coordinates to yield eye coordinates. Next, if you ' ve specified additional clipping planes to remove certain objects from the scene or to provide cutaway views of objects, these clipping planes is applied.

after this,  opengl applies the projection matrix to yield clip coordinates. This transformation defines a viewing volume; Objects outside this volume is clipped so, they ' re not drawn in the final scene. After this point, the perspective division are performed by dividing coordinate values by W, to produce normalized device C Oordinates. Finally, the transformed coordinates is converted to Windows coordinates by applying the viewport transformation. You can manipulate the dimensions of the viewport to cause the final image to be enlarged, shrunk, or stretched.

You might correctly suppose that the X-and y-coordinates is sufficient to determine which pixels need to be dra WN on the screen. However, all the transformations is performed on the z-coordinates as well. This is, at the end of this transformation process, the z-values correctly reflect the depth of a given vertex (measured In distance away from the screen). One use for this depth value is to eliminate unnecessary drawing. For example, suppose, vertices has the same x-and y-values but different z-values. OpenGL can use this information to determine which surfaces is obscured by other surfaces and can then avoid drawing the Hidden surfaces.

II. Implementation

1. Viewing transformation

void Glulookat(gldouble Eyex, gldouble eyey, Gldouble Eyez, gldouble CenterX, gldouble centery, GLdouble CenterZ, Gldouble UpX, gldouble upy, gldouble UpZ)

Parameters eyeXeyeYeyeZ   Specifies the position of the eye point. centerXcenterYcenterZ   Specifies the position of the reference point. upXupYupZ   Specifies the direction of theUp vector. (tilting the camera)

2. Modeling transformation

void Glscalef(glfloat x, glfloat y, glfloat z)

Parameters

xy,z

  Specify scale factors along the x, y, and z axes, respectively.

void Gltranslatef(glfloat x, glfloat y, glfloat z)

Parameters

xy,z

  Specify the x, Y and Z coordinates of a translation vector.

void Glrotatef(glfloat angle, glfloat x, glfloat y, glfloat z)

Parameters

angle

  Specifies the angle of rotation, in degrees.

xy,z

  Specify the x, y, and z coordinates of a vector, respectively.

3. Projection transformation

Before gifrustum () can be called to set the projection transformation, some preparation is needed. As shown in the reshape () routine in Example 3-1, the command called Gimatrixmode () was used first, with the argument Gl_ P Rojection. This indicates, the current matrix specifies the projection transformation and that subsequent transformation calls AF Fect the projection matrix.

void glfrustum(gldouble left, gldouble right, gldouble Bottom, gldouble top, Gldouble nearval, gldouble farval)

Parameters

left,right

  Specify the coordinates for the left and right vertical clipping planes.

bottom,top

  Specify the coordinates for the bottom and top horizontal clipping planes.

nearVal,farVal

  Specify the distances to the near and far depth clipping planes. Both distances must be positive.

4. Viewport transformation

Together, the projection transformation and the viewport transformation determine how a scene is mapped onto the Comput ER screen. The projection transformation specifies the mechanics of how the mapping should occur, and the viewport indicates the Shap E of the available which the scene is mapped. Since The viewport specifies the region the image occupies on the computer screens, you can think of the viewport transform ation as defining the size and location of the final processed photograph-for example, whether the photograph should is en larged or shrunk.

The arguments for Glviewport () describe the origin of the available screen space within the window-(0, 0) in this Example-and the width and height of the available, all measured in pixels. This is what this command needs to being called within reshape (): If the window changes size, the viewport needs to change ACC ordingly. Note the width and height are specified using the actual width and height of the window; Often, you want to specify the viewport on this and rather than give an absolute size.

void Glviewport(gldouble x, gldouble y, gldouble width, gldouble height)

Parameters

x,y

  Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0).

width,height

  Specify the width and height of the viewport. When a GL context was first attached to a window, width and height was set to the dimensions of that Window.

<opengl>viewing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.