D3DXMATRIX worldMatrix; //這個(gè)矩陣就從文件中讀進(jìn)來(lái) Device->SetTransform(D3DTS_WORLD, &worldMatrix); 注意,使用宏 D3DTS_WORLD 從世界坐標(biāo)系到觀察坐標(biāo)系變換: 這個(gè)變換動(dòng)作,實(shí)際上是為了簡(jiǎn)化運(yùn)算而做的。這樣變換之后,所有的頂點(diǎn)也就可以直接轉(zhuǎn)換為向量,非常的便于某些計(jì)算。這個(gè)動(dòng)作通常是,將攝像機(jī)平移到世界坐標(biāo)系原點(diǎn),再旋轉(zhuǎn)攝像師,使它的光軸與世界坐標(biāo)系z(mì)軸方向一致。與此同時(shí),空間中的所有幾何體都要隨攝像機(jī)一同變換,以確保攝像機(jī)的視場(chǎng)不變。這個(gè)變換叫取景變換,變換后得到觀察坐標(biāo)系。寫法如下: D3DXMATRIX ViewMatrix; D3DXVECTOR3 position, targetPoint, worldUp; D3DXMatrixLookAtLH(&ViewMatrix, //[OUT], 計(jì)算出的變換矩陣 &position, //攝像機(jī)位置 &targetPoint, //攝像機(jī)的觀察朝向 &worldUp);//攝像機(jī)的y朝向,也就是頭的朝向 Device->SetTransform(D3DTS_VIEW, &ViewMatrix); 注意宏,D3DTS_VIEW 其實(shí),D3DXMatrixLookAtLH()函數(shù)只是類似功能函數(shù)中的一個(gè),注意后綴 LH 這表示左手坐標(biāo)系,對(duì)應(yīng)的還有一個(gè)右手坐標(biāo)系,它們的區(qū)別在于:左手系 其z軸向里為正;右手系向外為正。 D3DXMatrixLookAtLH()函數(shù)解析: The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixLookAtLH function can be used as a parameter for another function. This function uses the following formula to compute the returned matrix. zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y zaxis.y 0 xaxis.z yaxis.z zaxis.z 0 -dot(xaxis, eye) -dot(yaxis, eye) -dot(zaxis, eye) l 5.
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注