階層モデル(Hierarchical Modeling

Download Report

Transcript 階層モデル(Hierarchical Modeling

6,階層的モデリング
インタラクティブCG05S
蔡 東生
参考文献
• CGテキスト 2−4−3
• Angel 9.1-9.6,9.8
• OpenGL プログラミングガイド、
レッドブック、3章
記号とインスタンス
• ほとんどのグラフィックAPIはいくつかの幾何
的プリミティブをもっている:
– 球、立方体、円筒
– これらの手続き関数は点(points)を与えてくれる。
しかしこれらの手続き関数は点Pでしかない
• これらの記号はインスタンス変換を通して実
体化・インスタンス化される
– これらの点はもともと局所座標系をつかい定義さ
れている(例、単位立方体)
Q:上記のインスタンス変換はどのような行列
か?
プリミティブをつなげる
3次元の例:ロボット
アーム
• 3自由度を持つロボットアームに
ついて考えてみよう
– Baseは垂直軸まわりにθ回転
– Lower armはxy-平面内Φ回転
– Upper armはxy-平面内Ψ回転
Q:baseの変換にどのような行列を用いるか?
Q:upper armの変換にはどのような行列か?
Q:lower armの変換にはどのような行列か?
ロボットアームの実装
• ロボットアームはグローバル行列
を保持しつつ、毎ステップごとに計
算できる
行列計算を繰り返すのは無駄!???
よりよいロボットアーム
の実装
• グローバル行列を毎回計算しなおすかわ
りに、グローバル行列にその場所に応じ
た新しい行列を右掛けしていく
OprnGLにおけるロボットアー
ム実装
• OpenGLはmodel-view matrixというグ
ローバル状態行列を保持してい
る,model-view matrixは場所場所に変換
行列を右掛けしていくことによりアップ
デートされていく
ObjectAxes.cpp
階層的モデリング
• 階層的モデルはツリーもしくは
DAGsを使ったインスタンスによって
構成される
• エッジは幾何学的変換を含む
• ノードは幾何形状(と描画属性)を含
む
Q:ロボットアームの場合はどうなるで
あろうか?
複雑な例:人間の人体
モデル
Q:もっとも合理的にこのツリーを横断するには
どうすればいいか?
Modeling with Transformation
• You’ve learned everything
you need to know to make
a stick person out of
cubes.
• Just translate, rotate, and
scale each one to get the
right size, shape, position,
and orientation.
• Looks great, until you try
to make it move.
The Right Control Knobs
• As soon as you want to
change something, the
model falls apart
• Reason: the thing you’re
modeling is constrained
but your model doesn’t
know it
• Wanted:
– some sort of representation of
structure
– a set of “control knobs”
(parameters) that make it easy to
move our stick person through
legal configurations
• This kind of control is
convenient for static
models, and vital for
animation!
• Key: structure the
transformations in the
right way: using a
Making an Articulated Model
r A
pB q
• A minimal 2-D jointed object:
– Two pieces, A (“forearm”) and B (“upper arm”)
– Attach point q on B to point r on A (“elbow”)
– Desired control knobs:
• T:
shoulder position (point at which p winds
up)
• u:
shoulder angle (A and B rotate together
about p)
• v:
elbow angle (A rotates about r, which
stays attached to p)
Making an Arm, step 1
r
A
• Start with A and B in their
untransformed configurations (B is
hiding behind A)
• First apply a series of
transformations to A, leaving B
where it is…
Making an Arm, step 2
r
A
pB q
r
A
• Translate by -r, bringing r to
the origin
• You can now see B peeking
out from behind A
Making an Arm, step 3
pB q
r
A
pB q
• Next, we rotate A by v (the
“elbow” angle)
Making an Arm, step 4
pB q
pB q
• Translate A by q, bringing r and q
together to form the elbow joint
• We can regard q as the origin of
the elbow coordinate system, and
regard A as being in this
coordinate system.
Making an Arm, step 5
pB q
pB q
• From now on, each transformation
applies to both A and B (This is
important!)
• First, translate by -p, bringing p to
the origin
• A and B both move together, so the
elbow doesn’t separate!
Making an Arm, step 6
pB q
• Then, we rotate by u, the
“shoulder” angle
• Again, A and B rotate
together
Making an Arm, step 7
• Finally, translate by T, bringing the
arm where we want it
• p is at origin of shoulder coordinate
system
So What Have We Done?
• Seems more complicated than just
translating and rotating each piece
separately
• But the model is easy to
modify/animate:
– Remember the transformation sequence,
and the parameters you used—they’re part
of the model.
– Whenever the parameters change, reapply
all of the transformations and draw the result
• The model will not fall apart!!!
• Note:
– u, v, and T are parameters of the model.
– but p, q, and r are structural constants.
– Changing u,v, or T wiggles the arm
– Changing p,q, or r dismembers it (useful only in
video games)
Transformation Hierarchies
• This is the build-an-arm
sequence, represented
as a tree
• Interpretation:
Trans T
Rot u
Trans -p
Trans q
Rot v
Trans -r
B
– Leaves are geometric
primitives
– Internal nodes are
transformations
– Transformations apply
to everything under
them—start at the
bottom and work your
way up
• You can build a wide
range of models this
Control
way
Knob
Primitive
A
Structural
Transformation Hierarchies
• Another point of view:
• The shoulder
coordinate
transformation moves
everything below it with
respect to the shoulder:
Trans T
Rot u
Trans -p
Trans q
Rot v
Trans -r
A
B
–B
– A and its transformation
• The elbow coordinate
transformation moves A
with respect to the
elbow
Shoulder
coordinate xform
Elbow coordinate
xform
Primitive
A Schematic Humanoid
• Each node
represents
hip
torso l. leg1 r. leg1
shoulder l. leg2 r. leg 2
l. arm1 r. arm1 neck
l. arm2 r. arm2 head
– rotation(s)
– geometric
primitive(s)
– struct.
transformations
• The root can be
anywhere. We
chose the hip
(can re-root)
• Control knob
for each joint
angle, plus
global position
and orientation
• A realistic
human would
be much more
Directed Acyclic
• This is a graph, so
you can re-root it.
Graph
• It’s directed,
rendering traversal
hip
only follows links
one way.
• It’s acyclic, to avoid
infinite loops in
torso l. leg1 r. leg1
rendering.
• Not necessarily a
tree.
shoulder l. leg2 r. leg 2
– e.g. l.arm2 and r.arm2
l. arm1 r. arm1 neck
l. arm2 r. arm2 head
primitives might be two
instantiations (one
mirrored) of the same
geometry
OpenGLにおける人体
モデルの実装
o-link arm, revisited, in Open
Trace of Opengl
calls
glLoadIdentity()
;
glOrtho(…);
glPushMatrix();
glTranslatef(Tx,
Ty,0);
glRotatef(u,0,0,
1);
glTranslatef(px,-py,0);
glPushMatrix();
glTranslatef(qx,
qy,0);
glRotatef(v,0,0,
1);
glTranslatef(rx,-ry,0);
Draw(A);
glPopMatrix();
Draw(B);
glPopMatrix();
Trans T
Rot u
Trans -p
Trans q
Rot v
Trans -r
A
B
変換の順番
• 最初の家のモデルに戻って考えよ
う
• 変換される家を書くためには、
OpenGLでは以下のようにプログラ
ムを書く
• ここで注意すべきは、複合変換行
列を作るためには左からスタートし
てそれぞれの変換行列をその後に
右掛けしていくことである
グローバル、固定座標
系システム
• 変換を考える一つのやり方は
各点の動きをグローバル、固
定座標系で考えることである
– 変換行列を左から右に、T, R, S
の順番で掛け合わせていく
– 次に変換行列をオブジェクト点に
掛ける:複合行列TRSをPの全て
の点に掛け合わせる
• この変換は点を全て最初の位置か
ら最終位置に移す
局所、座標変換システ
ム
• もう一つの変換の考え方はプリミティ
ブが最終的に描かれる局所座標系
に作用させることである
• これは先に述べた方法と全く同じ
アニメーション
• 上記の例は関節モデル
(Articulated Model)とよばれ
– 固体部品
– ジョイント(関節)接続
• これらは時間の関数としてジョ
イント角度(あるいは他の表示
パラメター)を決めることにより
アニメーションできる
キーフレームアニメーション
• もっとも一般的につくられるキャラク
タアニメーションはキーフレームア
ニメーションである
– それぞれのジョイントは様々なキーフ
レームで定義される
– システムはキーフレーム間を補間する
これを行うには以下のことが必要:
ーなめらかなキーフレーム間の補間:ス
プライン
ーとても良いインタラクティブシステム
ーアニメータの高度な技術
シーングラフ
• 階層的モデリングの考えは全
体のシーンにも適応される
– 多くの異なるオブジェクト
– ライト
– カメラ位置
• これらはシーンツリーとかシー
ングラフと呼ばれている
まとめ
• 以下のことを覚えよう
• 太文字の用語
• 幾何学変換を使いどのようにしてプ
リミティブは実体化(インスタンス
化)し階層的モデルを作るか
• どのようにしてツリー、DAGモデル
は階層的モデリングに使われてい
るか
• OpenGL変換は階層的モデルでど
のように使われているか
• キーフレームアニメーションはどう
作用するか