2 coen 290 - computer graphics i evening’s goals n discuss viewing and modeling transformations n...
TRANSCRIPT
![Page 1: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/1.jpg)
![Page 2: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/2.jpg)
2COEN 290 - Computer Graphics I
Evening’s Goals
Discuss viewing and modeling transformations
Describe matrix stacks and their uses Show basic geometric rasterization and
clipping algorithms
![Page 3: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/3.jpg)
3COEN 290 - Computer Graphics I
Modeling Objects
Recall objects are composed of geometric primitives• each primitive is composed of vertices
Model around the origin• model just means
“determine an object’s vertices”
![Page 4: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/4.jpg)
4COEN 290 - Computer Graphics I
Modeling Transformations
Position objects in world coordinates Move coordinate systems, not objects Affects all objects rendered after
transformation Types
• translation• scale• rotation• shear
![Page 5: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/5.jpg)
5COEN 290 - Computer Graphics I
Translation
Move the origin to a new location
![Page 6: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/6.jpg)
6COEN 290 - Computer Graphics I
1000
100
010
001
),,(z
y
x
zyxt
t
t
tttT
glTranslate[fd]()
glTranslatef( tx, ty, tz );
![Page 7: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/7.jpg)
7COEN 290 - Computer Graphics I
Scale
Stretch, mirror or decimate a coordinate direction
recthreflect/st1
rinkreflect/sh01
decimate0
shrink10
stretch1
s
s
s
s
Note, there’s a translation applied here to make thingseasier to see
![Page 8: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/8.jpg)
8COEN 290 - Computer Graphics I
glScale[fd]()
glScalef( sx, sy, sz );
1000
000
000
000
),,(z
y
x
zyxs
s
s
sssS
![Page 9: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/9.jpg)
9COEN 290 - Computer Graphics I
Rotation
Rotate coordinate system about an axis in space
Note, there’s a translation applied here to make thingseasier to see
![Page 10: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/10.jpg)
10
COEN 290 - Computer Graphics I
glRotate[fd]()
glRotatef( angle, x, y, z );
0
0
0
xy
xz
yz
S
zyxu
zyxv
vv
SuuIuuM tt )sin())(cos(
1000
0
0
0
vR M
![Page 11: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/11.jpg)
11
COEN 290 - Computer Graphics I
Some Additional Rotation Examples
1000
0)cos()sin(0
0)sin()cos(0
0001
xR
1000
0)cos(0)sin(
0010
0)sin(0)cos(
yR
![Page 12: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/12.jpg)
12
COEN 290 - Computer Graphics I
Shear
Scaling in one dimension depends on another
For example
No OpenGL command• load custom matrix
zfyfxx xzxy
![Page 13: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/13.jpg)
13
COEN 290 - Computer Graphics I
Shear
Making a shear matrix
1000
01
01
01
zyzx
yzyx
xzxy
ff
ff
ff
H
![Page 14: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/14.jpg)
14
COEN 290 - Computer Graphics I
Other OpenGL Matrix Commands
glMultMatrix( m )• multiples the current matrix by m
glLoadMatrix( m )• replaces the current matrix by m
glLoadIdentity()• replace the current matrix with an identity
matrix
![Page 15: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/15.jpg)
15
COEN 290 - Computer Graphics I
OpenGL Matrix Format
GLfloat m[16];
151173
141062
13951
12840
mmmm
mmmm
mmmm
mmmm
![Page 16: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/16.jpg)
16
COEN 290 - Computer Graphics I
Modeling Transforms and our Pipeline
World
Coordinates
Eye
Coordinates
ClipCoordinates
NDC’s
PerspectiveDivide
ProjectionTransformation
Model
Coordinates
ModelingTransformations
![Page 17: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/17.jpg)
17
COEN 290 - Computer Graphics I
Using Multiple Modeling Transforms
Multiple modeling transforms form a composite modeling transform
Individual transform matrices are multiplied together• for example
),,()(),,( zyxvzyx sssSRtttTM
![Page 18: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/18.jpg)
18
COEN 290 - Computer Graphics I
Multiplying Matrices
Matrix multiplication is not commutative• in general,• order of operations is important
OpenGL multiples matrices on the right
BAAB
DCBADCBA
![Page 19: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/19.jpg)
19
COEN 290 - Computer Graphics I
Independent vs. Dependent Transforms
Every modeling transform affects the model coordinate system
Transformations accumulate• we record every transformation every made• to undo a transform, we’d need to do the
inverse transform– this is very inconvenient
![Page 20: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/20.jpg)
20
COEN 290 - Computer Graphics I
A Stack Based Solution
We create a stack containing matrices Any transform multiples the top of stack Push makes a copy and pushes it onto the
stack Pop discards the top of stack
![Page 21: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/21.jpg)
21
COEN 290 - Computer Graphics I
A Stack Based Solution ( cont. )
w
z
y
x
ProjectionTransformation
1wz
wywx
ModelingTransformations
![Page 22: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/22.jpg)
22
COEN 290 - Computer Graphics I
OpenGL Matrix Stack Commands
Top of stack matrix is called the current matrix
glPushMatrix()• copy the current matrix and pushes it
glPopMatrix()• pop the current matrix
![Page 23: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/23.jpg)
23
COEN 290 - Computer Graphics I
OpenGL Matrix Stacks
Why multiple matrix stacks?• certain techniques are done in different spaces
glMatrixMode( mode )• choose which stack to manipulate
–GL_MODELVIEW–GL_PROJECTION
![Page 24: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/24.jpg)
24
COEN 290 - Computer Graphics I
Current Transformation Pipeline
World
Coordinates
Eye
Coordinates
ClipCoordinates
NDC’s
PerspectiveDivide
ProjectionTransformation
Model
Coordinates
Model
Coordinates
Model
Coordinates
ModelingTransformations
![Page 25: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/25.jpg)
25
COEN 290 - Computer Graphics I
Eye coordinates are nice, but ...
Eye coordinates are restrictive• eye’s positioned at the origin• looking down the -z axis
What if we want to look at the scene from somewhere else?• use a viewing transformation
![Page 26: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/26.jpg)
26
COEN 290 - Computer Graphics I
Viewing Transformations
Reorient world coordinates to match eye coordinates
Basically just a modeling transform• affects the entire scene• usually a translation and a rotation
Usually set up after the projection transform, but before any modeling transforms
![Page 27: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/27.jpg)
27
COEN 290 - Computer Graphics I
The Simplest Viewing Transform
“Push” the origin into the viewing frustum
z
near
far
y y
farneartz 21
![Page 28: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/28.jpg)
28
COEN 290 - Computer Graphics I
polarview()
Useful if you want to view an entire object
polarview( dist, elev, azim, twist ){
glTranslatef( 0, 0, -dist );glRotatef( -twist, 0, 0, 1 );glRotatef( -elev, 1, 0, 0 );glRotatef( azim, 0, 0, 1 );
}• update elev and azim for interactive viewing
![Page 29: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/29.jpg)
29
COEN 290 - Computer Graphics I
Transforming World to Eye Coordinates
Viewing transformgluLookAt( eyex, eyey, eyez,
lookx, looky, lookz,
upx, upy, upz );
Creates an orthonormal basis• a set of linearly independent vectors of unit
length
![Page 30: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/30.jpg)
30
COEN 290 - Computer Graphics I
Creating an Orthonormal Basis
1000
0
0
0
ˆˆˆ
ˆ
ˆ
ˆ
ˆ
zyx
zyx
zyx
upn
upn
eyelook
eyelook
nnn
vvv
uuu
nuv
u
n
![Page 31: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/31.jpg)
31
COEN 290 - Computer Graphics I
gluLookAt( eyex, eyey, eyez,
lookx, looky, lookz,
upx, upy, upz ){
/* Create matrix m */
glMultMatrixf( m ); glTranslatef( -eyex, -eyey, -eyez );}
![Page 32: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/32.jpg)
32
COEN 290 - Computer Graphics I
Our Final Transformation Pipeline
World
Coordinates
Eye
Coordinates
ClipCoordinates
NDC’s
PerspectiveDivide
ProjectionTransformation
ViewingTransformation
Model
Coordinates
Model
Coordinates
Model
Coordinates
ModelingTransformations
![Page 33: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/33.jpg)
33
COEN 290 - Computer Graphics I
Retrieving Matrix information
GLfloat m[16];
glGetFloatv( which, m ); which is which matrix stack to access
• GL_MODELVIEW_MATRIX• GL_PROJECTION_MATRIX
![Page 34: 2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric](https://reader035.vdocuments.us/reader035/viewer/2022062520/5697bfab1a28abf838c9ae48/html5/thumbnails/34.jpg)
34
COEN 290 - Computer Graphics I
Putting it all Together
General flow of transformations projection transformation viewing transformation push matrix modeling transformation render pop matrix goto as necessary