首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenGL gluLookAt

OpenGL gluLookAt
EN

Stack Overflow用户
提问于 2019-09-25 08:03:04
回答 1查看 142关注 0票数 0

我试着画一个茶壶,并在3D中查看它,但当我运行程序时,什么也没有显示出来。窗子里什么也没有。我知道这与我的gluLookAt()函数有关,但我不确定如何修复它。

代码语言:javascript
复制
// 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();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-25 08:16:56

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

代码语言:javascript
复制
gluLookAt(
  0, 0, 0,   //< camera location
  0, 0.5, 0, //< looking towards point
  1, 0, 0);  //< which direction is up?
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58089507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档