OpenGL的旋转摄像头点周围 [英] OpenGL rotating a camera around a point

查看:803
本文介绍了OpenGL的旋转摄像头点周围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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)

这篇关于OpenGL的旋转摄像头点周围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