如何在子弹物理学中让刚体的欧拉旋转在 0 到 360 之间
How to get the Euler rotation of a rigid body between 0 to 360 in Bullet Physics?
我目前正在尝试获取对象的旋转。我正在使用C++和子弹物理。这是我的代码:
btScalar x, y, z;
body[0]->getCenterOfMassTransform().getBasis().getEulerZYX(z, y, x);
但是,当我顺时针旋转对象时,我从 y(y 在 Bullet 中是垂直的)轴获得的数字从 0 到 -90 到 0 到 90,最后每旋转四分之一回到 0。它很接近,但我需要的是让它从 0 一直到 360。
项目符号文档说:
void getEulerZYX (btScalar &yaw, btScalar &pitch, btScalar &roll, unsigned int solution_number=1) const
和
solution_number Which solution of two possible solutions ( 1 or 2) are possible values
这是因为欧拉角是模棱两可的。 你试过解决方案 2 吗?
我遇到了同样的问题。我使用带有 Bullet 引擎的 LibGDX,所以我的代码示例在 Java 上,但我确信,它也适用于C++。这是我的解决方案(针对 Z 轴):
body.getWorldTransform().getRotation(mRotation);
// That gives you an angle in all range but excluding (85, 95) and (-95, 85). For other axis you can try to get Pitch or Yaw.
float roll = mRotation.getRoll();
// That gives you an angle in range [0, 240). Clockwise and counterclockwise directions isn't detected.
float angle = mRotation.getAngleAround(0, 0, 1);
// Usually 0, but on (85, 95) and (-95, 85) becomes 1 and -1.
int gimbalPole = mRotation.getGimbalPole();
// Using roll (pitch/yaw for other axis) if it's defined, and using angle with gimble pole otherwise.
float rotation = (gimbalPole == 0) ? roll : angle * gimbalPole;
获得的旋转将在(-180,180)范围内。它可以很容易地转换为[0, 360)范围:
if (rotation < 0) rotation += 360;
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 与互斥锁相比,旋转锁可以保证上下文切换
- 在cuda线程之间共享大量常量数据
- 在c代码之间共享数据的最佳方式
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 大小相等但成员数量不同的结构之间的性能差异
- 旋转块时如何修复块之间的间距
- 如何找到两个不同坐标系中对应点之间的旋转和平移(变换矩阵)
- 两组向量之间的四元旋转
- 如何在子弹物理学中让刚体的欧拉旋转在 0 到 360 之间
- 如何使用OpenCV计算两帧之间的旋转平移矩阵
- 帧之间的 OpenCV 平移/旋转位移
- 是否有可能得到两个图像之间的旋转和缩放只有一个冲浪描述符
- OpenCV SURF -获得两个图像之间的旋转角度
- 求两个全等三角形之间的旋转
- 四个旋转顶点之间的命中测试