【问题标题】:OpenGL gluLookAtOpenGL gluLookAt
【发布时间】:2019-09-25 00:03:03
【问题描述】:

我尝试绘制一个茶壶并以 3D 形式查看它,但是当我运行程序时,什么都没有出现。窗户里什么都没有。我知道这与我的 gluLookAt() 函数有关,但我不确定如何修复它。

// helloteapot.cc

//#include <GLUT/gl.h>
#include <GLUT/glut.h>
#include "GL/glui.h"

void display () {

/* clear window */
glClear(GL_COLOR_BUFFER_BIT);

/* draw scene */
glColor3f(1.0, 0.0, 0.0);
glTranslatef(0.0, 0.5, 0.0);
glutSolidTeapot(0.15);

/* flush drawing routines to the window */
glFlush();

}

int main ( int argc, char * argv[] ) {
glutInit(&argc,argv);

/* setup the size, position, and display mode for new windows */
glutInitWindowSize(800,600);
glutInitWindowPosition(0,0);
glutInitDisplayMode(GLUT_RGB);

/* create and set up a window */
glutCreateWindow("hello, teapot!");

glutDisplayFunc(display);

/*GLfloat width = 800;
GLfloat height = 600;
GLfloat aspect = (GLfloat)width / (GLfloat)height;

// Set the viewport to cover the new window
glViewport(0, 0, width, height);*/

// Set the aspect ratio of the clipping volume to match the 
viewport
glMatrixMode(GL_PROJECTION);  // To operate on the Projection 
matrix
glLoadIdentity();             // Reset
// Enable perspective projection with fovy, aspect, zNear and zFar
//luPerspective(45.0f, aspect, -100.0f, 100.0f);
gluLookAt(0, 0, 0, 0, 0.5, 0, 0, -1, 0);

/* tell GLUT to wait for events */
glutMainLoop();
}

【问题讨论】:

    标签: c++ opengl glut opengl-compat


    【解决方案1】:

    您已要求 GL 将相机定位在原点,将相机向上对准点 (0, 0.5, 0),并且还(错误地)将向上矢量指定为 0、-1、0。问题是相机的前进方向是 (0, 1, 0) [由您的眼睛和瞄准位置指定],并且该方向与向上矢量或 (0, -1, 0) 冲突。尝试使用与正向成直角的向量! (例如 [1, 0, 0], [0, 0, 1])

    gluLookAt(
      0, 0, 0,   //< camera location
      0, 0.5, 0, //< looking towards point
      1, 0, 0);  //< which direction is up?
    

    【讨论】:

      猜你喜欢
      • 2021-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多