我正在创建一个3D场景,我刚刚在其中插入了一个立方体对象。它在原点被渲染得很好,但是当我试图旋转它,然后转换它时,我得到了一个巨大的变形立方体。下面是我代码中的问题区域:
D3DXMATRIX cubeROT, cubeMOVE;
D3DXMatrixRotationY(&cubeROT, D3DXToRadian(45.0f));
D3DXMatrixTranslation(&cubeMOVE, 10.0f, 2.0f, 1.0f);
D3DXMatrixTranspose(&worldMatrix, &(cubeROT * cubeMOVE));
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_Direct3D->GetDeviceContext());
// Render the model using the light shader.
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(), m_Light->GetDirection(), m_Light->GetDiffuseColor());
// Reset the world matrix.
m_Direct3D->GetWorldMatrix(worldMatrix);
我发现是转置的cubeMOVE部分给了我这个问题,但我不知道为什么。
这样可以正确地旋转立方体:
D3DXMatrixTranspose(&worldMatrix, &cubeROT);
这正确地转换了多维数据集:
D3DXMatrixTranslation(&worldMatrix, 10.0f, 2.0f, 1.0f);
但这会创建变形的网格:
D3DXMatrixTranspose(&worldMatrix, &cubeMOVE);
我对DirectX非常陌生,所以任何帮助都是非常感谢的。
https://stackoverflow.com/questions/20640220
复制相似问题