0% found this document useful (0 votes)
7 views

Computer Graphics View Transformation

The document discusses 3D camera transformations in computer graphics, explaining the use of a viewing coordinate system and the process of mapping 3D images to 2D displays through various projection methods. It covers parallel and perspective viewing projections, detailing orthographic, isometric, oblique, and perspective projections, as well as OpenGL functions for implementing these transformations. Key functions like gluLookAt and glOrtho are highlighted for setting viewing parameters and projection matrices in OpenGL.

Uploaded by

sheldricktech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Computer Graphics View Transformation

The document discusses 3D camera transformations in computer graphics, explaining the use of a viewing coordinate system and the process of mapping 3D images to 2D displays through various projection methods. It covers parallel and perspective viewing projections, detailing orthographic, isometric, oblique, and perspective projections, as well as OpenGL functions for implementing these transformations. Key functions like gluLookAt and glOrtho are highlighted for setting viewing parameters and projection matrices in OpenGL.

Uploaded by

sheldricktech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

COMPUTER GRAPHICS

VIEWING

INTRODUCTION

3D Camera Transformation

In graphics we usually use a camera analogy, i.e., the viewer, located at the View
Reference Point (VRP), observes the scene through a camera and can move around the
scene. This is accomplished by defining a viewing coordinate system (VCS) (left handed),
which has the position and orientation of the camera. Then we align the VCS with the
world coordinate system (WCS), creating a viewing transformation matrix. This matrix is
then applied to all the objects in the scene, which moves them into the proper position as
seen from the VRP. This is assumed the world coordinate system is right handed.

Viewing Transformations: 2D and 3D

When we define an image in some world coordinate system, to display that image we
must map the image to the physical output device. This is a two stage process. For 3
dimensional images we must first determine the 3D camera viewpoint, called the View
Reference Point (VRP) and orientation. Then we project from 3D to 2D, since our display
device is 2 dimensional. Next, we must map the 2D representation to the physical device.

3D Viewing Projections

 The basic problem is to map a 3D object to a 2D Display surface.

 There are two general methods of 3D viewing projections: Parallel and Perspective

1
Viewing

Parallel Viewing Projections

 Projection rays (projectors) emanate from a Center of Projection (COP) and intersect
Projection Plane (PP).
 The COP for parallel projectors is at infinity. The length of a line on the projection
plane is the same as the "true Length".

 There are two different types of parallel projections:


 If the direction of projection is perpendicular to the projection plane then it is an
orthographic projection.
 If the direction of projection is not perpendicular to the projection plane then it is
an oblique projection.
 Look at the parallel projection of a point (x, y, z). (Note the left handed coordinate
system). The projection plane is at z = 0. x, y are the orthographic projection values
and xp, yp are the oblique projection values (at angle a with the projection plane)

 Look at orthographic projection: it is simple, just discard the z coordinates.


Engineering drawings frequently use front, side, top orthographic views of an object.
 Here are three orthographic views of an object.

2
Viewing

 Orthographic projections that show more than 1 side of an object are called
axonometric orthographic projections.
 The most common axonometric projection is an isometric projection where the
projection plane intersects each coordinate axis in the model coordinate system at an
equal distance.

Isometric Projection

 The projection plane intersects the x, y, z axes at equal distances and the projection
plane Normal makes an equal angle with the three axes.
 To form an orthographic projection xp = x, yp= y , zp = 0. To form different types
e.g., Isometric, just manipulate object with 3D transformations.

3
Viewing

Oblique Projection

 The projectors are not perpendicular to the projection plane but are parallel from the
object to the projection plane The projectors are defined by two angles A and d where:
A = angle of line (x,y,xp,yp) with projection plane,
d = angle of line (x, y, xp, yp) with x axis in projection plane
L = Length of Line (x,y,xp,yp).

 Now if A = 90° (projection line is perpendicular to PP) then tan A = infinity => L1 =
