gpt4 book ai didi

c++ - D3DXMatrix Rotation Axis 旋转错轴

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:00 25 4
gpt4 key购买 nike

我正在使用 directX 编写简单的 3d 应用程序。我是新手,但我想我了解 D3DX 旋转的工作原理。在创建碰撞检测功能时,我注意到球在错误的方向弹跳。代码应更改“方向” vector 中给出的轴方向。相反,它改变了另外两个:

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

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

最佳答案

您已经创建了一个绕 X 轴 180 度的旋转变换。对 (1,2,3) 进行操作会得到 (1,-2,-3),这是您指定的。

用具有法向 N 的平面“弹跳”您的“速度”S vector :

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

关于c++ - D3DXMatrix Rotation Axis 旋转错轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51006290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com