gpt4 book ai didi

c++ - OpenGL 旋转的问题

转载 作者:太空宇宙 更新时间:2023-11-03 10:31:16 24 4
gpt4 key购买 nike

在我的 OpenGL 应用程序中,我有一个使用键盘(移动)和鼠标(环顾四周)控制的相机。

到目前为止,一切都运行良好,我注意到如果我将相机在 Y 轴上移动到 300 以上,移动鼠标时它就会开始困惑。例如,如果我转到 Y =310,然后向上移动鼠标,当它开始向上看时,它也开始向左转。

我不确定这是什么原因。谁能帮忙?

这是计算 gluLookAt() 的向前和向上位置的代码

双 cosR、cosP、cosY;//sin/cos 的温度值来自 双 sinR, sinP, sinY;//输入的roll/pitch/yaw

if(Yaw > 359) Yaw = 0;
if(Pitch > 359) Pitch = 0;
if(Yaw < 0) Yaw = 359;
if(Pitch < 0) Pitch = 359;


cosY = cosf(Yaw*3.1415/180);
cosP = cosf(Pitch*3.1415/180);
cosR = cosf(Roll*3.1415/180);
sinY = sinf(Yaw*3.1415/180);
sinP = sinf(Pitch*3.1415/180);
sinR = sinf(Roll*3.1415/180);

//forward position
forwardPos.x = sinY * cosP*360;
forwardPos.y = sinP * 360;
forwardPos.z = cosP * -cosY*360;

//up position
upPos.x = -cosY * sinR - sinY * sinP * cosR;
upPos.y = cosP * cosR;
upPos.z = -sinY * sinR - sinP * cosR * -cosY;

最佳答案

万向锁。 It is explained here.

四元数是这个问题的标准解。

简而言之,在上述计算中,当两个轴角相互接近时,会导致可用运动损失。您需要第 4 个自由度来防止这种情况 - 这就是四元数数学所允许的。

关于c++ - OpenGL 旋转的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15960172/

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