如何在 DirectX 上沿 XYZ 轴旋转对象?
我尝试了这段代码:
D3DXMatrixRotationX(&matRotate, rx);
D3DXMatrixRotationY(&matRotate, ry);
D3DXMatrixRotationZ(&matRotate, rz);
d3ddev->SetTransform(D3DTS_WORLD, &matRotate);
但它似乎总是只旋转最后一次旋转(Z 轴)。
如何同时使用所有 XYZ 轴旋转对象? 我试图找到 OpenGL 旋转的 DirectX 等效项:
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声望才能做到)。
I tried this code:
D3DXMatrixRotationX(&matRotate, rx);
D3DXMatrixRotationY(&matRotate, ry);
D3DXMatrixRotationZ(&matRotate, rz);
d3ddev->SetTransform(D3DTS_WORLD, &matRotate);
But it seems to always only rotate the last rotation (Z axis).
How do i rotate an object with all the XYZ axes at the same time?
Im trying to find DirectX equivalent for OpenGL rotation:
glRotatef(rx, 1, 0, 0);
glRotatef(ry, 0, 1, 0);
glRotatef(rz, 0, 0, 1);
EDIT:
Looks like i figured it out by myself:
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);
IF not, please comment. I cant post it as an answer until 8 hours has passed! (need +7 reputation to do it).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
D3DXMatrixRotationX 不会旋转矩阵,但会创建一个可用于旋转某些内容的矩阵。
所以你可以在每一步之后使用矩阵并旋转其他东西,或者你可以使用 D3DXMatrixRotationYawPitchRoll 这样你只需要创建一次......
编辑:
您的编辑也有效...
D3DXMatrixRotationX doesn't rotate a matrix but creates a matrix that can be used to rotate something.
So it you could use the matrix right afterwards each step and rotate something else or you could use D3DXMatrixRotationYawPitchRoll so that you only need to create one once...
EDIT:
Your edit works too...