proj home

Files   Classes   Functions   Hierarchy  

cubedraw2d.cpp

Go to the documentation of this file.
00001 #include <cubedraw2d.h>
00002 #include <graphmisc.h>
00003 
00004 
00005 cubedraw2d::cubedraw2d
00006 (
00007   cube const & cb_, 
00008   doublec dx_
00009 )
00010   : cbd(cb_), dx(dx_) {}
00011 
00012 void cubedraw2d::writeface(uintc i)
00013 {
00014   double x;
00015   double y = 3.0*dx;
00016 
00017   uint index = i*9;
00018 
00019   glBegin(GL_TRIANGLES);
00020 
00021   for (uint k=0; k<3; ++k)
00022   {
00023     x=0.0;
00024     for (uint w=0; w<3; ++w)
00025     {
00026       // Write the square
00027       // x,y point to top left of square.
00028 
00029       //cbd.colorset(cb.x[index]);
00030       cbd.colorset(index);
00031 
00032       glVertex2d(x,y);
00033       glVertex2d(x,y-dx);
00034       glVertex2d(x+dx,y);
00035 
00036       glVertex2d(x+dx,y);
00037       glVertex2d(x,y-dx);
00038       glVertex2d(x+dx,y-dx);
00039 
00040       x += dx;
00041       ++index;
00042     }
00043     y -= dx;
00044   }
00045 
00046   glEnd();
00047 }
00048 
00049 
00050 void cubedraw2d::draw()
00051 {
00052 cout << "TODO look at cubedraw2d::draw()" << endl;
00053 
00054   glPushMatrix();
00055   glLoadIdentity();
00056 
00057   glPushAttrib(GL_CURRENT_BIT);
00058   glPushAttrib(GL_LIGHTING_BIT);
00059 
00060   doublec w = dx * 3.0;
00061 
00062   doublec xlen = 25.0;
00063   doublec ylen = 0.75*xlen;
00064   gluOrtho2D(0.0,xlen,0.0,ylen);
00065 
00066   doublec x0(0.4*xlen);
00067   doublec y0(0.3*ylen);
00068 
00069   glPushMatrix();
00070 
00071   glDisable(GL_LIGHTING);
00072 
00073   glTranslated(x0,y0,0.0);
00074   writeface(0);
00075 
00076   // Broken code to draw the cursor.
00077   cursor const & cs(cbd.cb.cs);
00078   double y = dx/3.0;
00079   glTranslated((dx-y)*0.5+cs.j*dx,dx*0.4+cs.k*dx,0.01);
00080 
00081   {
00082     glBegin(GL_TRIANGLES);
00083 
00084     glColor3f(1.0,0.0,0.0);
00085     glVertex2d(0.0,0.0);
00086 
00087     glColor3f(1.0,0.0,0.0);
00088     glVertex2d(y,0.0);
00089   
00090     glColor3f(0.0,0.0,1.0);
00091     glVertex2d(y*0.5,y*0.866);
00092 
00093     glEnd();
00094   }
00095   glPopMatrix();
00096 
00097 
00098   glPushMatrix();
00099   glTranslated(x0+w,y0,0.0);
00100   writeface(1);
00101   glPopMatrix();
00102 
00103   glPushMatrix();
00104   glTranslated(x0-w,y0,0.0);
00105   writeface(3);
00106   glPopMatrix();
00107 
00108   glPushMatrix();
00109   glTranslated(x0+2.0*w,y0,0.0);
00110   writeface(2);
00111   glPopMatrix();
00112 
00113   glPushMatrix();
00114   glTranslated(x0,y0+w,0.0);
00115   writeface(5);
00116   glPopMatrix();
00117 
00118   glPushMatrix();
00119   glTranslated(x0,y0-w,0.0);
00120   writeface(4);
00121   glPopMatrix();
00122 
00123 
00124   glPopAttrib();
00125   glPopAttrib();
00126 
00127   glerrordisplay();
00128 
00129   glPopMatrix();
00130 
00131 }
00132 
00133 
00134 
00135 
00136 

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