Hierarchical Modeling
Hierarchical Modeling
Computer
Graphics
Hierarchical Modeling
M=TRS
1
2/19/15
2
2/19/15
upper
arm
lower
arm
hammer
base
Absolute
Transforma9ons
q Each
part
of
the
object
is
transformed
independently
rela9ve
to
the
origin:
3
2/19/15
Rela9ve
Transforma9ons
q BeUer:
transform
each
object
rela-ve
to
its
parent
Step 1: Translate the base and its descendants by (5,0,0)
Rela9ve Transforma9ons
Step
2:
Rotate
the
lower
arm
and
its
descendants
by
-‐90
degrees
about
the
local
y
axis
4
2/19/15
Hierarchical Transforms
Ar9culated
Models
• Rigid
parts
connected
by
joints
rla!
rll
!
lll
!
l-- left!
r-- right!
-u- upper!
-l- !lower!
--a !arm!
--l !leg!
5
2/19/15
b c α
A
B want
a A α
B
A
b a=c
6
2/19/15
α
A
a
A B
A
a
• You
can
see
B
peeking
out
from
behind
A
α
A
A
B
A α
B
a a c
7
2/19/15
α
A
A
A B B
a c a c
S b
Making
an
Arm,
step
5
β
a=c
α
A
A
B A
B
a c
a c
8
2/19/15
α
A
• Next,
rotate
by
the
“shoulder”
angle
-‐β
– again,
A
and
B
rotate
together
A b
B
a c β
a=c
A
S
Making
an
Arm,
last
step
b
β
a=c
α
A
a=c
b A
a=c
A
9
2/19/15
Hierarchical
Transforms
S b
TSR-‐βT-‐b
β
a=c
α
A
Upper
arm
B
Lower
Arm
A
20
60
• Given x, y, α, β, θ1 and θ2, draw the scooter.
10
2/19/15
Step
1
• Write
func9ons
that
draw
parts
in
default
loca9on:
40
5
20
60
Step
2
• Construct
the
scene
graph
(model
as
a
tree)
40
5
Body
20
60
Lower Upper
Brake Brake
11
2/19/15
Step
3
40
• Label
each
edge
with
transforma9on
5
necessary
to
posi9on
child
with
respect
to
parent,
in
parent’s
default
loca9on
20
Body 60
(transform handle
w.r.t. default body)
(transform break
w.r.t. default handle)
Lower Upper
Brake Brake
Step
3
40
• Tree
Labeling
5
Tx,y
20
Body
60
T30,20R-α
T30Rβ
T-30Rβ
T-35Rθ1
T-35Rθ2
Lower Upper
Brake Brake
12
2/19/15
Step
4
• Code
it
up:
- Make
sure
that
the
transforma9ons
Tx,y
on
each
edge
apply
to
ALL
Body
descendants
T30,20R-α
T30Rβ
T-30Rβ
Handle Back Front
Wheel Wheel
T-35Rθ1 T-35R-θ2
Lower Upper
Brake Brake
13
2/19/15
Robot
Guy
l-- left!
r-- right!
-u- upper! rla!
rul!
lul!
rll!
lll!
14
2/19/15
Torso
rla!
lla!
rll
!
lll
!
Shoulders
Hips
T(…)*R(lua)
rla!
lla!
rll
!
lll
!
15
2/19/15
• Draw:
shaders-‐>setUniform("model",
transform
*
model);
glBindVertexArray(asset-‐>vao);
glDrawArrays(asset-‐>drawType,
asset-‐>drawStart,
asset-‐>drawCount);
• Translate:
transform
=
transform
*
translate(mat4(),
vec3(x,
y,
z));
for
(int
i
=
0;
i
<
child.size();
i++)
child[i]-‐>Translate(x,
y,
z);
16
2/19/15
Hands-‐on
Ac9vity
1
• Understand
the
use
of
assets
and
instances
in
05_asset_instance
• Download
robotmain.cpp
from
the
class
website
and
replace
main.cpp
from
05_asset_instance
by
robotmain.cpp.
Do
not
remove
the
original
main.cpp
(only
the
reference
to
it).
You
will
no9ce
that
robotmain.cpp
does
not
include
any
header
files
–
copy
them
from
the
original
main.cpp!
• Note
the
changes
in
ModelInstance
to
support
a
hierarchical
structure
• Make
sure
you
understand
the
implementa9on
of
ModelInstance
func9ons,
and
how
Translate
and
Rotate
apply
to
all
descendants
• The
func9ons
manipula9ng
the
robot
are
InitRobot
(incomplete),
ResetRobot
(complete)
and
DrawRobot
(incomplete).
Hands-‐on
Ac9vity
2
• GLFW
is
a
library
that
allow
us
to
create
a
window,
and
receive
mouse
and
keyboard
input
in
a
cross-‐pla{orm
way:
– Ini9alize
it
with
glfwInit !
– Create
a
window
with
glfwCreateWindow!
– Clean
up
with
glfwTerminate!
• One
way
to
handle
keyboard
events
is
to
use
the
glfwGetKey
func9on
– It
indicates
whether
a
key
is
pressed
or
not
• TO
DO:
complete
the
Update
func9on
to
handle
keyboard
input
and
change
the
robot
posi9on
interac9vely:
– Select
the
joint
angle
to
alter
based
on
the
key
pressed:
1
for
LUA,
2
for
LLA,
3
for
RUA,
4
for
RLA,
5
for
LUL,
6
for
LLL,
7
for
RUL,
8
for
RLL
– Increase
the
joint
angle
with
the
UP
key,
and
decrease
it
with
the
DOWN
key
– Call
Update
just
before
Render
to
adjust
the
robot
posi9on
• You
may
search
Google
for
GLFW_KEY_UP
to
find
out
what
other
predefined
keys
are
available
17