Files Classes Functions Hierarchy
00001 #include <iostream> 00002 using namespace std; 00003 00004 00005 #include <commandline.h> 00006 #include <gobj.h> 00007 #include <graphmisc.h> 00008 #include <maze004.h> 00009 #include <mazedisp03.h> 00010 #include <mazematrixD2.h> 00011 #include <mazematrixD2createmaze.h> 00012 #include <zpr.h> 00013 00014 00015 string maze004::doc[] = 00016 { 00017 "", 00018 "$ ./main prog=13 m=10 n=20 dx=0.15 backgroundcolor=0,255,0 wallcolor=0,25,255 randozize=0 id=1 origin=-1.4,-.5,0 - Display m by n maze." 00019 }; 00020 00021 mazegameD2state01* maze004::mg = 0; 00022 mazedisp03* maze004::md = 0; 00023 00024 // http://www.codeproject.com/KB/openGL/GLUT_WINDOW_TEMPLATE.aspx 00025 void maze004::special01(int key, int x, int y) 00026 { 00027 assert(mg!=0); 00028 assert(md!=0); 00029 00030 switch (key) 00031 { 00032 case GLUT_KEY_LEFT : mg->currentmove(3); break; 00033 case GLUT_KEY_RIGHT : mg->currentmove(1); break; 00034 case GLUT_KEY_UP : mg->currentmove(0); break; 00035 case GLUT_KEY_DOWN : mg->currentmove(2); break; 00036 } 00037 00038 glutPostRedisplay(); 00039 } 00040 00041 void maze004::keyboard01 00042 ( 00043 unsigned char key, 00044 int x, 00045 int y 00046 ) 00047 { 00048 assert(mg!=0); 00049 assert(md!=0); 00050 00051 // bool res; 00052 // uint k2; 00053 00054 switch (key) 00055 { 00056 case 27: exit(0); break; 00057 00058 // case 's': mg->currentmove(3); break; 00059 // case 'd': mg->currentmove(1); break; 00060 // case 'e': mg->currentmove(0); break; 00061 // case 'x': mg->currentmove(2); break; 00062 00063 } 00064 00065 glutPostRedisplay(); 00066 } 00067 00068 void maze004::display01() 00069 { 00070 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00071 00072 assert(gobj::global); 00073 00074 gobj::global->draw(); 00075 00076 glerrordisplay(); 00077 00078 glutSwapBuffers(); 00079 } 00080 00081 00082 void maze004::reshape01(intc width_,intc height_) 00083 { 00084 zpr::reshape(width_,height_); 00085 assert(md); 00086 assert(md->bp02); 00087 md->bp02->update(); 00088 } 00089 00090 maze004::maze004(int argc, char** argv) 00091 : xGraphics(true) 00092 { 00093 glutInit(&argc,argv); 00094 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00095 glutInitWindowSize(800,600); 00096 glutCreateWindow(""); 00097 glutDisplayFunc(maze004::display01); 00098 glutKeyboardFunc(maze004::keyboard01); 00099 glutSpecialFunc(maze004::special01); 00100 00101 00102 OpenGLinitialisation(); 00103 00104 glEnable(GL_DEPTH_TEST); 00105 glEnable(GL_CULL_FACE); 00106 glEnable(GL_NORMALIZE); 00107 00108 xGraphics.set(); 00109 00110 00111 commandline cmd(argc,argv); 00112 00113 00114 //gobjpush(new myaxes(1.0)); 00115 00116 // Construct the maze. 00117 00118 mg = new mazegameD2state01(); 00119 00120 cmd.mapvar(mg->m,"m"); 00121 cmd.mapvar(mg->n,"n"); 00122 cmd.mapvar(mg->randomize,"randomize"); 00123 00124 cmd.mapvar(mg->proper,"proper"); 00125 cmd.mapvar(mg->deletewall,"deletewall"); 00126 00127 mg->game01(); 00128 assert(mg->valid()); 00129 00130 md = new mazedisp03(*mg); 00131 md->game01default(); 00132 00133 cmd.mapvar(md->dx,"dx"); 00134 00135 cmd.mapvar(md->displaycellid,"id"); 00136 00137 cmd.mapvar(md->pipes,"pipes"); 00138 graphmisc::colornormalize(md->pipecolor,cmd,"pipecolor"); 00139 00140 cmd.mapvar(md->walls,"walls"); 00141 graphmisc::colornormalize(md->wallcolor,cmd,"wallcolor"); 00142 00143 string originstr("(0,0)"); 00144 cmd.mapvar(originstr,"origin"); 00145 md->origin.serializeInverseBrackets(originstr); 00146 00147 graphmisc::colornormalize(md->backgroundcolor,cmd,"backgroundcolor"); 00148 00149 cmd.mapvar(md->endpointratio,"endpointratio"); 00150 graphmisc::colornormalize(md->endpointcolor,cmd,"endpointcolor"); 00151 00152 graphmisc::colornormalize(md->currentposcolor,cmd,"currentposcolor"); 00153 00154 cout << mg->settings() << md->settings() << endl; 00155 00156 00157 00158 00159 } 00160 00161 00162 void maze004::eval() 00163 { 00164 gobjpush(new gobjglTranslated(md->origin.x,md->origin.y,0.0)); 00165 00166 gobjpush(new gobjglClearColor(md->backgroundcolor)); 00167 gobjpush(new gobjglClear(GL_COLOR_BUFFER_BIT)); 00168 00169 00170 zpr zz; 00171 // Because zpr overides reshape function in constructor. 00172 glutReshapeFunc(maze004::reshape01); 00173 00174 assert(md); 00175 zz.mousecallback = & md->mousecallback; 00176 md->zm = new zprmouse(zz); 00177 00178 md->construct(); 00179 gobjpush(md); 00180 00181 zz.update(); 00182 glutMainLoop(); 00183 } 00184
1.5.8