D3DXMatrix旋转轴旋转错误的轴

D3DXMatrixRotationAxis rotate the wrong axis

本文关键字:旋转 错误 D3DXMatrix      更新时间:2023-10-16

我正在用directX编写简单的3D应用程序。我是一个新手,但我想我了解 D3DX 旋转的工作原理。 在创建碰撞检测功能时,我注意到球以错误的方向反弹。代码应更改"方向"矢量中给定的轴的方向。相反,它更改了其他 2 个:

speed = D3DXVECTOR3(1.0f, 2.0f, 3.0f);
direction = D3DXVECTOR3(1.0f, 0.0f, 0.0f);
D3DXMATRIX temp;
D3DXMatrixRotationAxis(&temp, &direction, 3.14f);
D3DXVec3TransformCoord(&speed, &speed, &temp);

从断点我知道速度从 1、2、3 变为:

  • _D3DVECTOR {x=0.999999762 y=-2.00477481 z=-2.99681091 } _D3DVECTOR

我在这里做错了什么?这个想法是反转方向矢量中指定的轴。

您已经创建了围绕 X 轴的 180 旋转变换。 在 (1,2,3( 上操作会产生 (1,-2,-3(,这是您指定的。

用具有法线 N 的平面"弹跳"您的"速度"S 向量:

angle = acos(S*N);   // provided that * is an operator for D3DXVec3Dot
axis = S^N;          // provided that ^ is an operator for D3DXVec3Cross
D3DXMatrixRotationAxis(&temp, &axis , angle*2);   // angle is *2
D3DXVec3TransformCoord(&S, &S, &temp);
S=-S;                                             // negate direction