0, so have an orthographic projection.

 Two special cases of oblique projection:

1) A = 45° , tanA = 1 => L1 = 1 This is a Cavalier projection such that all lines
perpendicular to the projection plane is projected with no change in length.

2) A= 63.40°, tanA = 2, L1 = 1 / 2
Lines which are perpendicular to the projection plane are projected at 1 / 2
length . This is a Cabinet projection.

4
Viewing

Perspective Viewing Projection

 The Perspective viewing projection has a Center of Projection ("eye") at a finite


distance from the projection plane (PP).

 So the distance of a line from the projection plane determines its size on the
projection plane, i.e. the farther the line is from the projection plane, the smaller its
image on the projection plane.
 In the two images above, the projections of L1 = L2 but the actual length of L1 <> L2.
Perspective projection is more realistic since distant objects appear smaller.

Vanishing Points

 Any set of parallel lines that are not parallel to the projection plane will converge to a
vanishing point.
 If the set of lines is parallel to one of the three principal axis then it is called a
principal vanishing point.

5
Viewing

 In this image the X and Y lines are parallel to the Z axis. Since the projection plane is
normal to the Z axis there is only one principal vanishing point.
 Lines parallel to either X or Y axis are parallel to projection plane and have no
vanishing point. So it is a one-point projection.

6
Viewing

 In this image the lines are not parallel to the z axis. Since the projection plane
is normal to the z axis there is only one principal vanishing point. Lines
parallel to either x or y axis are parallel to projection plane and have no
vanishing point. So it is a one-point projection.

OpenGL Viewing-Transformation Function

 When we designate the viewing parameters in OpenGL, a matrix is formed and


concatenated with the current modelview matrix.
 Consequently, 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 modelview mode with the statement

glMatrixMode (GL_MODELVIEW);

GL_MODELVIEW
- used to store and combine the geometric transformation.
- It is also used to combine the geometric transformations with the
transformation to a viewing-coordinate system. Hence modelview mode is
specified with the statement

glMatrixMode (GL_MODELVIEW);
which designate a 4 by 4 modelview matrix as the current matrix.

7
Viewing

GlMatrixMode

 A routine used to set the projection mode, designates the matrix that is
to be used for the projection transformation.
 Transformation determines how a scene is to be projected onto the
screen.

gluLookAt

 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, xref, yref, zref, vx, vy, vz);
e.g.
gluLookAt (100.0, 50.0, 50.0, 50.0, 50.0, 0.0, 0.0, 1.0, 0.0);

 Parameter values are assigned floating-point values.


 The function (gluLookAt) designates the origin of the viewing reference frame as the

world-coordinate position : P0, = (x0, y0, z0)


Reference position as: Pref = (xref, yref, zref)
View up vector as: v = (vx, vy, vz)

 The positive zview axis for the viewing frame is in the direction N = P0 – Pref
 Unit axis vectors for the viewing reference frame are calculated as in the figure below

View Plane

Coordinate reference for obtain


a selected view of a 3-D scene

8
Viewing

 Since the viewing direction is a long the –zview axis, the reference position Pref is
also referred to as the “look-at-point”.
 This is usually taken to be some position in the center of the scene that we can use as
a reference for specifying the projection parameters.
 And we can think of the reference position as the point at which we want to aim that
is located at the viewing origin.
 The up orientation for the camera is designated with vector V, which is adjusted to a
direction perpendicular to N.
 Viewing parameters specified with the

gluLookAt function

are used to form the viewing-transformation matrix. The matrix is formed as a


combination of :
i) Translation, which shifts the viewing origin to the world origin
ii) Rotation, which aligns the viewing axes with the world axes.

NOTE: If we do not invoke values, the viewing reference frame is the same as the
world frame, with the viewing direction along the negative zworld axis.

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 gluLookAt function), 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);

Parameter values are assigned floating-point numbers.

 GlOrtho is used to select the clipping-window coordinates and the distances to the
