多數情況下,在游戲開發過程中,我們需要經常用變換來設置角色的變換。下面以平移、縮放、旋轉來說明一點在矩陣變換中需要注意的地方。
假設有如下數據:
D3DXMatrix rotateMat;
D3DXMatrix scaleMat;
D3DXMatrix translateMat;
...... // 這里的 ...... 表示,經過了一系列的變換,在接下來的代碼中,rotateMat、scalMat、translateMat已經是經過變換的了。
D3DXMatrix worldMat;//該矩陣用于保存上面三個合成的最終變換信息
D3DXMatrixIdentity(&worldMat);
D3DXMatrixMultiply(&worldMat, &rotateMat, &worldMat);//注意格式,需要如此寫。
D3DXMatrixMultiply(&worldMat, &scaleMat, &worldMat); //注意格式,需要如此寫。
D3DXMatrixMultiply(&worldMat, &translateMat, &world);//注意格式,需要如此寫。