场景绘制中的视点移动

来源:互联网 发布:吴宇森 李安 知乎 编辑:程序博客网 时间:2024/05/16 12:49

glutKeyboardFunc(keyboard); //定义键盘行为

 

void keyboard(unsigned char a, int x, int y)

{

   switch( a )

   {

       case 'w':

          viewpoint[0] -= 100.0;

          glutPostRedisplay();

   

}

 

//reshape 函数

void reshape(int w, int h)

 glViewport(0,0,w,h);

 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 

 gluPerspective(angle,ratio,nearP,farP);
 frustum.setCamInternals(angle,ratio,nearP,farP);

 glMatrixMode(GL_MODELVIEW);

}

 

//render

void render()

{

Vec3f l = Vec3f(viewPoint.x, viewPoint.y, viewPoint.z -1.0);
Vec3f u = Vec3f(0.0, 1.0, 0.0);
 
glLoadIdentity();
 
gluLookAt( viewPoint.x, viewPoint.y, viewPoint.z, l.x, l.y, l.z,u.x, u.y, u.z );
 
frustum.setCamDef(viewPoint,l,u);

 

glutSwapBuffers();

}

原创粉丝点击