旋轉(zhuǎn)矩陣 look at

視圖矩陣相機(jī)世界矩陣的逆矩陣;
位于相機(jī)坐標(biāo)系里的點(diǎn),乘以相機(jī)世界矩陣,即轉(zhuǎn)到了世界坐標(biāo)系里;
位于世界坐標(biāo)系里的點(diǎn),乘以視圖矩陣(相機(jī)世界矩陣的逆矩陣),即轉(zhuǎn)到了相機(jī)坐標(biāo)系里;
在相機(jī)坐標(biāo)系里,相機(jī)對(duì)著-z軸;
下面方法構(gòu)造出來(lái)的矩陣是相機(jī)世界矩陣,要想構(gòu)造視圖矩陣,得求逆矩陣,見(jiàn)這里

1644303468(1).png

Matrix44f lookAt(const Vec3f& from, const Vec3f& to, const Vec3f& tmp = Vec3f(0, 1, 0)) 
{ 
    Vec3f forward = normalize(from - to); 
    Vec3f right = crossProduct(normalize(tmp), forward); 
    Vec3f up = crossProduct(forward, right); 
 
    Matrix44f camToWorld; 
 
    camToWorld[0][0] = right.x; 
    camToWorld[0][1] = right.y; 
    camToWorld[0][2] = right.z; 
    camToWorld[1][0] = up.x; 
    camToWorld[1][1] = up.y; 
    camToWorld[1][2] = up.z; 
    camToWorld[2][0] = forward.x; 
    camToWorld[2][1] = forward.y; 
    camToWorld[2][2] = forward.z; 
 
    camToWorld[3][0] = from.x; 
    camToWorld[3][1] = from.y; 
    camToWorld[3][2] = from.z; 
 
    return camToWorld; 
} 
相機(jī)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容