OpenGL gluLookAt - PullRequest
       17

OpenGL gluLookAt

0 голосов
/ 25 сентября 2019

Я пытался нарисовать чайник и просмотреть его в 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();
}

1 Ответ

0 голосов
/ 25 сентября 2019

Вы попросили 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?
...