One reason that we use four by four matrices to store transforms is that a
single matrix can hold any number of transforms at once. As an example, consider
object three D's rotation paratmeter. Here is a snipet of code from the oil
angler demo. The airplane's three rotation axis are already set. This means that
the airplane is first rotated around its z axis then its y axis, then x.
Internally a transform matrix is made for each rotation. Then these are
multiplied together. Matrix multiplication works like this. For each location in
the resulting matrix, you take the corresponding row of the first matrix.
[inaudible] And the column of the second matrix, and perform a dot product
between these two. For example, to compute element n two four, I compute the dot
product of the fourth row of the first matrix, and the second column of the
second matrix. This gives this set of terms here, added together gives n two
four, 16 dot products later and you have the resulting matrix. To multiply
together our three rotation matrices. We can start at either end. Multiplying Rx
by Ry or Ry by Rz. I've decided to start with Ry and Rz. Multiplying these
together we get some temporary matrix U. We can then multiply together the X
rotation matrix by this temporary matrix. This gives us another matrix call it Q
which consists of all three rotation matrices multiplied together. This
resulting matrix Q can then be used to transform coordinates when an object
coordinate is transformed by this single matrix the coordinate in fact is
rotated by the three rotation matrices in turn it's clearly more efficient to
use a single matrix than three. The scale and translation parameters in the
object 3-d class do the same thing. They create matrices and these all get
multiplied together. Here's the full sequence of transforms that happen for an
object 3-d when using its parameters: scale, the 3 rotations, and translate.
Internally, these matrices are all multiplied together to give a single
resulting matrix m. The parameter in the object 3D class, is, in fact, called
matrix. You can now see why I've been listing the order of matrices as from
right to left. As this is the order we use for multiplying them together.
Multiplying matrices together like this is called concatenation.
変換を保存するのに4×4行列を使う理由の1つは
1つの行列が
一度にあらゆる数の変換を記憶できるからです
Object3Dの回転パラメータを見てみましょう
これは飛行機オブジェクトのオイラー角のコードで
3本の回転軸は設定済みです
飛行機はまずz軸周りを回転し
次にy軸その後x軸というように回転します
内部では変換行列は各回転に対して作られています
それからすべてが掛け算されます
行列の積の求め方をお見せします
左の行列の各値に対し
右のAの行列に対応する行と
Bの行列に対応する列があり
2つの値のドット積を求めます
例えばN24の値を求めるとしたら
行列Aの4行目と
行列Bの2列目のドット積を演算します
そうするとこの式になり
すべてを足すとN24の値が出ます
16回ドット積を計算すれば結果が求められます
3つの回転行列の掛け算ではこうなります
どちら側から始めてもいいですが
RyとRzのから演算しましょう
この2つを掛けて仮のU行列を出します
それからRxとこの仮の行列Uを掛け合わせた結果
Qという別の仮の行列ができます
これは3つの回転行列すべてが含まれた行列です
Q行列は座標を変換に用いることができ
オブジェクトはこの1つの行列によって変換されます
実際には座標は
3つの回転行列によって次々に回転しますが
設定では1つの行列を使う方が効率がいいのです
Object3Dクラスでも
行列を作りパラメータを一度に乗算しましたね
これはObject3Dのパラメータを使った時の
変換シーケンスで
スケーリング、3つの回転、平行移動を表しています
内部でこれらの行列が一度に乗算され
Mという行列ができます
Object3Dクラスのパラメータはmatrixと呼ばれます
なぜ私が行列の式を右から左へ書くか
分かったでしょう
行列の掛け算をする時と同じ順序だからです
このように複数の行列を1つにすることを
行列の連結と呼びます