早前一直被這個問題困惑,但是自己推倒了很多遍也沒推出來。
哎,在gameres上搜了3年前的談話,后來在gamedev搜到了答案。
其實在計算機圖形學中,只要是變換,無論平移,旋轉(zhuǎn),縮放,都是乘一個矩陣。
在模型視圖變換時,頂點乘模型視圖變換矩陣,而頂點對應的頂點法線向量(或其他的法線向量)則要乘模型視圖矩陣的逆轉(zhuǎn)置矩陣。
頂點和法線都是向量,他們的區(qū)別是什么?無非頂點是<x, y, z>表示缺省的<x, y, z, 1>,而法線向量是<x, y, z>表示缺省的<x, y, z, 0>。關于為什么是這樣,不用我說了吧,2個頂點向量減下看看就知道了。
從這點來看,確實不同,或許就是這個不同,造成了變換的不同吧。
法線向量只能保證方向的一致性,而不能保證位置的一致性,所以,所有線向量必須以面的形式進行變換,如下:
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