Title: Mathematical Basis for Graphics
1Mathematical Basis for Graphics
Representations in a frame Homogeneous
Coordinates
Affine Space
Scalars
Vectors
Points
Operations
Transformation
2Frames and Transformations of Representations
v is representation of a point or vector in
frame
If
then
u is representation of a point or vector in
frame
is of the form
3Instance Transformation
S
R
T
Model Coordinates
4Important Points to Know in Matrix Definition
and Manipulation
- Matrix forms for trans, scale, rot
- Concatenation of matrices
- OpenGL commands to change matrices
- Organization of matrix data structure
5How to Create 3D-Object Views?
6Classical ViewingPerspective Projection
Object
COP Center of Projection origin of camera frame
Projection Plane
COP
7Classical ViewingParallel Projection
Object
- Viewer at an infinite distance from the objects
- COP is replaced by DOP (Direction of Projection)
DOP
Projection Plane
8Examples of Classical Views
9Classical ViewingOrthographic Projection
10Classical ViewingAxonometric Projections
11Classical ViewingAxonometric Projections
12Dimetric Projection
13Isometric Projection
14Classical ViewingForeshortening
Projection Plane
Object
Object size s is foreshortened to l
u
n
q
l
s
15Classical ViewingPerspective Projection
VP2
VP1
- 3-point perspective
- 2-point perspective
- 1-point perspective
Perspective viewing
VP3
16Viewing in Computer GraphicsProjection Transforms
Projection Plane
T
17Front and Back Clipping Planes
18OpenGLCanonical Orthographic View Volume
y
Plane z -1
Plane z 1
x
DOP
Projection Plane
z
19Orthographic Viewing Transform
What we want
What we use
Transformation is
20General OpenGlOrthographic Projection
glOrtho(xmin, xmax, ymin, ymax, zmin, zmax)
P
Canonical view volume
21Affine Transformations for Normalization
22General OpenGLOrthographic Projection
P
Translate View Volume
Scale View Volume
23General OpenGLOrthographic Projection
P
Zeroed by postmult by
24Classical ViewingPerspective Projection
Object
Projection Plane
COP
25Perspective Projection
Parallel to the lens and orthogonal to the z-dir
More general case
3D view
Side view
Top view
26Perspective Projection (2)
Proj. Plane
Equations are non linear. Therefore cannot use
linear affine transformation.
27Whats problems in Perspective Projection??
All points along a projector project into the
same point, we cannot recover a point from its
projection Solution using homogeneous
coordinates to handle projections
28Perspective Division
Consider the transformation matrix
If we allow the form
to represent a point,
we can recover the original form by division by
w. This is called perspective division.
The transformation then yields
29Projection Pipeline
30Canonical Perspective Transformation
31Canonical Perspective TransformationIdea -
Transformation of View Volume
Orthographic projection is applied as last step
to project to plane z 0.
32Three Steps in Determining the OpenGL Perspective
Transformation
- Shearing the window to the z-axis
- Scaling
- 3. Perspective normalization/mapping
33Shearing Transform in 2D
- Consider shear transformation matrix along x-axis
- The term a is the proportionality constant. A
point P (x,y,1) after transformation becomes - Note that x is a function of y
34Shearing Transform in 2D (cont)
- Similarly consider shear transformation matrix
along y-axis - The term b is the proportionality constant. A
point P (x,y,1) after transformation becomes - Note that y is a function of x
35Shearing Transform in 3D
- Shear transformation matrix in (x,y) plane
- A point P (x,y,z,1) after transformation
becomes - Note that x and y are functions of z
36Perspective Tx -- Shearing the window to the
z-axis
- move the ray from the origin through the window
center onto the z axis - when z -n, ?x should be (rl)/2n and ?y should
be (tb)/2n, so we get
37Perspective Tx -- Shearing the window to the
z-axis
- So the shearing transformation will then be
- That means, the shearing matrix is given by
38Perspective Tx --Scaling
-
- We want the oblique clipping planes to have
- Such that with boundaries lb-n and r t n.
- This requires a scale to make the window this
size
39Perspective Tx Scaling (cont)
-
- Therefore, the scaling matrix is given by,
40Perspective Tx Perspective normalization/mapping
- We want to map the frustum to a 2x2x2 cube
centered at the orgin. First, we map the bounding
planes x ?z and y ?z to the planes x ?1 and
y ?1. This can be done by mapping x to x/-z and
y to y/-z -
41Perspective Tx Perspective normalization/mapping
-
- Ø We use a map to homogeneous coordinates
and then project back to 3 space by dividing - Ø Now, we need to solve a, b, c and d such
that z in -n, -f maps to z in -1,1. -
- Ø As x maps to x/-z, we get
-
42Perspective Tx Perspective normalization/mapping
-
- Ø As the near plane is at z-n and the far
plane at z-f, which map to (-1, 1) respectively,
we get
43Perspective Tx Perspective normalization/mapping
-
- Ø Thus, the perspective normalization matrix is
given by,
44Perspective Transformation matrix
45General OpenGL Perspective Transformation
glFrustrum(l,r,b,t,n,f)
46Canonical Transformation of View VolumeIn OpenGL
After normalization, OpenGL is in left-handed 3D
normalized coordinates.
47General OpenGL Perspective TransformationAnother
form
gluPerspective(fovy, aspect, zNear, ZFar)
fovy Specifies the field of view angle in
degrees, in the y direction. aspect Specifies
the aspect ratio that determines the ratio of
width to height. zNear Specifies the distance
from the viewer to the near clipping plane,
always positive. zFar Specifies the distance
from the viewer to the far clipping plane, always
positive.
48Hidden Surface Removal(Z - Buffer Algorithm)
General Approaches Object Space
Algorithms Draw back facing polygons
first. Convex objects do not render back
facing polygons. What about front facing
polygons that obstruct each other? Image Space
Algorithms Determine relationship among points
on each projector
49Initializing Z-Buffer in OpenGL
glutInitDisplayMode(GLUT_DOUBLEGLUT_RGBGLUT_DEPT
H)
Allocates the buffer.
glEnable(GL_DEPTH_TEST)
Enables depth testing.
50Positioning the Camera
Initially, the camera is at (0,0,0) for
perspective viewing looking in the -z
direction. To move the camera away from modeled
objects distance d along the the positive z
axis glTranslatef(0.0, 0.0, -d) What you are
really doing is translating the modeled objects
in the negative z direction. If you want to look
at the model from the positive x direction at a
distance d glTranslatef(0.0, 0.0,
-d) glRotatef(-90.0, 0.0, 1.0, 0.0)
51A More Intuitive ApproachOffered by glu
gluLookAt(eyex, eyey, eyez, atx, aty, atz,
upx, upy, upz) eyex, eyey, eyez specify the
position of the eye point and are mapped to
the origin. atx, aty, atz specify a point being
looked at, which will be rendered in center of
view port. It is mapped to the -z axis. upx,
upy, upz specify components of the camera up
vector.