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 <maze005.h> 00009 #include <mazedisp03.h> 00010 #include <mazematrixD2.h> 00011 #include <mazematrixD2createmaze.h> 00012 00013 #include <zpr.h> 00014 00015 00016 string maze005::doc[] = 00017 { 00018 "", 00019 "$ ./main prog=14 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." 00020 }; 00021 00022 mazegameD2state01* maze005::mg = 0; 00023 mazegameD2solver01* maze005::ms = 0; 00024 mazedisp03* maze005::md = 0; 00025 bool* maze005::help = 0; 00026 menusystem* maze005::messages = 0; 00027 00028 // http://www.codeproject.com/KB/openGL/GLUT_WINDOW_TEMPLATE.aspx 00029 void maze005::special01(int key, int x, int y) 00030 { 00031 assert(mg!=0); 00032 assert(md!=0); 00033 00034 switch (key) 00035 { 00036 case GLUT_KEY_LEFT : mg->currentmove(3); break; 00037 case GLUT_KEY_RIGHT : mg->currentmove(1); break; 00038 case GLUT_KEY_UP : mg->currentmove(0); break; 00039 case GLUT_KEY_DOWN : mg->currentmove(2); break; 00040 } 00041 00042 glutPostRedisplay(); 00043 } 00044 00045 void maze005::keyboard01 00046 ( 00047 unsigned char key, 00048 int x, 00049 int y 00050 ) 00051 { 00052 assertreturn(mg!=0); 00053 assertreturn(md!=0); 00054 assertreturn(ms!=0); 00055 assertreturn(messages); 00056 00057 switch (key) 00058 { 00059 case 'q': exit(0); break; 00060 00061 case 's': 00062 if (!(*ms)) ++(*ms); 00063 break; 00064 case 'S': 00065 for ( ; !(*ms); ++(*ms) ); 00066 break; 00067 case 'h': 00068 *help = !(*help); break; 00069 00070 case '1': 00071 messages->addfont10paragraphs((stringc)(*mg),50); break; 00072 case '2': messages->scrolldown(); break; 00073 case '3': messages->scrollup(); break; 00074 case '4': messages->clear(); break; 00075 00076 case 'p': md->pipes = ! md->pipes; md->gx.update(); break; 00077 case 'w': md->walls = ! md->walls; md->gx.update(); break; 00078 case 'i': md->displaycellid= ! md->displaycellid; md->gx.update(); break; 00079 00080 } 00081 00082 glutPostRedisplay(); 00083 } 00084 00085 void maze005::display01() 00086 { 00087 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00088 00089 assert(gobj::global); 00090 00091 gobj::global->draw(); 00092 00093 glerrordisplay(); 00094 00095 glutSwapBuffers(); 00096 } 00097 00098 00099 void maze005::reshape01(intc width_,intc height_) 00100 { 00101 zpr::reshape(width_,height_); 00102 assert(md); 00103 // assert(md->bp02); 00104 // md->bp02->update(); 00105 } 00106 00107 void maze005::menubuild() 00108 { 00109 menusystem * menu = 00110 new menusystem(point2<GLint>(60,30),10); 00111 menu->fontcolor = point4<float>(218.0/255.0,165.0/255.0,32.0/255.0,0.75); 00112 00113 menu->addfont12("Maze Game [prototype 02]",2); 00114 00115 menu->addfont10("[page up] move up",1); 00116 menu->addfont10("[page down] move down",1); 00117 menu->addfont10("[< home] move left",1); 00118 menu->addfont10("[end >] move right",2); 00119 00120 menu->addfont10("[s] solver 1 step",1); 00121 menu->addfont10("[S] solve maze",1); 00122 menu->addfont10("[h] Toggle the menu",2); 00123 00124 menu->addfont10("[p] Toggle pipes",1); 00125 menu->addfont10("[w] Toggle walls",1); 00126 menu->addfont10("[i] Toggle cell id",2); 00127 00128 menu->addfont10("[1] Print settings",1); 00129 menu->addfont10("[2] scroll down",1); 00130 menu->addfont10("[3] scroll up",1); 00131 menu->addfont10("[4] clear",2); 00132 00133 menu->addfont10("[q] Quit",1); 00134 00135 menu->lightingdisable(); 00136 00137 gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true); 00138 help = & menuswitch->isdrawn; 00139 gobjpush(menuswitch); 00140 00141 // The messages menu 00142 messages = 00143 new menusystem(point2<GLint>(60,250),10); 00144 gobjpush(messages); 00145 messages->fontcolor = point4<float>(1.0,0.0,0.0,0.8); 00146 messages->lightingdisable(); 00147 } 00148 00149 maze005::maze005(int argc, char** argv) 00150 : xGraphics(true) 00151 { 00152 glutInit(&argc,argv); 00153 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00154 glutInitWindowSize(800,600); 00155 glutCreateWindow(""); 00156 glutDisplayFunc(maze005::display01); 00157 glutKeyboardFunc(maze005::keyboard01); 00158 glutSpecialFunc(maze005::special01); 00159 00160 00161 OpenGLinitialisation(); 00162 00163 glEnable(GL_DEPTH_TEST); 00164 glEnable(GL_CULL_FACE); 00165 glEnable(GL_NORMALIZE); 00166 00167 xGraphics.set(); 00168 00169 commandline cmd(argc,argv); 00170 00171 // Construct the maze. 00172 00173 mg = new mazegameD2state01(); 00174 00175 cmd.mapvar(mg->m,"m"); 00176 cmd.mapvar(mg->n,"n"); 00177 cmd.mapvar(mg->randomize,"randomize"); 00178 00179 cmd.mapvar(mg->proper,"proper"); 00180 cmd.mapvar(mg->deletewall,"deletewall"); 00181 00182 mg->game01(); 00183 assert(mg->valid()); 00184 00185 md = new mazedisp03(*mg); 00186 md->game01default(); 00187 00188 cmd.mapvar(md->dx,"dx"); 00189 00190 cmd.mapvar(md->displaycellid,"id"); 00191 00192 cmd.mapvar(md->pipes,"pipes"); 00193 graphmisc::colornormalize(md->pipecolor,cmd,"pipecolor"); 00194 00195 cmd.mapvar(md->walls,"walls"); 00196 graphmisc::colornormalize(md->wallcolor,cmd,"wallcolor"); 00197 00198 string originstr("(0,0)"); 00199 cmd.mapvar(originstr,"origin"); 00200 md->origin.serializeInverseBrackets(originstr); 00201 00202 graphmisc::colornormalize(md->backgroundcolor,cmd,"backgroundcolor"); 00203 00204 cmd.mapvar(md->endpointratio,"endpointratio"); 00205 graphmisc::colornormalize(md->endpointcolor,cmd,"endpointcolor"); 00206 00207 graphmisc::colornormalize(md->currentposcolor,cmd,"currentposcolor"); 00208 00209 cout << mg->settings() << md->settings() << endl; 00210 00211 ms = new mazegameD2solver01(*mg); 00212 00213 } 00214 00215 00216 void maze005::eval() 00217 { 00218 assert(md); 00219 assert(ms); 00220 00221 gobjpush(new gobjglTranslated(md->origin.x,md->origin.y,0.0)); 00222 00223 gobjpush(new gobjglClearColor(md->backgroundcolor)); 00224 gobjpush(new gobjglClear(GL_COLOR_BUFFER_BIT)); 00225 00226 zpr zz; 00227 // Because zpr overides reshape function in constructor. 00228 glutReshapeFunc(maze005::reshape01); 00229 00230 assert(md); 00231 zz.mousecallback = & md->mousecallback; 00232 md->zm = new zprmouse(zz); 00233 00234 md->construct(); 00235 gobjpush(md); 00236 00237 ms->reset(); 00238 00239 menubuild(); 00240 00241 zz.update(); 00242 glutMainLoop(); 00243 } 00244
1.5.8