3D Viewing and Orthogonal Projections - PowerPoint PPT Presentation

1 / 31
About This Presentation
Title:

3D Viewing and Orthogonal Projections

Description:

In this week and next week, we will ... c) the view volume is the parallelepiped. 2D Drawing (cont. ... rectangle in 3-space ( parallelepiped) that extends from ... – PowerPoint PPT presentation

Number of Views:767
Avg rating:3.0/5.0
Slides: 32
Provided by: Ami48
Category:

less

Transcript and Presenter's Notes

Title: 3D Viewing and Orthogonal Projections


1
3D Viewing and Orthogonal Projections
  • Chapter 5 and 7.6.2 in Hill

2
Introduction
In this week and next week, we will discuss how
viewing and perspective transformations are
handled for 3-D spaces. In particular, we will
look at how OpenGL performs drawing of 3D
scenes. In OpenGL and most similar graphics
systems, the process involves three basic
steps 1. Modelview transformation 2.
Perspective transformation 3. Mapping to the
viewport
3
3-D coordinate system
Basically, we will assume that all of the objects
defined are initially represented relative to a
standard 3-dimensional coordinate frame called
world coordinate that follow a right-hand
coordinate system.
y
x
z
4
Basic steps in 3D Drawing
Modelview transformation Maps objects (actually
vertices) from their world-coordinate
representation to one that is centered around the
viewer. The resulting coordinates are called
eye-coordinates Perspective projection This
projects points in 3-D eye-coordinates to points
on a plane called viewplane. This projection
process consists of two separate parts the
projection transformation (affine) and
clipping. Mapping to the viewport Convert the
point from these 2-D coordinate to the viewport
(pixel) coordinates.
5
2D Drawing (so far)
2D drawing is based on a special case of 3D
viewing. a) parallel projection b) the eye
or camera is along the z-axis at the
window or viewplane, a rectangle lying on in
the xy-plane c) the view volume is the
parallelepiped
6
2D Drawing (cont.)
Points lying in the view volume will are
projected onto the window along lines parallel
to z-axis Points lying outsides the view volume
will be clipped off Function provided by OpenGL
is glOrtho2D(left, right, bottom, top)
7
3D Drawing
In 3-D drawing, the camera or eye will have
more flexibility in term of position and
orientation to produce better views of the scene.
Example below shows the position and orientation
of a camera or eye in a scene.
In this scene, the block has undergone
transformation process from its original shape
which is a cube and displayed using parallel
projection.
8
3D Drawing (cont.)
Basically, this is done by OpenGL where it
provides functions to define the view volume and
its position. We will look at the details of
drawing 3D scene using parallel projection.
9
OpenGL Graphics Pipeline
Again we will look at the OpenGL graphics
pipeline
Each vertex will have to go through this
pipeline. They will encounter three matrices
before being displayed on the screen.
10
Modelview Matrix
Modelview matrix This matrix combines two
effects the sequence of modeling
transformation applied to objects and the
transformations that orients and positions
the camera in space. It is actually a composite
matrix produced by multiplying 2 matrices( M
modeling matrix, Vviewing matrix)
  • Before the transformation b) after the
    modeling transformation
  • c) After the modelview transformation

