OpenGL的旋转摄像头点周围摄像头、OpenGL

由网友(不打扰你的幸福)分享简介:在OpenGL我试图旋转摄像头点周围,带摄像头是距离r由点及所面临的问题,当它旋转。换句话说,我希望相机沿着圆在距中心的半径r的圆周移动,与面对中心在沿圆周方向的任意点摄像机In OpenGL I'm trying to rotate a camera around a point, with camera bein...

在OpenGL我试图旋转摄像头点周围,带摄像头是距离r由点及所面临的问题,当它旋转。换句话说,我希望相机沿着圆在距中心的半径r的圆周移动,与面对中心在沿圆周方向的任意点摄像机

In OpenGL I'm trying to rotate a camera around a point, with camera being distance r from the point and facing the point when it rotates. In other words, I want the camera to move along the circumference of a circle at a radius r from the center, with the camera facing the center at any point along the circumference.

让我们说,在三维空间中圆心为(3,0,3);

Lets say that in 3d space the center of the circle is (3, 0, 3);

我已经试过:

// move to center of circle    
glTranslatef(-3, 0, -3)
// move a distance away from the circle
glTranslatef(0, 0, r);
// rotate along the y "up" axis
glRotatef(CameraAngle, 0, 1, 0);

在这里CameraAngle是度移动绕了一圈。

where CameraAngle is the degrees being moved around the circle.

我的最终结果是相机仍沿原点,而不是圆的中心旋转。谁能帮我解决这个问题?谢谢!

My end result is the camera is still rotating along the origin, not the center of the circle. Can anyone help me fix this problem? Thanks!

推荐答案

您需要:

绕原点的相机,然后把它翻译(*)

使用 gluLookAt 保持相机指向的圆心 use gluLookAt to keep the camera pointing at the center of the circle

(*)旋转功能正常绕原点旋转。要绕另一点 P ,你必须:

(*) rotation functions normally rotate about the origin. To rotate around another point P you have to:

翻译(-P) 旋转 翻译(P)
阅读全文

相关推荐

最新文章