早前一直被這個(gè)問題困惑,但是自己推倒了很多遍也沒推出來。
哎,在gameres上搜了3年前的談話,后來在gamedev搜到了答案。
其實(shí)在計(jì)算機(jī)圖形學(xué)中,只要是變換,無論平移,旋轉(zhuǎn),縮放,都是乘一個(gè)矩陣。
在模型視圖變換時(shí),頂點(diǎn)乘模型視圖變換矩陣,而頂點(diǎn)對(duì)應(yīng)的頂點(diǎn)法線向量(或其他的法線向量)則要乘模型視圖矩陣的逆轉(zhuǎn)置矩陣。
頂點(diǎn)和法線都是向量,他們的區(qū)別是什么?無非頂點(diǎn)是<x, y, z>表示缺省的<x, y, z, 1>,而法線向量是<x, y, z>表示缺省的<x, y, z, 0>。關(guān)于為什么是這樣,不用我說了吧,2個(gè)頂點(diǎn)向量減下看看就知道了。
從這點(diǎn)來看,確實(shí)不同,或許就是這個(gè)不同,造成了變換的不同吧。
法線向量只能保證方向的一致性,而不能保證位置的一致性,所以,所有線向量必須以面的形式進(jìn)行變換,如下:
Transforming Planes
If we have a plane vector n = [a, b, c, d] which describes a plane then for any point p = [x, y, z, 1] in that plane the follow equation holds:
nt p = ax + by + cz + d = 0
If for a point p on the plane, we apply an invertible transformation R to get the transformed point p1, then the plane vector n1 of the transformed plane is given by applying a corresponding transformation Q to the original plane vector n where Q is unknown.
p1 = R p
n1 = Q n
We can solve for
Q by using the resulting plane equation:
n1t p1 = 0
Begin by substituting for
n1 and
p1:
(Q n)t (R p) = 0
nt Qt R p = 0
If
Qt R =
I then
nt Qt R p =
nt I p =
nt p = 0 which is given.
Qt R = I
Qt = R-1
Q = (R-1)t
Substituting
Q back into our plane vector transformation equation we get:
n1 = Q n = (R-1)t n