11
Projection Matrix
Projection matrix this matrix scales and shifts
each vertex so that all vertices that lie inside
the view volume will lie in a standard cube
centered at origin ( rectangular into cube shape
of view volume) for a parallel projection
Only after this, the clipping process will take
place
12
Viewport Matrix
This is the final stage where the surviving
part of the object will be mapped on the screen.
It is done by the viewport matrix. This matrix
maps the standard cube into a block shape which
has x and y values extend across the viewport (
in screen coordinates) and z-component extends
from 0 to 1 that is used to retain depth
information (the distance between the point and
the eye of the camera). Recall the
world-to-viewport Transformation (lecture 3b).
13
Setting the camera in OpenGL
In this case, we will be using a function that
sets the camera for a parallel projection. The
function is called glOrtho(left, right, bott,
top, near, far) The six values (all of Gldouble
type) in the function specify a rectangle in
3-space ( parallelepiped) that extends from left
to right in x, from bott to top in y and from
near to far in z.
14
Setting the camera in OpenGL (cont.)
The following code sets the projection
matrix glMatrixMode(GL_PROJECTION) glLoadIden
tity() glOrtho(left, right, bottom, top, near,
far)
15
Parallel Projections
There are two kind of parallel projection 1)
Orthographic projection 2) Oblique
projection In this course, we will concentrate
on orthographic projection since this is the one
that is supported by OpenGL through the function
glOrtho(). Orthographic projection is a
projection where the lines of projection are all
parallel to one of the coordinates axis, the z-
axis
16
Orthographic Projection
Orthographic projection
17
Orthographic Projection
The transformation maps a point P in 3-space to
point P on the xy-coordinate plane by setting
the z-coordinate to zero. Therefore, a point P
(px, py, pz, 1) is mapped to the point P (px,
py, 0, 1)
NB Although it is easy to assume that OpenGL
simply Set the z-coordinate to zero since it is
not needed for final drawing, it is actually not
the case. The z-coordinate is still needed to
convey depth information that is useful for
hidden surface removal (will be explained
later).
18
Orthographic Projection
Basically, after defining a view volume of shape
rectangle R using glOrtho() function, OpenGL will
automatically mapped R to a 2 x 2 x 2 cube
called canonical view volume that extends from 1
to 1 along each coordinate axis.
19
Orthographic Projection
The matrix that achieves this transformation is
the composition of a scaling and translation
transformation matrices. Basically, we want to
translate the view volume to the center of the
origin and then scale each axis so that each of
the rectangle widths is scaled to a width 2. The
matrix has the following form
20
Orthographic Projection
The main reason why OpenGL performs this mapping
Transformation is to simplify the clipping and
depth buffer Processing.
21
Converting to viewer-centered Coordinate system
  • This process is to change the coordinate system
    from the one that is used to define an object
    (world coordinate) to the coordinate system that
    is used to set the eye or camera (eye
    coordinate)

22
Positioning and Aiming the camera
In OpenGL, there is a function that can be used
to generate the desired transformation matrices
(V) to perform this change of coordinates and
multiply these matrices with the top current
transformation (CT) stack. Remember that this
operation should be done in Modelview mode. The
function is shown below glLookAt(eyeX, eyeY,
eyeZ, ctrX, ctrY, ctrZ, upX, upY, upZ)
The arguments for this function are all of type
Gldouble. It consists of two points and one
vector.
23
Positioning and Aiming the camera (cont.)
The point Eye (eyeX, eyeY, eyeZ) is the
viewpoint which is the location of the viewer (or
the camera). To indicate the direction that the
camera is pointed, a central point to which the
camera is facing is given by Ctr (ctrX, ctrY,
ctrZ). It is important to determines the viewing
vector, that indicates the direction that the
viewer is facing. To fix the orientation of the
camera, the vector up (upX, upY, upZ) provides
the direction that is up relative to the camera
(I.e. vector up (0,1,0) will set the camera
having an upwards direction parallel to the y-axis
24
Positioning and Aiming the camera (cont.)
A diagram showing how we specify the viewers
position and look at position
25
Example
The code fragment below shows an example how to
set a camera that is situated at eye (4,4,4),
looking at origin with Look (0,1,0) and the
upwards direction is set to up (0,1,0)
glMatrixMode(GL_MODELVIEW) glLoadIdentity() glLo
okAt(4, 4, 4, 0, 1, 0, 0, 1, 0)
26
Implementation of glLookAt()
27
Cont.
How does OpenGl implement this change of
coordinate transformation from world coordinate
to eye coordinate? Basically, a transformation
matrix (V) will be built to perform this
transformation Refer to the diagram previously
shown, we have a camera with its coordinate
system hanging in the world. This
coordinate system has its origin at eye and
oriented according to its three mutually
perpendicular unit vectors u, v and n. Based on
the diagram, we also know that the eye is looking
in the direction of -n
28
Cont.
gluLookAt() uses the parameters eye, look and up
to create unit vector u, v, and n according the
following relationships n normalise (eye
look) u normalise (up x n) v normalise (n
x u )
Using this information, OpenGL will build the
viewing matrix V
29

Cont.
The matrix will be in the following form where
the point d has components (dx,dy,dz) (-eye.u,
-eye.v, -eye.n)
30
Exercises
For the case eye (4,4,4) lookAt (0,1,0)
and up (0,1,0)
  • Show that u, v and n are mutually perpendicular
  • Show that the resulting matrix (V) is

31
Exercises
c) Show that the matrix V properly converts world
coordinates to eye coordinates by
demonstrating that it maps eye into the
origin (0,0,0,1), u into x (1,0,0,0), v into y
(0,1,0) and n into z (0,0,1)
Write a Comment
User Comments (0)
About PowerShow.com