我试图查看3D圆锥体,为此我使用了gluLookAt。我在屏幕的中间位置pos(250,250,0)处绘制一个圆锥体,然后用原点上方的摄像头对其进行查看。输出是一个圆,与我预期看到的圆锥相反。似乎相机也位于(250,250,0)点,但是它在gluLookAt中指定,它应该在原点上方。我在这里俯瞰什么?
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(250, 250, 0);
glutSolidCone(30, 10, 20, 20);
glTranslatef(-250, -250, 0);
gluLookAt(0, 0, 100, 250, 250, 0, 0, 0, 1);
glFlush();
glutSwapBuffers();
}
int main(int argc, char **argv)
{
float x, y;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Cone");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMotionFunc(drag);
glutMouseFunc(click);
glutSpecialFunc(catchKey);
glEnable(GL_DEPTH_TEST);
glutMainLoop(); //calls do_one_simulation_step, keyboard, display, drag, reshape
return 0;
}
答案 0 :(得分:2)
一些问题:
gluLookAt()
的方式没有任何用处。gluPerspective()
或glFrustum()
设置真实的透视变换。gluLookAt()
的眼睛/中心坐标有点呆滞;我将视线移到(50、50、50)并设置为观察原点。一起:
#include <GL/glut.h>
#include <GL/GLU.h>
void display( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
double w = glutGet( GLUT_WINDOW_WIDTH );
double h = glutGet( GLUT_WINDOW_HEIGHT );
gluPerspective( 60.0, w / h, 1.0, 1000.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 50, 50, 50, 0, 0, 0, 0, 0, 1 );
glutWireCone( 10, 30, 20, 20 );
glutSwapBuffers();
}
int main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize( 500, 500 );
glutCreateWindow( "Cone" );
glutDisplayFunc( display );
glEnable( GL_DEPTH_TEST );
glutMainLoop();
return 0;
}