OpenGL旋转相机
OpenGL rotation of the camera
我有一个立方体,当然有6条边。现在我不想在其中一些边看不见的时候渲染所有边。所以我把相机的旋转传递给下面的绘制函数:
void Voxel::draw(QGLWidget *parent, GLfloat rotationX, GLfloat rotationY, GLfloat rotationZ) {
glBegin(GL_QUADS);
parent->qglColor(color);
if ((rotationY > -90 && rotationY < 90) | rotationY < -270) {
// Side top
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glVertex3f( 1.0f, 1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glVertex3f(-1.0f, 1.0f, -1.0f); // Bottom Left Of The Texture and Quad
}
// Side bottom
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glVertex3f( 1.0f, -1.0f, 1.0f); // Top Right Of The Texture and Quad
glVertex3f(-1.0f, -1.0f, 1.0f); // Top Left Of The Texture and Quad
// Side 1
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad
// Side 2
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad
glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad
// Side 3
glVertex3f(1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glVertex3f(1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glVertex3f(1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glVertex3f(1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
// Side 4
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad
glEnd();
}
然而,出于某种原因,这并不能完全奏效。尤其是在绕X轴旋转时。在某些旋转点上,它不显示四边形,而应该显示四边形。
我这样设置旋转:
glRotatef(rotationX, 1.0, 0.0, 0.0);
glRotatef(rotationY, 0.0, 1.0, 0.0);
如果我需要解释更多,请询问。如果你知道一些关于这些事情的好文档,请这样说。
这可能不是你所期望的答案,但通常OpenGL硬件非常擅长不显示不面向相机的面,这被称为背面剔除。现代桌面硬件每秒可以丢弃大约40亿个三角形。所以这个优化可能不是一个,也可能不值得你花时间在它上
更重要的是,假设您使用的是透视投影,关于立方体相对于"相机"的位置,您关于立方体面的可见性与其旋转相关的假设可能不正确。
我认为行中的代码中有一个愚蠢的错误
if ((rotationY > -90 && rotationY < 90) | rotationY < -270) {
您应该使用||来代替|
相关文章:
- 将"Compass"与相机旋转隔离开GL
- 如何围绕对象旋转相机?
- 如何使用gluLookAt围绕OpenGL中的点旋转相机视图
- 如何校准相机焦距,平移和旋转给定四个点
- 从iPhone相机拍摄的视频似乎被OpenCV旋转了90度?我该如何解决这个问题?
- 相机的旋转方向在一段时间后反转
- 将网格与VTK相机对齐(相机的视觉表示,随之移动和旋转的网格)
- 直接相机旋转的错误控制
- 如何使OpenGL相机旋转360度
- C++OpenGl相机旋转使用四元数问题
- 尝试保持光标居中时,相机旋转会受损
- OpenGL第一人称相机旋转和平移
- 在openGL或更具体的LWJGL中,一个人如何相对于相机旋转
- 使用lookAt进行相机旋转
- 变换四元数相机旋转矩阵- OpenCV
- 使用相机旋转使四边形始终显示在相机前面(c++/opengl)
- OpenGL 相机旋转不起作用
- 如何累积相机旋转
- GLM相机X,Y旋转引入Z旋转的问题
- openGL光照随相机旋转