我的计划:
1. 计算鼠标方向 [x, y] [成功]
在我的鼠标移动事件中:
int directionX = lastPosition.x - position.x;
int directionY = lastPosition.y - position.y;
2. 计算角度 [theta, phi] [成功]
float theta = fmod(lastTheta + sensibility * directionY, M_PI);
float phi = fmod(lastPhi + sensibility * directionX * -1, M_PI * 2);
编辑 {
错误修复:
float theta = lastTheta + sensibility * directionY * -1;
if (theta < M_PI / -2)theta = M_PI / -2;
else if (theta > M_PI / 2)theta = M_PI / 2;
float phi = fmod(lastPhi + sensibility * directionX * -1, M_PI * 2);
现在我已经有了theta、phi、中心点和半径,我想要计算相机看向中心点时的位置和旋转。
3. 计算位置坐标[X,Y,Z] [失败]
float newX = radius * sin(phi) * cos(theta);
float newY = radius * sin(phi) * sin(theta);
float newZ = radius * cos(phi);
解决方案 [由meowgoesthedog提供]:
float newX = radius * cos(theta) * cos(phi);
float newY = radius * sin(theta);
float newZ = radius * cos(theta) * sin(phi);
4. 计算旋转 [失败]
float pitch = ?;
float yaw = ?;
解决方案[由meowgoesthedog提供]:
float pitch = -theta;
float yaw = -phi;
感谢您的解决方案!