Забыли?

?

# Lecture notes

код для вставкиСкачать
```Last Time
вЂў 3D Transformations
вЂ“ Most are natural extensions of 2D transforms
вЂ“ Rotations can be represented in many ways: Orthonormal 3x3 submatrix, Quaternions, Axis-Angle, Exponential Map, Euler Angles
вЂў Coordinate Systems
вЂ“ Local/Object, Global/World, Eye/View/Camera, Canonical View,
Window/Screen
вЂў Canonical to Window mappings
вЂў Orthogonal projection when the camera axes are aligned
with the world axes
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Today
вЂў General Orthogonal viewing
вЂў Perspective viewing
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Simple Orthographic Projection
вЂў The view volume is a rectilinear box for orthographic projection
вЂў Assume that the viewer is looking in the вЂ“z direction, with x to the right
and y up
вЂ“ Can move but not rotate the camera
вЂ“ Assuming a right-handed coordinate system
вЂў The view volume is defined by:
вЂ“
вЂ“
вЂ“
вЂ“
вЂ“
вЂ“
2/24/04
a near plane at z=n
a far plane at z=f , (f < n)
a left plane at x=l
a right plane at x=r, (r>l)
a top plane at y=t
and a bottom plane at y=b, (b<t)
y
z
(l,t,f)
x
(r,b,n)
В© University of Wisconsin, CS559 Spring 2004
Rendering the Volume
вЂў To project, map the view volume onto the canonical view volume
вЂ“ After that, we know how to map the view volume to the window
вЂў The mapping looks similar to the one for canonical в†’ window:
пѓЄ
y
пѓЄ canonical
пѓЄ z canonical
пѓЄ
1
пѓ«
пѓ№ пѓ© 2 пЂЁr пЂ­ l пЂ©
пѓє пѓЄ
0
пѓєпЂЅ пѓЄ
пѓє пѓЄ
0
пѓє пѓЄ
0
пѓ» пѓ«
пѓЄ
0
пЂЅ пѓЄ
пѓЄ
0
пѓЄ
0
пѓ«
0
0
2 пЂЁt пЂ­ b пЂ©
0
0
2 пЂЁn пЂ­ f
0
0
0
0
2 пЂЁt пЂ­ b пЂ©
0
0
2 пЂЁn пЂ­ f
0
0
пѓєпѓЄ
0 0
пѓєпѓЄ
0 пѓє пѓЄ0
пѓєпѓЄ
1 пѓ» пѓ«0
0
0
1
0
0
1
0
0
пЂ­ пЂЁ r пЂ« l пЂ© пЂЁ r пЂ­ l пЂ© пѓ№ пѓ© x view
пѓєпѓЄ
пЂ­ пЂЁt пЂ« b пЂ© пЂЁt пЂ­ b пЂ©
y
пѓє пѓЄ view
пЂ­ пЂЁ n пЂ« f пЂ© пЂЁ n пЂ­ f пЂ©пѓє пѓЄ z view
пѓєпѓЄ
1
пѓ»пѓ« 1
x canonical пЂЅ M view пЂ­ пЂѕ canonical x view
2/24/04
пЂ­ пЂЁr пЂ« l пЂ© 2 пѓ№
пѓє
пЂ­ пЂЁt пЂ« b пЂ© 2
пѓє
пЂ­ пЂЁn пЂ« f пЂ© 2 пѓє
пѓє
1
пѓ»
В© University of Wisconsin, CS559 Spring 2004
пѓ№
пѓє
пѓє
пѓє
пѓє
пѓ»
General Orthographic
Projection
вЂў We could look at the world from any direction, not just
along вЂ“z
вЂў The image could rotated in any way about the viewing
direction: x need not be right, and y need not be up
вЂў How can we specify the view under these circumstances?
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Specifying a View
вЂў The location of the eye in space
вЂ“ A point in space for the center of projection, (ex,ey,ez)
вЂў The direction in which we are looking: gaze direction
вЂ“ Specified as a vector: (gx,gy,gz)
вЂ“ This vector will be normal to the image plane
вЂў A direction that we want to appear up in the image
вЂ“ (upx,upy,upz), This vector does not have to be perpendicular to n
вЂў We also need the size of the view volume вЂ“ l,r,t,b,n,f
вЂ“ Specified with respect to the eye and image plane, not the world
2/24/04
В© University of Wisconsin, CS559 Spring 2004
General Orthographic
Subtle point: it doesnвЂ™t
precisely matter where we
put the image plane
e
image plane
g
t,n
t,f
y
(0,0)
x
b,n
b,f
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Getting thereвЂ¦
вЂў We wish to end up in the вЂњsimpleвЂќ situation, so we need a
coordinate system with:
вЂ“
вЂ“
вЂ“
вЂ“
A vector toward the viewer
One pointing right in the image plane
One pointing up in the image plane
The origin at the eye
вЂў We must:
вЂ“ Define such a coordinate system, view space
вЂ“ Transform points from the world space into view space
вЂ“ Apply our simple projection from before
2/24/04
В© University of Wisconsin, CS559 Spring 2004
View Space
вЂў Given our camera definition:
вЂ“
вЂ“
вЂ“
вЂ“
Which point is the origin of view space?
Which direction is the normal to the view plane, w?
How do we find the right vector, u?
How do we find the up vector, v?
вЂў Given these points, how do we do the transformation?
2/24/04
В© University of Wisconsin, CS559 Spring 2004
View Space
вЂў The origin is at the eye: (ex,ey,ez)
вЂў The normal vector is the normalized viewing direction:
w пЂЅ пЂ­ gЛ†
вЂ“ It is actually more general to think of it as the vector perpendicular
to the image plane
вЂў We know which way up should be, and we know we have a
right handed system, so u=upГ—w, normalized: uЛ†
вЂў We have two vectors in a right handed system, so to get the
third: v=wГ—u
2/24/04
В© University of Wisconsin, CS559 Spring 2004
World to View
вЂў We must translate so the origin is at (ex,ey,ez)
вЂў To complete the transformation we need to do a rotation
вЂў After this rotation:
вЂ“ The direction u in world space should be the direction (1,0,0) in
view space
вЂ“ The vector v should be (0,1,0)
вЂ“ The vector w should be (0,0,1)
u
u
0пѓ№
вЂў The matrix that does that is:
2/24/04
x
пѓЄ
v
пѓЄ x
пѓЄwx
пѓЄ
пѓ« 0
y
z
vy
vz
wy
wz
0
0
В© University of Wisconsin, CS559 Spring 2004
пѓє
пѓє
0пѓє
пѓє
1пѓ»
0
All Together
вЂў We apply a translation and then a rotation, so the result is:
M world
пЂ­ пЂѕ view
пѓЄ
vx
пѓЄ
пЂЅ
пѓЄwx
пѓЄ
пѓ« 0
uy
uz
vy
vz
wy
wz
0
0
пѓєпѓЄ
0 0
пѓєпѓЄ
0 пѓє пѓЄ0
пѓєпѓЄ
1 пѓ» пѓ«0
0
0
1
0
0
1
0
0
пЂ­ ex пѓ№ пѓ© u x
пѓє пѓЄ
пЂ­ ey
v
пѓєпЂЅ пѓЄ x
пЂ­ ez пѓє пѓЄwx
пѓє пѓЄ
1 пѓ» пѓ« 0
вЂў And to go all the way from world to screen:
M world
пЂ­ пЂѕ canonical
пЂЅ M view пЂ­ пЂѕ canonical M world
x canonical пЂЅ M world
2/24/04
пЂ­ пЂѕ canonical
пЂ­ пЂѕ view
x world
В© University of Wisconsin, CS559 Spring 2004
uy
uz
vy
vz
wy
wz
0
0
пЂ­ w п‚· eпѓ№
пѓє
пЂ­ w п‚·e
пѓє
пЂ­ w п‚· eпѓє
пѓє
1 пѓ»
OpenGL and Transformations
вЂў OpenGL internally stores several matrices that control
viewing of the scene
вЂ“ The MODELVIEW matrix is intended to capture all the
transformations up to the view space
вЂ“ The PROJECTION matrix captures the view to screen conversion
вЂў You also specify the mapping from the canonical view
volume into window space
вЂ“ Directly through function calls to set up the window
вЂў Matrix calls multiply some matrix M onto the current matrix
C, resulting in CM
вЂ“ Set view transformation first, then set transformations from local to
world space вЂ“ last one set is first one applied
2/24/04
В© University of Wisconsin, CS559 Spring 2004
OpenGL Camera
вЂў The default OpenGL image plane has u aligned with the x axis, v
aligned with y, and n aligned with z
вЂ“ Means the default camera looks along the negative z axis
вЂ“ Makes it easy to do 2D drawing (no need for any view transformation)
вЂў glOrtho(вЂ¦) sets the view->canonical matrix
вЂ“ Modifies the PROJECTION matrix
вЂў gluLookAt(вЂ¦) sets the world->view matrix
вЂ“ Takes an image center point, a point along the viewing direction and an up
vector
вЂ“ Multiplies a world->view matrix onto the current MODELVIEW matrix
вЂ“ You could do this yourself, using glMultMatrix(вЂ¦) with the matrix
from the previous slides
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Left vs Right Handed View
Space
вЂў You can define u as right, v as up, and n as toward the
viewer: a right handed system uп‚ґv=w
вЂ“ Advantage: Standard mathematical way of doing things
вЂў You can also define u as right, v as up and n as into the
scene: a left handed system vп‚ґu=w
вЂ“ Advantage: Bigger n values mean points are further away
вЂў OpenGL is right handed
вЂў Many older systems, notably the Renderman standard
developed by Pixar, are left handed
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Perspective Projection
вЂў Abstract camera model - box
with a small hole in it
2/24/04
вЂў Pinhole cameras work in
practice - camera obscura, etc
В© University of Wisconsin, CS559 Spring 2004
Distant Objects Are Smaller
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Parallel lines meet
common to draw film plane
in front of the focal point
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Vanishing points
вЂў Each set of parallel lines
(=direction) meets at a different
point: The vanishing point for
this direction
вЂ“ Classic artistic perspective is 3point perspective
вЂў Sets of parallel lines on the
same plane lead to collinear
vanishing points: the horizon
for that plane
вЂў Good way to spot faked images
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Basic Perspective Projection
вЂў Assume you have transformed to view space, with x to the
right, y up, and z back toward the viewer
вЂў Assume the origin of view space is at the center of
projection (the eye)
вЂў Define a focal distance, d, and put the image plane there
(note d is negative)
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Basic Perspective Projection
вЂў If you know P(xv,yv,zv) and d, what is P(xs,ys)?
вЂ“ Where does a point in view space end up on the screen?
P(xv,yv,zv)
yv
P(xs,ys)
d
xv
2/24/04
В© University of Wisconsin, CS559 Spring 2004
-zv
Basic Case
вЂў Similar triangles gives:
xs
d
yv
пЂЅ
xv
ys
zv
d
P(xs,ys)
d
View Plane
2/24/04
В© University of Wisconsin, CS559 Spring 2004
пЂЅ
yv
zv
P(xv,yv,zv)
-zv
Simple Perspective
Transformation
вЂў Using homogeneous coordinates we can write:
пѓ© xs пѓ№ пѓЄ
yv
пѓЄ пѓє пѓЄ
ys п‚є
пѓЄ пѓє пѓЄ zv
пѓЄпѓ« d пѓєпѓ» пѓЄ z
v
пѓЄпѓ« d
2/24/04
пѓ№
пѓє
пѓє
пѓє
пѓє
пѓєпѓ»
пѓЄ
0
Ps пЂЅ пѓЄ
пѓЄ0
пѓЄ
пѓЄпѓ« 0
0
0
1
0
0
1
1
d
0
В© University of Wisconsin, CS559 Spring 2004
0пѓ№
пѓє
0
пѓєP
0пѓє v
пѓє
0пѓє
пѓ»
Perspective View Volume
вЂў Recall the orthographic view volume, defined by a near, far,
left, right, top and bottom plane
вЂў The perspective view volume is also defined by near, far,
left, right, top and bottom planes вЂ“ the clip planes
вЂ“ Near and far planes are parallel to the image plane: zv=n, zv=f
вЂ“ Other planes all pass through the center of projection (the origin of
view space)
вЂ“ The left and right planes intersect the image plane in vertical lines
вЂ“ The top and bottom planes intersect in horizontal lines
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Clipping Planes
Left Clip
Plane
Near Clip
Plane
xv
n
l
View
Volume
r
Far Clip
Plane
f
-zv
Right Clip
Plane
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Where is the Image Plane?
вЂў Notice that it doesnвЂ™t really matter where the image plane is
located, once you define the view volume
вЂ“ You can move it forward and backward along the z axis and still get
the same image, only scaled
вЂў But we need to know where it is to define the clipping
planes
вЂ“ Assume the left/right/top/bottom planes are defined according to
where they cut the near clip plane
вЂў Or, define the left/right and top/bottom clip planes by the
field of view
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Clipping Planes
Left Clip
Plane
Near Clip
Plane
xv
FOV
View
Volume
Far Clip
Plane
f
-zv
Right Clip
Plane
2/24/04
В© University of Wisconsin, CS559 Spring 2004
OpenGL
вЂў gluPerspective(вЂ¦)
вЂ“
вЂ“
вЂ“
вЂ“
Field of view in the y direction (vertical field-of-view)
Aspect ratio (should match window aspect ratio)
Near and far clipping planes
Defines a symmetric view volume
вЂў glFrustum(вЂ¦)
вЂ“ Give the near and far clip plane, and places where the other clip
planes cross the near plane
вЂ“ Defines the general case
вЂ“ Used for stereo viewing, mostly
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Perspective Projection Matrices
вЂў We want a matrix that will take points in our perspective
view volume and transform them into the orthographic view
volume
вЂ“ This matrix will go in our pipeline just before the orthographic
projection matrix
(r,t,n)
(r,t,n)
(l,b,n)
(l,b,n)
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Mapping Lines
вЂў We want to map all the lines through the center of projection
to parallel lines
вЂ“ Points on lines through the center of projection map to the same
point on the image
вЂ“ Points on parallel lines map orthographically to the same point on
the image
вЂ“ If we convert the perspective case to the orthographic case, we can
use all our existing methods
вЂў The intersection points of lines with the near clip plane
should not change
вЂў The matrix that does this, not surprisingly, looks like the
matrix for our simple perspective case
2/24/04
В© University of Wisconsin, CS559 Spring 2004
General Perspective
M
P
пѓЄ
0
пѓЄ
пЂЅ
пѓЄ0
пѓЄ
пѓ«0
0
0
1
0
0
0
пЂЁn пЂ« f пЂ©
1 n
n
пѓє пѓЄ
0
0
пѓєп‚є пѓЄ
пЂ­ f пѓє пѓЄ0
пѓє пѓЄ
0 пѓ» пѓ«0
0
0
n
0
0
nпЂ« f
0
1
0 пѓ№
пѓє
0
пѓє
пЂ­ nf пѓє
пѓє
0 пѓ»
вЂў This matrix leaves points with z=n unchanged
вЂў It is just like the simple projection matrix, but it does some extra things
to z to map the depth properly
вЂў We can multiply a homogenous matrix by any number without changing
the final point, so the two matrices above have the same effect
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Complete Perspective
Projection
вЂў After applying the perspective matrix, we still have to map
the orthographic view volume to the canonical view
volume:
пЂ­ пЂЁr пЂ« l пЂ© пѓ№
M view пЂ­ пЂѕ screen пЂЅ M O M P
2/24/04
пѓЄ пЂЁr пЂ­ l пЂ©
пѓЄ
пѓЄ 0
пЂЅпѓЄ
пѓЄ
пѓЄ 0
пѓЄ
пѓЄпѓ« 0
0
2
пЂЁt пЂ­ b пЂ©
0
0
2
0
пЂЁn пЂ­
0
0
пЂЁr пЂ­ l пЂ© пѓє пѓ© n
пѓє
пЂ­ пЂЁt пЂ« b пЂ© пѓє пѓЄ
0
пѓЄ
пЂЁt пЂ­ b пЂ© пѓє
пѓЄ0
пЂ­ пЂЁn пЂ« f пЂ© пѓє пѓЄ
пѓє
пЂЁn пЂ­ f пЂ© пѓє пѓ« 0
1
пѓєпѓ»
В© University of Wisconsin, CS559 Spring 2004
0
0
n
0
0
пЂЁn пЂ« f пЂ©
0
1
0 пѓ№
пѓє
0
пѓє
пЂ­ nf пѓє
пѓє
0 пѓ»
OpenGL Perspective Projection
вЂў For OpenGL you give the distance to the near and far clipping planes
вЂў The total perspective projection matrix resulting from a glFrustum
call is:
пѓ№
пЂЁr пЂ« l пЂ©
0
0
пѓЄ
пѓє
пЂЁ
пЂЁ
r
пЂ­
l
r
пЂ­
l
пѓЄ
пѓє
2n
пЂЁt пЂ« b пЂ©
пѓЄ
пѓє
0
0
пѓє
M OpenGL пЂЅ пѓЄ
пЂЁt пЂ­ b пЂ© пЂЁt пЂ­ b пЂ©
пѓЄ
пѓЄ
пѓЄ
пѓЄ
пѓ«
2/24/04
0
0
0
0
пЂЁn
пЂЁn
пЂ« f
пЂ­ f
пЂ­1
пѓє
n пѓє
пѓє
0
пѓ»
В© University of Wisconsin, CS559 Spring 2004
Near/Far and Depth Resolution
вЂў It may seem sensible to specify a very near clipping plane
and a very far clipping plane
вЂ“ Sure to contain entire scene
вЂў But, a bad idea:
вЂ“ OpenGL only has a finite number of bits to store screen depth
вЂ“ Too large a range reduces resolution in depth - wrong thing may be
considered вЂњin frontвЂќ
вЂ“ See Shirley for a more complete explanation
вЂў Always place the near plane as far from the viewer as
possible, and the far plane as close as possible
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Clipping
вЂў Parts of the geometry to be rendered may lie outside the
view volume
вЂ“ View volume maps to memory addresses
вЂ“ Out-of-view geometry generates invalid addresses
вЂ“ Geometry outside the view volume also behaves very strangely
under perspective projection
вЂў Triangles can be split into two pieces, for instance
вЂў Clipping removes parts of the geometry that are outside the
view
вЂў Best done in screen space before perspective divide
вЂ“ Before dividing out the homogeneous coordinate
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Clipping
вЂў Points are trivial to clip - just check which side of the clip
planes they are on
вЂў Many algorithms for clipping lines exist
вЂ“ Next lecture
вЂў Two main algorithms for clipping polygons exist
вЂ“ Sutherland-Hodgman (today)
вЂ“ Weiler (next lecture)
2/24/04
В© University of Wisconsin, CS559 Spring 2004
Clipping Points
вЂў A point is inside the view volume if it is on the вЂњinsideвЂќ of all the
clipping planes
вЂ“ The normals to the clip planes are considered to point inward, toward the
visible stuff
вЂў Now we see why clipping is done in canonical view space
вЂў For instance, to check against the left plane:
вЂ“ X coordinate in 3D must be > -1
вЂ“ In homogeneous screen space, same as: xscreen> -wscreen
вЂў In general, a point, p, is вЂњinsideвЂќ a plane if:
вЂ“ You represent the plane as nxx+nyy+nzz+d=0, with (nx,ny,nz) pointing
inward
вЂ“ And nxpx+nypy+nzpz+d>0
2/24/04
В© University of Wisconsin, CS559 Spring 2004
```
###### Документ
Категория
Презентации
Просмотров
14
Размер файла
202 Кб
Теги
1/--страниц
Пожаловаться на содержимое документа