proj home

Files   Classes   Functions   Hierarchy  

maze001.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 
00005 #include <commandline.h>
00006 #include <graphmisc.h>
00007 #include <maze001.h>
00008 #include <zpr.h>
00009 
00010 string maze001::doc[] = 
00011 {
00012   "",
00013   "Display an easy one path maze."
00014 };
00015 
00016 void maze001::keyboard01
00017 (
00018   unsigned char key, 
00019   int x, 
00020   int y
00021 )
00022 {
00023   switch (key)
00024   {
00025     case 27:
00026       exit(0);
00027       break;
00028   }
00029 }
00030 
00031 void maze001::display01()
00032 { 
00033   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00034 
00035   gobj::global->draw();
00036 
00037 
00038   glerrordisplay();
00039   
00040   glutSwapBuffers();
00041 }
00042 
00043 void maze001::celldraw
00044 ( 
00045   cellD2<uint> const & x,
00046   point2<double> const & p00
00047 )
00048 {
00049   point2<double> p10 = p00;
00050   p10.x += dx;
00051   point2<double> p01 = p00;
00052   p01.y += dx;
00053   point2<double> p11 = p00;
00054   p11.x += dx;
00055   p11.y += dx;
00056 
00057   if (x.ni[1]==0)
00058   {
00059     gobjpush(new gobjglVertex2d(p10));
00060     gobjpush(new gobjglVertex2d(p11));
00061   }
00062 
00063   if (x.ni[3]==0)
00064   {
00065     gobjpush(new gobjglVertex2d(p01));
00066     gobjpush(new gobjglVertex2d(p00));
00067   }
00068 
00069   
00070   if (x.ni[0]==0)
00071   {
00072     gobjpush(new gobjglVertex2d(p01));
00073     gobjpush(new gobjglVertex2d(p11));
00074   }
00075   
00076   if (x.ni[2]==0)
00077   {
00078     gobjpush(new gobjglVertex2d(p00));
00079     gobjpush(new gobjglVertex2d(p10));
00080   }
00081 
00082 
00083 
00084 }
00085 
00086 void maze001::constructgraphics()
00087 {
00088 
00089   gobjpush(new gobjglDisable(GL_LIGHTING));
00090   gobjpush(new gobjglBegin(GL_LINES));
00091   gobjpush(new gobjglColor3f(0.0,0.0,1.0));
00092 
00093   uint id;
00094   point2<int> pos1;
00095   point2<double> pos2;
00096   for (mmap.reset(); !mmap; ++mmap)
00097   {
00098     id=mmap.currentIndex();
00099     pos1=mmap.currentPosition();
00100     pos2.x = dx*pos1.x+origin.x;
00101     pos2.y = dx*pos1.y+origin.y;
00102     celldraw(mz.vi[id],pos2);
00103   }
00104 
00105   gobjpush(new gobjglEnd()); 
00106 }
00107 
00108 maze001::maze001(int argc, char** argv)
00109   : mz(3,3), mmap(mz,1,1), xGraphics(true)
00110 {
00111   glutInit(&argc,argv);
00112   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00113   glutInitWindowSize(800,600);
00114   glutCreateWindow("");
00115   glutDisplayFunc(maze001::display01);
00116   glutKeyboardFunc(maze001::keyboard01);
00117 
00118   OpenGLinitialisation();
00119 
00120   glEnable(GL_DEPTH_TEST);
00121   glEnable(GL_CULL_FACE);
00122   glEnable(GL_NORMALIZE);
00123 
00124   xGraphics.set();
00125 
00126   commandline cmd(argc,argv);
00127 
00128   uint k;
00129   k = mz.add();
00130   uint k2;
00131   k2 = mz.add();
00132   mz.link(k,1,1,3);
00133 
00134   mz.link(1,1,2);
00135   mz.link(2,1,3);
00136   mz.link(3,2,6);
00137   mz.link(6,3,5);
00138   mz.link(5,3,4);
00139   mz.link(4,2,7);
00140   mz.link(7,1,8);
00141   mz.link(8,1,9);
00142   mz.link(9,1,k2);
00143 
00144   assert(mz.valid());
00145 
00146   mmap.relativeto(1);
00147   mmap.eval();
00148 
00149   dx=0.2;
00150   origin = point2<double>(0.0,0.0);
00151 
00152   cmd.mapvar(dx,"dx");
00153   cmd.mapvar(origin.x,"originx");
00154   cmd.mapvar(origin.y,"originy");
00155   
00156 
00157 
00158 /*
00159   gobjpush(new gobjglColor3ub(34,139,34));
00160   //gridsquare * gs = new gridsquare(1,0x0101,5,5,1.0,1.0);
00161   gridsquare * gs = new gridsquare(1,0xaaaa,5,5,1.0,1.0);
00162   
00163   gobjpush(gs);
00164 */
00165 
00166 }
00167 
00168 
00169 void maze001::eval()
00170 {
00171   constructgraphics();
00172 
00173   zpr zz;
00174 
00175   zz.update();
00176   glutMainLoop();
00177 }
00178 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8