資源簡介
在visual c++ 6.0 下,利用opengl畫了一個交互式的3D 模型,可以利用方向鍵實現交互功能,讓讀者能夠全方位的看到3D模型

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
void?init()
{
glClearColor(0.00.00.00.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
}
static?GLfloat?view_rotx?=?10.0?view_roty?=?20.0?view_rotz?=?0.0;
void?display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glRotatef(view_rotx?1.0?0.0?0.0);
glRotatef(view_roty?0.0?1.0?0.0);
glRotatef(view_rotz?0.0?0.0?1.0);
//glPushMatrix();
//glColor3f(0.50.50.5);
//auxSolidBox(100.110);
//glPopMatrix();
glPushMatrix();
glColor3f(1.00.01.0);
glTranslatef(2.50-2.5);
auxSolidBox(353);
glPopMatrix();
glPushMatrix();
glColor3f(1.00.00.0);
glTranslatef(2.502.5);
auxSolidBox(353);
glPopMatrix();
glPushMatrix();
glColor3f(0.01.00.0);
glTranslatef(-2.502.5);
auxSolidBox(3103);
glPopMatrix();
glPushMatrix();
glColor3f(0.00.01.0);
glTranslatef(-2.50-2.5);
auxSolidBox(3103);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void?reshape(int?wint?h)
{
glViewport(00wh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0w/h1.020.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.00.05.00.00.00.00.01.00.0);
}
void?keyboard(unsigned?char?keyint?xint?y)
{
switch(key){
case?27:
exit(1);
}
}
void?mySpecial(int?keyint?xint?y)
{
switch?(key)?
{
case?GLUT_KEY_UP:
view_rotx?+=?5.0;
break;
case?GLUT_KEY_DOWN:
view_rotx?-=?5.0;
break;
case?GLUT_KEY_LEFT:
view_roty?+=?5.0;
break;
case?GLUT_KEY_RIGHT:
view_roty?-=?5.0;
break;
default:
return;
}
glutPostRedisplay();
}
int?main(?int?argc?char**?argv?)
{
glutInit(&argcargv);
????glutInitDisplayMode(GLUT_DOUBLE?|?GLUT_RGB?|?GLUT_DEPTH?);
????glutInitWindowPosition(?0?0?);
????glutInitWindowSize(?720?360?);
????glutCreateWindow(?“3D?map“?);
????init();
glutKeyboardFunc(?keyboard?);
glutSpecialFunc(mySpecial);
????glutReshapeFunc(?reshape?);
????glutDisplayFunc(?display?);
glutMainLoop(??);
????return(0);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2202??2011-04-21?11:53??3Dmap\3Dmap.cpp
?????文件???????4344??2011-04-21?12:04??3Dmap\3Dmap.dsp
?????文件????????518??2011-04-21?10:13??3Dmap\3Dmap.dsw
?????文件??????41984??2011-04-25?09:43??3Dmap\3Dmap.ncb
?????文件??????48640??2011-04-25?09:43??3Dmap\3Dmap.opt
?????文件????????920??2011-04-25?09:36??3Dmap\3Dmap.plg
?????文件?????237623??2011-04-25?09:36??3Dmap\Debug\3Dmap.exe
?????文件?????343756??2011-04-25?09:36??3Dmap\Debug\3Dmap.ilk
?????文件??????18387??2011-04-25?09:36??3Dmap\Debug\3Dmap.obj
?????文件????3701356??2011-04-25?09:36??3Dmap\Debug\3Dmap.pch
?????文件?????631808??2011-04-25?09:36??3Dmap\Debug\3Dmap.pdb
?????文件?????148480??2011-04-25?09:36??3Dmap\Debug\vc60.idb
?????文件??????77824??2011-04-25?09:36??3Dmap\Debug\vc60.pdb
?????目錄??????????0??2011-04-25?09:36??3Dmap\Debug
?????目錄??????????0??2011-04-25?09:43??3Dmap
-----------?---------??----------?-----??----
??????????????5257842????????????????????15
評論
共有 條評論