資源簡介
交互式計算機圖形學--基于openGL的自頂向下方法,包含6個cpp文件,其中涉及到彩色立方體,以及立方體的旋轉、點光源下的陰影顯示、鼠標鍵盤的交互,可改變視景深度。
代碼片段和文件信息
/*?rotating?cube?with?color?interpolation?*/
/*?demonstration?of?use?of?homogeneous-coordinate?transformations
and?simple?data?structure?for?representing?cube?from?Chapter?4?*/
/*?colors?are?assigned?to?the?vertices?*/
/*?cube?is?centered?at?origin?*/
#include?
#include?
GLfloat?vertices[]?={-1.0-1.0-1.01.0-1.0-1.0
1.01.0-1.0?-1.01.0-1.0?-1.0-1.01.0?1.0-1.01.0
1.01.01.0?-1.01.01.0};
GLfloat?colors[]?=?{0.00.00.01.00.00.0?1.01.00.0
0.01.00.0?0.00.01.0?1.00.01.0?1.01.01.0?0.01.01.0};
GLubyte?cubeIndices[]={032123760473126545670154};
static?GLfloat?theta[]?=?{0.00.00.0};
static?GLint?axis?=?2;
void?display()
{
/*?display?callback?clear?frame?buffer?and?z?buffer
???rotate?cube?and?draw?swap?buffers?*/
?glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
?glLoadIdentity();
?glRotatef(theta[0]?1.0?0.0?0.0);
?glRotatef(theta[1]?0.0?1.0?0.0);
?glRotatef(theta[2]?0.0?0.0?1.0);
?glDrawElements(GL_QUADS?24?GL_UNSIGNED_BYTE?cubeIndices);
?glBegin(GL_LINES);
???glVertex3f(0.00.00.0);
???glVertex3f(1.01.01.0);
?glEnd();
?glFlush();
?glutSwapBuffers();
}
void?spinCube()
{
/*?idle?callback?spin?cube?2?degrees?about?selected?axis?*/
?theta[axis]?+=?2.0;
?if(?theta[axis]?>?360.0?)?theta[axis]?-=?360.0;
?glutPostRedisplay();
}
void?mouse(int?btn?int?state?int?x?int?y)
{
/*?mouse?callback?selects?an?axis?about?which?to?rotate?*/
?if(btn==GLUT_LEFT_BUTTON?&&?state?==?GLUT_DOWN)?axis?=?0;
?if(btn==GLUT_MIDDLE_BUTTON?&&?state?==?GLUT_DOWN)?axis?=?1;
?if(btn==GLUT_RIGHT_BUTTON?&&?state?==?GLUT_DOWN)?axis?=?2;
}
void?myReshape(int?w?int?h)
{
????glViewport(0?0?w?h);
????glMatrixMode(GL_PROJECTION);
????glLoadIdentity();
????if?(w?<=?h)
????????glOrtho(-2.0?2.0?-2.0?*?(GLfloat)?h?/?(GLfloat)?w
????????????2.0?*?(GLfloat)?h?/?(GLfloat)?w?-10.0?10.0);
????else
????????glOrtho(-2.0?*?(GLfloat)?w?/?(GLfloat)?h
????????????2.0?*?(GLfloat)?w?/?(GLfloat)?h?-2.0?2.0?-10.0?10.0);
????glMatrixMode(GL_MODELVIEW);
}
int?main(int?argc?char?**argv)
{
/*?need?both?double?buffering?and?z?buffer?*/
???glutInit(&argc?argv);
???glutInitDisplayMode(GLUT_DOUBLE?|?GLUT_RGB?|?GLUT_DEPTH);
???glutInitWindowSize(500?500);
???glutCreateWindow(“colorcube“);
???glutReshapeFunc(myReshape);
???glutDisplayFunc(display);
???glutIdleFunc(spinCube);
???glutMouseFunc(mouse);
???glEnable(GL_DEPTH_TEST);?/*?Enable?hidden--surface--removal?*/
???glEnableClientState(GL_COLOR_ARRAY);
???glEnableClientState(GL_NORMAL_ARRAY);
???glEnableClientState(GL_VERTEX_ARRAY);
???glVertexPointer(3?GL_FLOAT?0?vertices);
???glColorPointer(3GL_FLOAT?0?colors);
???glColor3f(1.01.01.0);
???glutMainLoop();
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2835??2008-10-23?10:34??計算機圖形學代碼\code\cubev.c
?????文件???????3198??2002-04-06?11:06??計算機圖形學代碼\code\cubevs.c
?????文件???????3116??2005-04-26?20:37??計算機圖形學代碼\code\cube_view.c
?????文件???????1869??2008-10-09?11:02??計算機圖形學代碼\code\simple.c
?????文件???????2494??2005-04-25?07:22??計算機圖形學代碼\code\single_double.c
?????文件???????2491??2008-10-09?10:54??計算機圖形學代碼\code\square.c
?????目錄??????????0??2008-12-12?20:42??計算機圖形學代碼\code
?????目錄??????????0??2008-11-17?12:04??計算機圖形學代碼
-----------?---------??----------?-----??----
????????????????16003????????????????????8
- 上一篇:H.264編碼器流程圖
- 下一篇:Todolist(最佳中文版時間管理工具)
評論
共有 條評論