Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 1
Graphics Pipeline : Geometric Operations
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 2
•• Tools for creating and manipulating a “camera” Tools for creating and manipulating a “camera” that produces pictures of a 3D scenethat produces pictures of a 3D scene
•• Viewing transformationsViewing transformations and and projectionsprojections
•• Perform Perform cullingculling or backor back--face eliminationface elimination
Viewing transformation
3D Rendering Pipeline3D Rendering Pipeline
Object definitionObject definition
Compose sceneCompose sceneDefine view referenceDefine view referenceDefine lightingDefine lighting
CullCullClip to 3D view volumeClip to 3D view volume
Hidden surface removalHidden surface removalRasterizationRasterizationShadingShading
Local coordinate space
World coordinate space
View space
3D screen space
Display space
Modeling transformation
View transformation
Projection
Projection divide
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 4
Yw
Zw
Xw
Compose sceneCompose sceneDefine view referenceDefine view reference
World coordinate space
View space
Modeling transformation
View transformation
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
11w
w
w
viewv
v
v
zyx
Tzyx
( )vvv zyx
( )www zyx
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 5
View plane eye
VU
-N
RTTview = ⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
⋅−⋅−⋅−
=
1000100010001
NeVecVeVecUeVec
T
( )( )000−= eyeeVec
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
1000000
zyx
zyx
zyx
NNNVVVUUU
R
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
11w
w
w
viewv
v
v
zyx
Tzyx
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 5
Viewing transformation
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 6
Viewing Transforms
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
1000000
zyx
zyx
zyx
NNNVVVUUU
RLemma:Where does thismatrix come from:
U
V
Nt
ge
e = Eye Positiong = gaze directiont = view up vector
N= ||g||g
U= ||t x N||t x N
V= N x U
N
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 7
Special Orthogonal Matrics
See 453 slides
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 8
Taxonomy of ProjectionsTaxonomy of Projections
Parallel Perspective
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 9
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
==
1/100010000100001
d
TT persproj
obs: d is N in the picture
Perspective ProjectionsPerspective Projections
dzwzZyYxX
v
v
v
v
====
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 10
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
==
1000000000100001
ortproj TT
Parallel Projections (orthographic)Parallel Projections (orthographic)
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 11
Yw
Zw
Xw
Compose sceneCompose sceneDefine view Define view referencereference
World coordinate space
View space
Modeling transformation
View transformation( )vvv zyx
( )www zyx
ProjectionProjection
3D screen space( )WZYX
Projection DivideProjection Divide
( )sss zyx
Perspective DividePerspective Divide
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 12
PerspectivePerspective
wZz
wYy
wXx
s
s
s
=
=
=
dzwzZyYxX
v
v
v
v
====
where
Parallel Parallel (orthographic)(orthographic)
0===
s
vs
vs
zyyxx
Perspective DividePerspective Divide
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 13
See 453 slides for ramifications of divide by W
Perspective DividePerspective Divide
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 14
View VolumeView Volume
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 15
Xw
eye
VU
View planewindow
eye
Yw
Zw
View volume
We specify it!
-NWhat appears on the screen: projection of part of the scene contained within the view volume
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 16
View planewindow
eye
View volume
dhzx v
v −=
h
d
dhzx v
v =
dhzy v
vol =
dhzy v
v −=
dzv =
fzv =f
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 18
( )
( ) ⎟⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜⎜
⎝
⎛
−−
−⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
000
10000100001
10000100000
000
dffd
dffh
dh
d
Tpers
Scaling (d/h in x and y)Truncated pyramid into a
Regular pyramid
Regular pyramid into a box
Perspective MatrixPerspective Matrix
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 19
( )
( ) ⎟⎟⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜⎜⎜
⎝
⎛
−−
−=
000
100
100
000
dffd
dff
hd
hd
Tpers
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 20
wZz
wYy
wXx
s
s
s
=
=
=
( ) ( )v
v
v
v
zwdf
dfdf
fzZ
yhdY
xhdX
=−
−−
=
=
=where
( )
( ) ⎟⎟⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜⎜⎜
⎝
⎛
−−
−=
000
100
100
000
dffd
dff
hd
hd
Tpers
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 21
OpenGL: Viewing Process, Graphics PipelineOpenGL: Viewing Process, Graphics Pipeline
Scales and shifts each vertex so that all of them that lie inside the view volume will lie inside a standard cube
Provides the CTCombines two effects: Modeling transformations applied to objects +Transformation that orients and positions the camera in space
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 22
OpenGL: Positioning and Aiming the CameraOpenGL: Positioning and Aiming the Camera
View plane
eye
VU
-N
glMatrixMode (GL_MODELVIEW)glLoadIdentity();
glLookAtglLookAt (eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.(eye.x, eye.y, eye.z, look.x, look.y, look.z, up.x, up.y, up.z);z);
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 25
OpenGL: Setting the Camera OpenGL: Setting the Camera
(Parallel Projection)(Parallel Projection)
glMatrixMode (GL_PROJECTION)glLoadIdentity();
glOrthoglOrtho (left, right, bottom, top, near, far);(left, right, bottom, top, near, far);
University of Calgary GraphicsJungle Project CPSC 587 2005
CPSC 587/687
page 26
OpenGL: Setting the Camera OpenGL: Setting the Camera (Perspective Projection)(Perspective Projection)
glMatrixMode (GL_PROJECTION)glLoadIdentity();
glFrustumglFrustum (left, right, bottom, top, near, far);(left, right, bottom, top, near, far);
gluPerspectivegluPerspective ((viewAngleviewAngle, aspect, near, far);, aspect, near, far);
or
more intuitive
3D Rendering Pipeline3D Rendering Pipeline
1. INTRODUCTION
2. IMAGING
3. 3D RENDERING OVERVIEW
4. MODELING (1)shapes and transformations
5. RENDERING (1, 2, 3, 4)
1. Graphics Pipeline : Geometric Operations
6. MODELING (2)Representation and Modeling
7. ANIMATION
8. TOPICS
Object definitionObject definition
Compose sceneCompose sceneDefine view referenceDefine view referenceDefine lightingDefine lighting
CullCullClip to 3D view volumeClip to 3D view volume
Hidden surface removalHidden surface removalRasterizationRasterizationShadingShading
Local coordinate space
World coordinate space
View space
3D screen space
Display space
Modeling transformation
View transformation
Projection
Projection divide
Yw
Zw
Xw
Compose sceneCompose sceneDefine view referenceDefine view reference
World coordinate space
View space
Modeling transformation
View transformation
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
=
⎟⎟⎟⎟⎟
⎠
⎞
⎜⎜⎜⎜⎜
⎝
⎛
11w
w
w
viewv
v
v
zyx
Tzyx
( )vvv zyx
( )www zyx
( ) 0>− FmdoteyeP
Culling (backCulling (back--face removal)face removal)View plane
eye
VU
-N
F is F is back faceback face ifif
Dot ProductDot Product
Angle between Two Vectors
∑=
=⋅=n
iiiwvwvd
1
Sign and Perpendicularity
( )∧∧
⋅= cbθcos
“perpendicular”orthogonalnormal
Normal to a PlaneNormal to a Plane
Finding the Normal VectorsFinding the Normal Vectors
Flat Face:1V
2V 3Vm
( ) ( )2321 VVVVm −×−=
Two Problems:
1V
2V
3V
Vectors nearly parallel, the cross product will be very small,Numerical inaccuracies may result
Polygon is not perfect planar
Finding the Normal VectorsFinding the Normal Vectors
Robust Method (Newell): 1V
2V 3Vm
( )( ) ( )( )
( )( ) ( )( )
( )( ) ( )( )∑
∑
∑
−
=
−
=
−
=
+−=
+−=
+−=
1
0
1
0
1
0
N
iinextiinextiz
N
iinextiinextiy
N
iinextiinextix
yyxxm
xxzzm
zzyym
Vertex and Face TableVertex and Face Table
Shared vertices
Still no topology information
Each face lists vertex references
( )111 ,, zyx
( )222 ,, zyx
( )333 ,, zyx
( )444 ,, zyx
( )555 ,, zyx
F1F2
F3
VERTEX TABLE
V1
V2
V3
V4
V5
( )111 ,, zyx
( )222 ,, zyx
( )333 ,, zyx
( )444 ,, zyx
( )555 ,, zyx
FACE TABLE
V1 V2 V3
V3 V2 V4
V3 V4 V5
F1
F2
F2
Mesh
pt
norm
face
Point3
x, y, zVector3
dx, dy, dz
VertexID
vertIndexnormIndex
numVerts
numNormals
numFacesnVerts
Face
vert
( ) 0>− FmdoteyeP
Culling (backCulling (back--face removal)face removal)View plane
eye
VU
-N
F is F is back faceback face ifif
void Mesh :: draw ()
{
for (int f = 0; f < numFaces; f++)
{
glBegin (GL_POLYGON)
for (int v = 0; v < face[f].nVerts; v++)
{
int iv = face[f].vert[v].vertIndex;
glVertex3f(pt[iv].x, pt[iv].y, pt[iv].z);
}
glEnd();
}
}
void Mesh :: draw ()
{
for (int f = 0; f < numFaces; f++)
{
If ( isBackFace ( f, eye ) ) continue;glBegin (GL_POLYGON)
for (int v = 0; v < face[f].nVerts; v++)
{
int iv = face[f].vert[v].vertIndex;
glVertex3f(pt[iv].x, pt[iv].y, pt[iv].z);
}
glEnd();
}
}