我試過這段代碼:如何在DirectX上旋轉XYZ軸上的對象?
D3DXMatrixRotationX(&matRotate, rx);
D3DXMatrixRotationY(&matRotate, ry);
D3DXMatrixRotationZ(&matRotate, rz);
d3ddev->SetTransform(D3DTS_WORLD, &matRotate);
但它似乎永遠只旋轉旋轉最後(Z軸)。
如何在同一時間旋轉所有XYZ軸的物體? 我試着去尋找的DirectX相當於對OpenGL旋轉:
glRotatef(rx, 1, 0, 0);
glRotatef(ry, 0, 1, 0);
glRotatef(rz, 0, 0, 1);
編輯: 貌似我想通了由自己:
D3DXMATRIX matRotateX;
D3DXMATRIX matRotateY;
D3DXMATRIX matRotateZ;
D3DXMatrixRotationX(&matRotateX, rx);
D3DXMatrixRotationY(&matRotateY, ry);
D3DXMatrixRotationZ(&matRotateZ, rz);
D3DXMATRIX matRotate = matRotateX*matRotateY*matRotateZ;
d3ddev->SetTransform(D3DTS_WORLD, &matRotate);
如果沒有,請發表評論。我不能將它作爲答案發布,直到8小時過去! (需要+7聲望才能做到)。
我不知道DirectX,但你可能有錯誤的順序乘法。如果您知道您的訂單是正確的,請忽略此評論,否則請檢查它。 – 2012-01-09 13:43:41