【发布时间】:2017-06-06 08:09:33
【问题描述】:
我的问题是 OpenGL 总是围绕 (0,0,0) 旋转。但如果我翻译
“相机”,例如,如果我向后移动,它也会围绕 (0,0,0) 旋转。但是我需要围绕相机旋转,所以我必须将这些点平移回 (0,0,0),旋转并将它们平移到它们的旧位置。
但是这里出现错误:旋转后,平移是相对于旋转的。
那么,我该如何翻译回来呢?
PS:我不想使用 gluLookAt()
所以我相对于相机旋转的代码是:
//set rotation to zero
glRotatef(-yr,0.0f,1.0f,0.0f);
glRotatef(-xr,1.0f,0.0f,0.0f);
//set points relative to camera
glTranslatef(-cam_pos[0],-cam_pos[1],-cam_pos[2]);
//reset rotation
glRotatef(yr,0.0f,1.0f,0.0f);
glRotatef(xr,1.0f,0.0f,0.0f);
//rotate
glRotatef(angley,0.0f,1.0f,0.0f);
glRotatef(anglex,1.0f,0.0f,0.0f);
//and now, how to translate back,
//movement is relative to the cam ?
//I would simply use :
//glTranslatef(cam_pos[0],cam_pos[1],cam_pos[2]);
//which wont work because its relative to the new rotation.
【问题讨论】:
-
你能分享你的代码来“翻译”相机吗?
-
可以,但没关系。
-
请提供MCVE 并尝试更明确地说明您的问题,这个问题对我来说很不清楚
-
我会再问这个问题,因为几乎没有 [on hold] 问题回来。