proj home

Files   Classes   Functions   Hierarchy  

cubedraw3d.cpp

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

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