near and far clipping planes from the viewing origin.
 There is no option in OpenGL for the placement of the view plane. The near clipping
plane is always also the view plane, and therefore the clipping window is always on
the near plane of the view plane.
 Function glOrtho generates a parallel projection that is perpendicular to the view
plane (the near clipping plane).
 Thus, this function generates a finite orthogonal projection view volume for the
specified clipping planes and clipping window.
 In OpenGL, the near and far plane are not optional; they must always be specified for
any projection transformation.

9
Viewing

 Parameters dnear and dfar denotes distances in the negative zview direction from the
viewing-coordinate origin.
Example:

If dfar = 55.0, then far clipping plane is at the coordinate position zfar = -55.0

A negative value for either parameter denotes a distance “behind” the viewing
origin, along the positive zview axis.
 We can assign any values for the OpenGL orthogonal-projection function are –1 or
+1, which produce a view volume that is a symmetric normalized cube in the right-
handed viewing coordinate system. This default is equivalent to issuing the statement

glOrtho (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

 The default clipping window is thus a symmetric normalized square, and the default
view volume is a symmetric normalized cube with

znear = 1.0 (behind the viewing position)


zfar = -1.0

An example showing the appearance and position of the default orthogonal-


projection view volume.

yview

Top

Far Clipping
Clipping Window
Window

xview

Left

Near Clipping
Right Window
zview

Coordinate extents for this symmetric cube are from –1 to +1


in each direction. The near clipping plane is at znear = 1;
and the far clipping plane is at zfar = -1

10
Viewing

 For a 2-D application, we use the gluOrtho2D function to set up the clipping window
e.g.
gluOrtho2D (xwmin, xwmax, ywmin, ywmax);

 We could also use the glOrtho function to specify the clipping window, as long as
parameters dnear and dfar are assigned values that were on opposite sides of the
coordinate origin.
 In fact, a call to gluOrtho2D is equivalent to a call to glOrtho

with dnear = -1.0 and


dfar = 1.0

OpenGL Symmetric Perspective –Projection function

 There are two functions for producing a perspective projection view of a scene.
i) One of these functions generates a symmetric frustum view volume about the
viewing direction (the negative zview axis).
ii) The other function can be used for either a symmetric-perspective projection.
 For both functions, the projection reference point is the viewing-coordinate origin and
the near clipping plane is the view plane.
 A symmetric, perspective-projection, frustum view volume is set up with the GLU
function

gluPerspective (theta, aspect, dnear, dfar);

All parameter values are assigned floating-point numbers,

 First two parameters define:


 The size of the clipping window on the near plane
 The position
 Second two parameters specify:
 The distances from the view point (coordinate origin) to the near and far
clipping planes.
 Parameter theta represents the field-of-view angle, which is the angle between the top
and bottom clipping planes

11
Viewing

Clipping yview
Window
xview

θ zview

Frustum view Projection Reference Point


volume

Above figure: Field-of-view angle θ for a symmetric perspective-projection view


volume, with the clipping window between the near clipping plane and the
projection reference point.

- The angle θo (theta) can be assigned any value from 0o to 180o.

 Parameter
Aspect is assigned a value for the aspect ration (width / height) of the clipping
window.

Clipping Window

Projection Reference Point


yview

Height

zview
Θ/2

Zprp - Zvp

Relationship between the field-of-view angle θ , and height of the


clipping window, and the distance between the projection reference
point and the view plane

12
Viewing

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,m xwmin, ywmin, ywmax, dnear, dfar);

Parameters are assigned floating –point numbers.

 The near plane is the view plane and the


 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 distance must be positive.
 The first 4 parameters set the coordinates for the distances from the coordinate origin
to the near and far clipping planes along the negative zview axis.
Example:
GlFrustum (-40.0, 40.0, -60.0, 60.0, 25,125);

Coordinate limits Positions for


for the window near and far
clipping
planes

13

You might also like