scene graphs & modeling transformations...•julian beever. 46 projective transformations...
TRANSCRIPT
1
Scene Graphs &Modeling Transformations
COS 426, Spring 2020
Felix Heide
Princeton University
2
3D Object Representations
• Points• Range image
• Point cloud
• Surfaces• Polygonal mesh
• Subdivision
• Parametric
• Implicit
• Solids• Voxels
• BSP tree
• CSG
• Sweep
• High-level structures• Scene graph
• Application specific
3
3D Object Representations
• What object representation is best for this?
4
3D Object Representations
• Desirable properties of an object representation• Easy to acquire• Accurate• Concise• Intuitive editing• Efficient editing• Efficient display• Efficient intersections• Guaranteed validity• Guaranteed smoothness• etc.
(CS Building, Princeton University)
5
Overview
• Scene graphs• Geometry & attributes
• Transformations
• Bounding volumes
• Transformations• Basic 2D transformations
• Matrix representation
• Matrix composition
• 3D transformations
6
Scene Graphs
Building
Floor 4 Floor5Floor 3Floor 2Floor 1
Chair KBookshelf 1
Desk ChairBookshelf
Desk 1 Desk 2 Chair 1
Floor Furniture
Office NOffice 1
Office Furniture
Definitions
Instances
7
Scene Graphs
• Hierarchy (DAG) of nodes, where each may have:• Geometry representation
• Modeling transformation
• Parents and/or children
• Bounding volume
Base[M1]
Upper Arm[M2]
Lower Arm[M3]
Robot ArmAngel Figures 8.8 & 8.9
8
Scene Graphs
• Advantages • Allows definitions of objects in own coordinate systems
y
x
z
9
IcosahedronTetrahedronCube Octahedron Dodecahedron
Level B
…
Instance 4Instance 1
Level A
…
Instances
Definitions
Instance 4Instance 1
Scene
…
Instance 4Instance 1
Scene Graphs
• Advantages • Allows definitions of objects in own coordinate systems
• Allows use of object definition multiple times in a scene
H&B Figure 109
10
Scene Graphs
• Advantages • Allows definitions of objects in own coordinate systems
• Allows use of object definition multiple times in a scene
• Allows hierarchical processing (e.g., intersections)
Haverkort
11
Scene Graphs
• Advantages • Allows definitions of objects in own coordinate systems
• Allows use of object definition multiple times in a scene
• Allows hierarchical processing (e.g., intersections)
• Allows articulated animation Base[M1]
Upper Arm[M2]
Lower Arm[M3]
Robot ArmAngel Figures 8.8 & 8.9
13
Overview
• Scene graphs• Geometry & attributes
• Transformations
• Bounding volumes
• Transformations• Basic 2D transformations
• Matrix representation
• Matrix composition
• 3D transformations
14
2D Modeling Transformations
ScaleRotate
Translate
ScaleTranslate
x
y
World Coordinates
Modeling
Coordinates
15
2D Modeling Transformations
x
y
World Coordinates
Modeling
Coordinates
Let’s look
at this in
detail…
16
2D Modeling Transformations
x
y
Modeling
Coordinates
17
2D Modeling Transformations
x
y
Modeling
Coordinates
Scale .3, .3Rotate -90
Translate 5, 3
18
2D Modeling Transformations
x
y
Modeling
Coordinates
Scale .3, .3Rotate -90
Translate 5, 3
19
2D Modeling Transformations
x
y
Modeling
Coordinates
Scale .3, .3Rotate -90
Translate 5, 3
World Coordinates
20
Basic 2D Transformations
• Translation:• x’ = x + tx• y’ = y + ty
• Scale:• x’ = x * sx • y’ = y * sy
• Shear:• x’ = x + hx*y• y’ = y + hy*x
• Rotation:• x’ = x*cosQ - y*sinQ• y’ = x*sinQ + y*cosQ
Transformations can be combined
(with simple algebra)
21
Basic 2D Transformations
• Translation:• x’ = x + tx• y’ = y + ty
• Scale:• x’ = x * sx • y’ = y * sy
• Shear:• x’ = x + hx*y• y’ = y + hy*x
• Rotation:• x’ = x*cosQ - y*sinQ• y’ = x*sinQ + y*cosQ
22
Basic 2D Transformations
• Translation:• x’ = x + tx• y’ = y + ty
• Scale:• x’ = x * sx• y’ = y * sy
• Shear:• x’ = x + hx*y• y’ = y + hy*x
• Rotation:• x’ = x*cosQ - y*sinQ• y’ = x*sinQ + y*cosQ
x’ = x*sx
y’ = y*sy
(x,y)
(x’,y’)
23
Basic 2D Transformations
• Translation:• x’ = x + tx• y’ = y + ty
• Scale:• x’ = x * sx • y’ = y * sy
• Shear:• x’ = x + hx*y• y’ = y + hy*x
• Rotation:• x’ = x*cosQ - y*sinQ• y’ = x*sinQ + y*cosQ
x’ = (x*sx)*cosQ - (y*sy)*sinQ
y’ = (x*sx)*sinQ + (y*sy)*cosQ
(x’,y’)
24
Basic 2D Transformations
• Translation:• x’ = x + tx• y’ = y + ty
• Scale:• x’ = x * sx • y’ = y * sy
• Shear:• x’ = x + hx*y• y’ = y + hy*x
• Rotation:• x’ = x*cosQ - y*sinQ• y’ = x*sinQ + y*cosQ
x’ = ((x*sx)*cosQ - (y*sy)*sinQ) + tx
y’ = ((x*sx)*sinQ + (y*sy)*cosQ) + ty
(x’,y’)
25
Basic 2D Transformations
• Translation:• x’ = x + tx• y’ = y + ty
• Scale:• x’ = x * sx • y’ = y * sy
• Shear:• x’ = x + hx*y• y’ = y + hy*x
• Rotation:• x’ = x*cosQ - y*sinQ• y’ = x*sinQ + y*cosQ
x’ = ((x*sx)*cosQ - (y*sy)*sinQ) + tx
y’ = ((x*sx)*sinQ + (y*sy)*cosQ) + ty
26
Overview
• Scene graphs• Geometry & attributes
• Transformations
• Bounding volumes
• Transformations• Basic 2D transformations
• Matrix representation
• Matrix composition
• 3D transformations
27
Matrix Representation
• Represent 2D transformation by a matrix
• Multiply matrix by column vector apply transformation to point
=
yx
dcba
yx''
dcba
dycxy
byaxx
+=
+=
'
'
28
Matrix Representation
• Transformations combined by multiplication
=
yx
lk
ji
hg
fedcba
yx''
Matrices are a convenient and efficient way
to represent a sequence of transformations
29
=
yx
dcba
yx''
2x2 Matrices
• What types of transformations can be represented with a 2x2 matrix?
2D Identity?
yyxx
==''
=
yx
yx
1001
''
2D Scale around (0,0)?
ysyyxsxx
*'*'
==
=
yx
dcba
yx''
=
yx
sysx
yx
00
''
30
2x2 Matrices
• What types of transformations can be represented with a 2x2 matrix?
2D Rotate around (0,0)?
yxyyxx
*cos*sin'*sin*cos'
Q+Q=Q-Q=
=
yx
dcba
yx''
QQQ-Q
=
yx
yx
cossinsincos
''
2D Shear?
yxshyyyshxxx
+=+=
*'*'
=
yx
dcba
yx''
=
yx
shyshx
yx
11
''
𝑠ℎ𝑥
31
2x2 Matrices
• What types of transformations can be represented with a 2x2 matrix?
2D Mirror over Y axis?
yyxx
=-=
''
=
yx
dcba
yx''
-=
yx
yx
1001
''
2D Mirror over (0,0)?
yyxx
-=-=
''
=
yx
dcba
yx''
-
-=
yx
yx
1001
''
32
=
yx
dcba
yx''
2x2 Matrices
• What types of transformations can be represented with a 2x2 matrix?
2D Translation?
tyyytxxx
+=+=
''
Only linear 2D transformations
can be represented with a 2×2 matrix
NO.
33
Linear Transformations
• 2D linear transformations are combinations of …• Scale,
• Rotation,
• Shear, and
• Mirror
• Properties of linear transformations:• Satisfies:
• Origin maps to origin
• Points at infinity stay at infinity
• Lines map to lines
• Parallel lines remain parallel
• Ratios are preserved
• Closed under composition
)()()( 22112211 pppp TsTsssT +=+
=
y
x
dc
ba
y
x
'
'
34
2D Translation
• 2D translation represented by a 3x3 matrix• Point represented with homogeneous coordinates
tyyytxxx
+=+=
''
=
1100
10
01
1
'
'
y
x
ty
tx
y
x
35
Homogeneous Coordinates
• Add a 3rd coordinate to every 2D point• (x, y, w) represents a point at location (x/w, y/w)
• (x, y, 0) represents a point at infinity
• (x, 0, 0) and (0, y, 0) are not allowed
1 2
1
2(2,1,1) or (4,2,2) or (6,3,3)
Convenient coordinate system to
represent many useful transformations
x
y
36
Basic 2D Transformations
• Basic 2D transformations as 3x3 matrices
Q-Q
=
1100
0cossin
0sincos
1
'
'
y
x
y
x
=
1100
10
01
1
'
'
y
x
ty
tx
y
x
=
1100
01
01
1
'
'
y
x
shy
shx
y
x
Translate
Rotate Shear
=
1100
00
00
1
'
'
y
x
sy
sx
y
x
Scale
37
Affine Transformations
• Affine transformations are combinations of …• Linear transformations, and
• Translations
• Properties of affine transformations:• Origin does not necessarily map to origin
• Points at infinity remain at infinity
• Lines map to lines
• Parallel lines remain parallel
• Ratios are preserved
• Closed under composition
=
wyx
fedcba
wyx
100
''
38
Projective Transformations
• The world is in 3D, the screen is flat. How to Project?
(Thanks Justin the almighty)
39
Projective Transformations
• Drop one axis?
40
Projective Transformations
• What is wrong with this picture?
41
Projective Transformations
• Pinhole camera model
42
Projective Transformations
• Perspective Warp!
43
Projective Transformations
• OpenGL’s version
2𝑛
𝑤0 0 0
02𝑛
ℎ0 0
0 0 −𝑓 + 𝑛
𝑓 − 𝑛−
2𝑓𝑛
𝑓 − 𝑛0 0 −1 0
𝑛ear
𝑓ar
𝑤
ℎ
http://www.songho.ca/opengl/gl_projectionmatrix.html
Demo: http://www.songho.ca/opengl/gl_transform.html
+
44
Projective Transformations
• Projective transformations (homographies):• Affine transformations, and
• Projective warps
• Properties of projective transformations:• Origin does not necessarily map to origin
• Point at infinity may map to finite point
• Lines map to lines
• Parallel lines do not necessarily remain parallel
• Ratios are not preserved
• Closed under composition
=
wyx
ihgfedcba
wyx
'
''
45
Projective Transformations
• Perspective warp in art• Julian Beever
46
Projective Transformations
• Perspective warp in art• Julian Beever
47
Overview
• Scene graphs• Geometry & attributes
• Transformations
• Bounding volumes
• Transformations• Basic 2D transformations
• Matrix representation
• Matrix composition
• 3D transformations
48
Matrix Composition
• Transformations can be combined by matrix multiplication
QQQ-Q
=
w
yx
sysx
tytx
w
yx
100
0000
1000cossin0sincos
100
1001
'
''
p’ = T(tx,ty) R(Q) S(sx,sy) p
49
Matrix Composition
• Matrices are a convenient and efficient way to represent a
sequence of transformations• General purpose representation
• Hardware matrix multiply
• Efficiency with premultiplication• Matrix multiplication is associative
p’ = (T * (R * (S*p) ) )
p’ = (T*R*S) * p
50
Matrix Composition
• Be aware: order of transformations matters• Matrix multiplication is not commutative
p’ = T * R * S * p
“Global” “Local”
51
Matrix Composition
• Rotate by Q around arbitrary point (a,b)• M=T(a,b) * R(Q) * T(-a,-b)
• Scale by sx,sy around arbitrary point (a,b)• M=T(a,b) * S(sx,sy) * T(-a,-b)
(a,b)
(a,b)
The trick:
First, translate (a,b) to the origin.
Next, do the rotation about origin.
Finally, translate back.
(Use the same trick.)
52
Overview
• Scene graphs• Geometry & attributes
• Transformations
• Bounding volumes
• Transformations• Basic 2D transformations
• Matrix representation
• Matrix composition
• 3D transformations
53
3D Transformations
• Same idea as 2D transformations• Homogeneous coordinates: (x,y,z,w)
• 4x4 transformation matrices
=
wzyx
ponmlkjihgfedcba
wzyx
''
''
54
Basic 3D Transformations
=
wz
yx
wz
yx
1000010000100001
'
''
=
wz
yx
tz
tytx
wz
yx
1000100
010001
'
''
=
wz
yx
sz
sysx
wz
yx
1000000
000000
'
''
-
=
wz
yx
wz
yx
1000010000100001
'
''
Identity Scale
Translation Mirror over X axis
55
Basic 3D Transformations
QQQ-Q
=
wz
yx
wz
yx
1000010000cossin00sincos
'
''
Rotate around Z axis:
Q-Q
=
wz
yx
wz
yx
10000cos0sin00100sin0cos
'
''
Rotate around Y axis:
QQQ-Q
=
wz
yx
wz
yx
10000cossin00sincos00001
'
''
Rotate around X axis:
56
Transformations in Scene Graphs
Rose et al. `96
Root
LHip
LKnee
LAnkle
RHip
RKnee
RAnkle
Chest
LCollar
LShld
LElbow
LWrist
LCollar
LShld
LElbow
LWrist
Neck
Head
57
Summary
• Scene graphs• Hierarchical
• Modeling transformations
• Bounding volumes
• Coordinate systems• World coordinates
• Modeling coordinates
• 3D modeling transformations• Represent most transformations by 4x4 matrices
• Composite with matrix multiplication (order matters)