OpenGL 3D Viewing Functions

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

OPENGL 3D VIEWING FUNCTIONS

3D VIEWING FUNCTIONS

• The OpenGL Utility library (GLU) includes functions for specifying


the three dimensional viewing parameters.
• And another function for setting up a symmetric perspective projection
transformation.
• Other functions, such as those for an orthogonal projection, an oblique
perspective projection, and the viewport transformation, are contained
in the basic OpenGL library.
OPENGL VIEWING-TRANSFORMATION
FUNCTION

• When we designate the viewing parameters in OpenGL, a matrix is


formed and concatenated with the current model-view matrix.
• This viewing matrix is combined with any geometric transformations
we may have also specified.
• This composite matrix is then applied to transform object descriptions
in world coordinates to viewing coordinates.
• We set the model-view mode with the statement:
glMatrixMode(GL_MODELVIEW);
OPENGL FUNCTIONS

• Viewing parameters are specified with the following GLU function, which is in the OpenGL Utility
library because it invokes the translation and rotation routines in the basic OpenGL library.
gluLookAt(x0, y0, z0 pref, yref, zref, Vx, Vy, Vz);
• This function designates the origin of the viewing reference frame as the world-coordinate position
PO=(x0,yo,z0)
• The reference position as Pref=(xref, yref, zref),and the view-up vector as V=(Vx, Vy, Vz).
• The positive zview axis for the viewing frame is in the direction N = Po - Pref
• If we do not invoke the gluLookAt function, the default OpenGL viewing parameters are
PO=(0,0,0)
Pref=(0,0,-1)
V=(0,1,0)
OPENGL ORTHOGONAL-PROJECTION FUNCTION

• Projection matrices are stored in the OpenGL projection mode.


• So, to set up a projection-transformation matrix, we must first invoke that mode with the statement
glMatrixMode(GL_PROJECTION);
• Then, when we issue any transformation command, the resulting matrix will be concatenated with
the current projection matrix.
• Orthogonal-projection parameters are chosen with the function
glOrtho(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
• The near clipping plane is always also the view plane, and therefore the clipping window is always
on the near plane of the view volume.
• This default is equivalent to issuing the statement
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
OPENGL SYMMETRIC PERSPECTIVE-
PROJECTION FUNCTION

• A symmetric perspective-projection frustum view volume is set up with


the GLU function
gluPerspective (theta, aspect, dnear, dfar);
• Parameter theta represents the field-of-view angle, which is the angle
between the top and bottom clipping planes.
• This angle can be assigned any value from0°to 180°.
• Parameter aspect is assigned a value for the aspect ratio (width/height)
of the clipping window.
• If we do not specify a projection function, our scene is displayed using
the default orthogonal projection.
OPENGL GENERAL PERSPECTIVE-
PROJECTION FUNCTION

• We can use the following function to specify a perspective projection


that has either a symmetric frustum view volume or an oblique frustum
view volume.
glFrustum(xwmin, xwmax, ywmin, ywmax, dnear, dfar);
• As in the other viewing-projection functions, the near plane is the view
plane and the projection reference point is at the viewing
position(coordinate origin).
• This function has the same parameters as the orthogonal, parallel
projection function, but now the near and far clipping-plane distances
must be positive.
OPENGL VIEWPORTS AND DISPLAY
WINDOWS

• After the clipping routines have been applied in normalized coordinates,


contents of the normalized clipping window, along with the depth
information, are transferred to three dimensional screen coordinates.
• The color value for each xy position on the viewport is stored in the refresh
buffer (color buffer), and the depth information for each xy position is
stored in the depth buffer.
• A rectangular view put is defined with the following OpenGL function
glViewport(xvmin, yvmin, vpWidth, vpHeight);
• To maintain the proportions of objects in a scene, we set the aspect ratio of
the wave board equal to the aspect ratio of the clipping window.

You might also like