Files Classes Functions Hierarchy
Iterate over mazematrixD2 as a matrix drawing each cell. More...
#include <mazedisp03.h>


Public Member Functions | |
| mazedisp03 (mazegameD2state01 &mg_) | |
| Default maze draw. | |
| ~mazedisp03 () | |
| Cleanup. | |
| void | draw () |
| Draws to the global graphics stream. | |
| void | construct () |
| Build the static geometry and add dynamic geometry. | |
| void | staticgraphics () |
| Geometry which does not change. | |
| void | mouseevent () |
| Processes mouse event. | |
| void | celldraw (cellD2< uint > const &x, point2< double > const &p) |
| Draw cell. | |
| void | celldraw2 (cellD2< uint > const &x, point2< double > const &p) |
| Draw cell with path istead of walls. | |
| void | game01default () |
| Default settings for game01. | |
| stringc | settings () const |
| This class's command line settings. | |
| point2< double > const | cellmidpoint (uintc id) const |
| Get the midpoint of the cell given the cells id. | |
| void | currentposdraw () |
| void | f01 () |
Public Attributes | |
| graphicsImmediateDeferredSwitch | gx |
| Contains all the graphics. | |
| uint | staticgraphicsindex |
| Index into gx for static geometry. | |
| mazegameD2state01 & | mg |
| Maze game. | |
| double | dx |
| Square cell side length. | |
| bool | displaycellid |
| Display the cells id. | |
| bool | pipes |
| Instead of drawing the walls, draw the paths. | |
| point3< double > | pipecolor |
| Color of pipes. | |
| bool | walls |
| Display the walls. | |
| point3< double > | wallcolor |
| Color of cell walls. | |
| point2< double > | origin |
| Initial translation of maze. | |
| point3< double > | backgroundcolor |
| Background color. | |
| double | endpointratio |
| Size of start and finish spheres. | |
| point3< double > | endpointcolor |
| Start and finish sphere color. | |
| point3< double > | currentposcolor |
| Current position and path color. | |
| fnobj0Tfn< mazedisp03, void > | mousecallback |
| Functional object calling mouse(zpr&). | |
| zprmouse * | zm |
| buttonpanel02 * | bp02 |
| Movement buttons. | |
Iterate over mazematrixD2 as a matrix drawing each cell.
Interprets mazematrixD2 as a m by n matrix, iterating over each cell and drawing it.
Definition at line 21 of file mazedisp03.h.
| mazedisp03::mazedisp03 | ( | mazegameD2state01 & | mg_ | ) |
Default maze draw.
Definition at line 15 of file mazedisp03.cpp.
00016 : mg(mg_), mousecallback(*this,&mazedisp03::mouseevent), zm(0) 00017 { 00018 }
| mazedisp03::~mazedisp03 | ( | ) |
Draw cell.
Definition at line 194 of file mazedisp03.cpp.
References gobjpush, cellD2< T >::ni, point2< T >::x, and point2< T >::y.
Referenced by staticgraphics().
00198 { 00199 point2<double> p10 = p00; 00200 p10.x += dx; 00201 point2<double> p01 = p00; 00202 p01.y += dx; 00203 point2<double> p11 = p00; 00204 p11.x += dx; 00205 p11.y += dx; 00206 00207 if (x.ni[1]==0) 00208 { 00209 gobjpush(new gobjglVertex2d(p10)); 00210 gobjpush(new gobjglVertex2d(p11)); 00211 } 00212 00213 if (x.ni[3]==0) 00214 { 00215 gobjpush(new gobjglVertex2d(p01)); 00216 gobjpush(new gobjglVertex2d(p00)); 00217 } 00218 00219 if (x.ni[0]==0) 00220 { 00221 gobjpush(new gobjglVertex2d(p01)); 00222 gobjpush(new gobjglVertex2d(p11)); 00223 } 00224 00225 if (x.ni[2]==0) 00226 { 00227 gobjpush(new gobjglVertex2d(p00)); 00228 gobjpush(new gobjglVertex2d(p10)); 00229 } 00230 }
Draw cell with path istead of walls.
Definition at line 233 of file mazedisp03.cpp.
References gobjpush, cellD2< T >::ni, point2< T >::x, and point2< T >::y.
Referenced by staticgraphics().
00237 { 00238 double dx2 = dx*0.5; 00239 00240 point2<double> p3 = p00; 00241 p3.y += dx2; 00242 point2<double> p1 = p00; 00243 p1.x += dx; 00244 p1.y += dx2; 00245 point2<double> p0 = p00; 00246 p0.x += dx2; 00247 p0.y += dx; 00248 point2<double> p2 = p00; 00249 p2.x += dx2; 00250 00251 point2<double> pcenter = p00; 00252 pcenter.x += dx2; 00253 pcenter.y += dx2; 00254 00255 if (x.ni[1]!=0) 00256 { 00257 gobjpush(new gobjglVertex2d(pcenter)); 00258 gobjpush(new gobjglVertex2d(p1)); 00259 } 00260 00261 if (x.ni[3]!=0) 00262 { 00263 gobjpush(new gobjglVertex2d(pcenter)); 00264 gobjpush(new gobjglVertex2d(p3)); 00265 } 00266 00267 if (x.ni[0]!=0) 00268 { 00269 gobjpush(new gobjglVertex2d(pcenter)); 00270 gobjpush(new gobjglVertex2d(p0)); 00271 } 00272 00273 if (x.ni[2]!=0) 00274 { 00275 gobjpush(new gobjglVertex2d(pcenter)); 00276 gobjpush(new gobjglVertex2d(p2)); 00277 } 00278 }
Get the midpoint of the cell given the cells id.
Definition at line 85 of file mazedisp03.cpp.
References mazematrixD2< T >::dim, dx, mg, mazegameD2state01::mz, point2< T >::x, and point2< T >::y.
Referenced by currentposdraw(), and staticgraphics().
00086 { 00087 uint k = id-1; 00088 uint m=mg.mz.dim[0]; 00089 uint n=mg.mz.dim[1]; 00090 00091 point2<uint> pos1; 00092 point2<double> pos2; 00093 00094 pos1.x = k % n; 00095 pos1.y = (m*n-1)/n-k/n; 00096 pos2.x = dx*pos1.x; 00097 pos2.y = dx*pos1.y; 00098 00099 return pos2+point2<double>(dx*0.5,dx*0.5); 00100 }
| void mazedisp03::construct | ( | ) |
Build the static geometry and add dynamic geometry.
Definition at line 47 of file mazedisp03.cpp.
References bp02, currentposdraw(), gobjcallbackcreatenew(), gx, graphicsImmediateDeferredSwitch::pushdeferred(), graphicsImmediateDeferredSwitch::pushimmediate(), staticgraphics(), staticgraphicsindex, graphicsImmediateDeferred::update(), and zm.
Referenced by maze005::eval(), and maze004::eval().
00048 { 00049 //gx.push(staticgraphicsindex,*this,&mazedisp03::staticgraphics); 00050 gx.pushdeferred(staticgraphicsindex,*this,&mazedisp03::staticgraphics); 00051 gx.update(); 00052 00053 uint index; 00054 00055 gx.pushimmediate(index,gobjcallbackcreatenew(*this,&mazedisp03::currentposdraw)); 00056 00057 00058 // Turned off mouse button 00059 bp02 = new buttonpanel02(zm); 00060 // gx.pushimmediate(index,bp02); 00061 00062 }
| void mazedisp03::currentposdraw | ( | ) |
Definition at line 300 of file mazedisp03.cpp.
References cellmidpoint(), currentposcolor, dx, endpointratio, mg, mazegameD2state01::path, point2< T >::x, point3< T >::x, point2< T >::y, point3< T >::y, and point3< T >::z.
Referenced by construct().
00301 { 00302 assert(mg.path.empty()==false); 00303 uint cp = mg.path[mg.path.size()-1]; 00304 00305 point2<double> cpx = cellmidpoint(cp); 00306 00307 glPushAttrib(GL_CURRENT_BIT); 00308 glColor3d(currentposcolor.x,currentposcolor.y,currentposcolor.z); 00309 00310 // Assume model view 00311 glPushMatrix(); 00312 glTranslated(cpx.x,cpx.y,0.0); 00313 glutSolidSphere(dx*endpointratio,35,35); 00314 glPopMatrix(); 00315 00316 for (uint i=0; i<mg.path.size(); ++i) 00317 { 00318 point2<double> cppos = cellmidpoint(mg.path[i]); 00319 glPushMatrix(); 00320 glTranslated(cppos.x,cppos.y,0.0); 00321 glutSolidSphere(dx*endpointratio*0.5,35,35); 00322 glPopMatrix(); 00323 } 00324 00325 glPopAttrib(); 00326 00327 //f01(); 00328 }
| void mazedisp03::draw | ( | ) | [virtual] |
Draws to the global graphics stream.
Implements gobj.
Definition at line 41 of file mazedisp03.cpp.
References graphicsImmediateDeferred::draw(), and gx.
| void mazedisp03::f01 | ( | ) |
Definition at line 330 of file mazedisp03.cpp.
References zpr::height, SHOW, zpr::width, point2< T >::x, point2< T >::y, zm, and zprmouse::zz.
00331 { 00332 assert(zm); 00333 00334 // Code taken from tutorial 00335 // http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL 00336 00337 glMatrixMode(GL_PROJECTION); 00338 glPushMatrix(); 00339 glLoadIdentity(); 00340 glOrtho(0,zm->zz.width,zm->zz.height,0,0,1); 00341 glDisable(GL_DEPTH_TEST); 00342 glMatrixMode(GL_MODELVIEW); 00343 glPushMatrix(); 00344 glLoadIdentity(); 00345 glTranslatef(0.375,0.375,0); 00346 00347 int radius=5; 00348 int x1=320; 00349 int y1=240; 00350 00351 //cout << "Drawing in 2D" << endl; 00352 00353 glPushAttrib(GL_CURRENT_BIT); 00354 glPushAttrib(GL_LIGHTING_BIT); 00355 glDisable(GL_LIGHTING); 00356 glColor3f(1.0,0.0,0.0); 00357 00358 double rad=3.141592*2.0/360.0; 00359 00360 glBegin(GL_TRIANGLE_FAN); 00361 glVertex2f(x1,y1); 00362 for (double angle=0; angle<=360; angle+=2) 00363 { 00364 point2<double> x2(x1+ sin(rad*angle)*radius, y1 + cos(rad*angle)*radius); 00365 cout << SHOW(x2) << " "; 00366 glVertex2d(x2.x,x2.y); 00367 //glVertex2f(x1 + sin(rad*angle) * radius, y1 + cos(rad*angle) * radius); 00368 //glVertex2f(x1 + sin(angle)*radius, y1 + cos(angle)*radius); 00369 } 00370 glEnd(); 00371 00372 cout << endl; 00373 00374 glPopAttrib(); 00375 glPopAttrib(); 00376 00377 // Returning to previous state. 00378 glPopMatrix(); 00379 glMatrixMode(GL_PROJECTION); 00380 glPopMatrix(); 00381 glMatrixMode(GL_MODELVIEW); 00382 00383 glEnable(GL_DEPTH_TEST); 00384 }
| void mazedisp03::game01default | ( | ) |
Default settings for game01.
Definition at line 26 of file mazedisp03.cpp.
References backgroundcolor, currentposcolor, displaycellid, dx, endpointcolor, endpointratio, origin, pipecolor, pipes, wallcolor, and walls.
00027 { 00028 dx=0.1; 00029 displaycellid=false; 00030 pipes=false; 00031 pipecolor=point3<double>(1.0,0.0,0.0); 00032 walls=true; 00033 wallcolor=point3<double>(0.0,0.0,1.0); 00034 origin=point2<double>(0.0,0.0); 00035 backgroundcolor=point3<double>(0.0,0.0,0.0); 00036 endpointratio=0.25; 00037 endpointcolor=point3<double>(0.0,1.0,0.0); 00038 currentposcolor=point3<double>(0.0,1.0,205.0/255.0); 00039 }
| void mazedisp03::mouseevent | ( | ) |
Processes mouse event.
Definition at line 387 of file mazedisp03.cpp.
References zprmouse::update(), and zm.
00388 { 00389 assert(zm); 00390 if (zm==0) 00391 return; 00392 00393 zm->update(); 00394 00395 //cout << "mouse() " << zm->mouse() << " " << zm->world() << endl; 00396 00397 // Turned off button code because of bad usablity 00398 /* 00399 assert(bp02); 00400 bool res(false); 00401 uint index; 00402 bp02->process(res,index,zm->mouseint()); 00403 00404 if (res==false) 00405 return; 00406 00407 assertreturnfalse(index<4); 00408 00409 mg.currentmove(index); 00410 00411 glutPostRedisplay(); 00412 */ 00413 }
| stringc mazedisp03::settings | ( | ) | const |
This class's command line settings.
Definition at line 280 of file mazedisp03.cpp.
References backgroundcolor, currentposcolor, displaycellid, dx, endpointcolor, endpointratio, stringconvert::findandreplacefn(), origin, pipecolor, pipes, stringto(), stringconvert::tostring(), wallcolor, and walls.
00281 { 00282 string options=""; 00283 string s; 00284 00285 options += ( "dx=" + stringconvert::tostring(dx) + " "); 00286 options += ( "id=" + stringconvert::tostring(displaycellid) + " "); 00287 options += ( "pipes=" + stringconvert::tostring(pipes) + " "); 00288 options += ( "pipecolor=" + stringconvert::findandreplacefn(stringto(pipecolor*255.0)," ",",") + " "); 00289 options += ( "walls=" + stringconvert::tostring(walls) + " "); 00290 options += ( "wallcolor=" + stringconvert::findandreplacefn(stringto(wallcolor*255.0)," ",",") + " "); 00291 options += ( "origin=" + stringconvert::findandreplacefn(origin," ",",") + " "); 00292 options += ( "backgroundcolor=" + stringconvert::findandreplacefn(stringto(backgroundcolor*255.0)," ",",") + " "); 00293 options += ( "endpointratio=" + stringconvert::tostring(endpointratio) + " "); 00294 options += ( "endpointcolor=" + stringconvert::findandreplacefn(stringto(endpointcolor*255.0)," ",",") + " "); 00295 options += ( "currentposcolor=" + stringconvert::findandreplacefn(stringto(currentposcolor*255.0)," ",",") + " "); 00296 00297 return options; 00298 }
| void mazedisp03::staticgraphics | ( | ) |
Geometry which does not change.
Definition at line 102 of file mazedisp03.cpp.
References celldraw(), celldraw2(), cellmidpoint(), mazematrixD2< T >::dim, displaycellid, dx, endpointcolor, endpointratio, mazegameD2state01::gamefinish, mazegameD2state01::gamestart, gobj::global, gobjpush, mg, mazegameD2state01::mz, pipecolor, pipes, mazematrixD2< T >::valid(), mazematrixD2< T >::vi, wallcolor, walls, point2< T >::x, and point2< T >::y.
Referenced by construct().
00103 { 00104 assert(dx!=0.0); 00105 assert(mg.mz.valid()); 00106 assert(mg.mz.vi.size()==(1+mg.mz.dim[2])); 00107 00108 gobjpush(new gobjglDisable(GL_LIGHTING)); 00109 gobjpush(new gobjglBegin(GL_LINES)); 00110 00111 uint m=mg.mz.dim[0]; 00112 uint n=mg.mz.dim[1]; 00113 00114 uint id; 00115 point2<uint> pos1; 00116 point2<double> pos2; 00117 uint K=m*n-1; 00118 00119 if (walls) 00120 { 00121 gobjpush(new gobjglColor3d(wallcolor)); 00122 00123 for (uint k=0; k<mg.mz.dim[2]; ++k) 00124 { 00125 id=k+1; 00126 pos1.x = k % n; 00127 pos1.y = K/n-k/n; 00128 pos2.x = dx*pos1.x; 00129 pos2.y = dx*pos1.y; 00130 celldraw(mg.mz.vi[id],pos2); 00131 } 00132 } 00133 00134 if (pipes) 00135 { 00136 gobjpush(new gobjglColor3d(pipecolor)); 00137 for (uint k=0; k<mg.mz.dim[2]; ++k) 00138 { 00139 id=k+1; 00140 pos1.x = k % n; 00141 pos1.y = K/n-k/n; 00142 pos2.x = dx*pos1.x; 00143 pos2.y = dx*pos1.y; 00144 celldraw2(mg.mz.vi[id],pos2); 00145 } 00146 } 00147 00148 gobjpush(new gobjglEnd()); 00149 00150 // Each cell has a midpoint in the maze, calculate it. 00151 vector< point2<double> > pi; 00152 pi.push_back(point2<double>()); 00153 00154 for (uint k=0; k<mg.mz.dim[2]; ++k) 00155 { 00156 pi.push_back(cellmidpoint(k+1)); 00157 /* 00158 id=k+1; 00159 pos1.x = k % n; 00160 pos1.y = K/n-k/n; 00161 pos2.x = dx*pos1.x; 00162 pos2.y = dx*pos1.y; 00163 00164 pi.push_back(pos2+point2<double>(dx*0.5,dx*0.5)); 00165 */ 00166 } 00167 00168 if (displaycellid) 00169 { 00170 assert(gobjContainer::global); 00171 gobjpush(new gobjglColor3f(point3<float>(1.0,0.0,0.0))); 00172 pointsdisplay2D< point2<double> > pd(*gobjContainer::global,pi,false,true,true); 00173 } 00174 00175 gobjpush( new gobjglEnable(GL_LIGHTING) ); 00176 gobjpush( new gobjglColor3d(endpointcolor) ); 00177 00178 //double endpointsratio=0.25; 00179 00180 gobjpush( new gobjglPushMatrix() ); 00181 gobjpush( new gobjglTranslated( pi[mg.gamestart] ) ); 00182 gobjpush( new gobjglutSolidSphere(dx*endpointratio,35,35) ); 00183 gobjpush( new gobjglPopMatrix() ); 00184 00185 gobjpush( new gobjglPushMatrix() ); 00186 gobjpush( new gobjglTranslated( pi[mg.gamefinish] ) ); 00187 gobjpush( new gobjglutSolidSphere(dx*endpointratio,35,35) ); 00188 gobjpush( new gobjglPopMatrix() ); 00189 00190 }
| point3<double> mazedisp03::backgroundcolor |
Background color.
Definition at line 50 of file mazedisp03.h.
Referenced by maze005::eval(), maze004::eval(), game01default(), and settings().
Movement buttons.
Definition at line 78 of file mazedisp03.h.
Referenced by construct(), and maze004::reshape01().
| point3<double> mazedisp03::currentposcolor |
Current position and path color.
Definition at line 56 of file mazedisp03.h.
Referenced by currentposdraw(), game01default(), and settings().
Display the cells id.
Definition at line 38 of file mazedisp03.h.
Referenced by game01default(), settings(), and staticgraphics().
| double mazedisp03::dx |
Square cell side length.
Definition at line 36 of file mazedisp03.h.
Referenced by cellmidpoint(), currentposdraw(), game01default(), settings(), and staticgraphics().
| point3<double> mazedisp03::endpointcolor |
Start and finish sphere color.
Definition at line 54 of file mazedisp03.h.
Referenced by game01default(), settings(), and staticgraphics().
| double mazedisp03::endpointratio |
Size of start and finish spheres.
Definition at line 52 of file mazedisp03.h.
Referenced by currentposdraw(), game01default(), settings(), and staticgraphics().
Contains all the graphics.
Definition at line 27 of file mazedisp03.h.
Referenced by construct(), and draw().
Maze game.
Definition at line 33 of file mazedisp03.h.
Referenced by cellmidpoint(), currentposdraw(), and staticgraphics().
Functional object calling mouse(zpr&).
Definition at line 75 of file mazedisp03.h.
Referenced by maze005::eval(), and maze004::eval().
| point2<double> mazedisp03::origin |
Initial translation of maze.
Definition at line 48 of file mazedisp03.h.
Referenced by maze005::eval(), maze004::eval(), game01default(), and settings().
| point3<double> mazedisp03::pipecolor |
Color of pipes.
Definition at line 42 of file mazedisp03.h.
Referenced by game01default(), settings(), and staticgraphics().
Instead of drawing the walls, draw the paths.
Definition at line 40 of file mazedisp03.h.
Referenced by game01default(), settings(), and staticgraphics().
Index into gx for static geometry.
Definition at line 30 of file mazedisp03.h.
Referenced by construct().
| point3<double> mazedisp03::wallcolor |
Color of cell walls.
Definition at line 46 of file mazedisp03.h.
Referenced by game01default(), settings(), and staticgraphics().
Display the walls.
Definition at line 44 of file mazedisp03.h.
Referenced by game01default(), settings(), and staticgraphics().
Definition at line 76 of file mazedisp03.h.
Referenced by construct(), maze005::eval(), maze004::eval(), f01(), mouseevent(), and ~mazedisp03().
1.6.1