proj home

Files   Classes   Functions   Hierarchy  

main.cpp

Go to the documentation of this file.
00001 
00002 #include <cassert>
00003 #include <iostream>
00004 #include <deque>
00005 
00006 #include <GL/glut.h>
00007 #include <GL/gl.h>
00008 
00009 using namespace std;
00010 
00011 #include <typedefs.h>
00012 
00013 #include <point.h>
00014 #include <random.h>
00015 #include <gobj.h>
00016 
00017 #include <polytrimon.h>
00018 
00019 
00020 void shape02( vector< point2<float> > & vL )
00021 {
00022   vL.clear();
00023 
00024   uintc vsz = 7;
00025   float v[vsz*2] = 
00026   {
00027      4.0, 9.0,
00028      7.0, 8.0,
00029      7.0, 5.0,
00030      8.0, 3.0,
00031     12.0, 2.0,
00032      1.0, 0.0,
00033      0.0, 7.0
00034   };
00035 
00036   for (uint i=0; i<vsz; ++i)
00037     vL.push_back( point2<float>(v[i*2],v[i*2+1]) );
00038 }
00039 
00040 
00041 void shape01(vector< point2<float> > & vL)
00042 {
00043   vL.clear();
00044 
00045   uintc vsz = 25;
00046   float v[vsz*2] = 
00047   {
00048     6.0, 17.0,
00049     5.5, 16.0,
00050     6.5, 15.0,
00051     8.0, 14.0,
00052    11.0, 11.5,
00053 
00054    15.0, 10.5,
00055     8.0,  9.5,
00056    10.0,  9.0,
00057     7.0,  8.5,
00058     6.5,  7.5,
00059 
00060     9.0,  7.5,
00061     9.5,  6.5,
00062     9.0,  5.0,
00063     7.0,  3.0,
00064     9.0,  1.5,
00065 
00066    13.0,  0.0,
00067     0.0,  1.0,
00068     4.0,  2.0,
00069     9.0,  6.0,
00070     5.0,  6.0,
00071 
00072     3.0,  8.0,
00073     5.5, 10.0,
00074     6.0, 11.0,
00075     5.0, 12.0,
00076     1.0, 13.5,
00077   };
00078 
00079   for (uint i=0; i<vsz; ++i)
00080     vL.push_back( point2<float>(v[i*2],v[i*2+1]) );
00081 }
00082 
00083 class printtri
00084 {
00085 public:
00086 
00087   void operator () 
00088   (
00089     uintc i,
00090     uintc j,
00091     uintc k
00092   )
00093   {
00094     cout << "(" << i << "," << j << ",";
00095     cout << k << ")" << endl;
00096   }
00097 
00098 };
00099 
00100 
00101 void test01()
00102 {
00103 
00104   vector< point2<float> > pts;
00105 
00106   shape01(pts);
00107 
00108   polytrimon p(pts);
00109 
00110   p.tessellate( printtri() );
00111 
00112 }
00113 
00114 gobjContainer xGraphics(true);
00115 
00116 vector< point2<float> > pts;
00117 
00118 class drawtri
00119 {
00120   gobjContainer * c;
00121   random11<double> r;
00122 public:
00123 
00124   drawtri()
00125     { c = gobjContainer::global; }
00126   
00127   void operator () 
00128   (
00129     uintc i,
00130     uintc j,
00131     uintc k
00132   )
00133   {
00134     c->push( new gobjglColor3f(r(),r(),r()) );
00135     c->push( new gobjglVertex2f( pts[i].x, pts[i].y ) );
00136     c->push( new gobjglVertex2f( pts[j].x, pts[j].y ) );
00137     c->push( new gobjglVertex2f( pts[k].x, pts[k].y ) );
00138   }
00139 
00140 };
00141 
00142 
00143 
00144 void display()
00145 {
00146   glClear(GL_COLOR_BUFFER_BIT);
00147 
00148   xGraphics.draw();
00149 
00150   glFlush();
00151 }
00152 
00153 void keyboard(unsigned char key, int x, int y)
00154 {
00155   switch (key)
00156   {
00157     case 27:
00158       exit(0);
00159       break;
00160   }
00161 }
00162 
00163 void test02(int argc, char** argv)
00164 {
00165   glutInit(&argc,argv);
00166   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
00167   
00168   uintc wx=600;
00169   uintc wy=800;
00170   glutInitWindowSize(wx,wy);
00171 
00172   glutCreateWindow("");
00173   glutKeyboardFunc(keyboard);
00174 
00175   glMatrixMode(GL_PROJECTION);
00176   glLoadIdentity();
00177 
00178   
00179   float x0 = -5.0;
00180   float x1 = 20.0;
00181 
00182   float dx = x1-x0;
00183   float dy = dx/(float)wx*wy; 
00184   
00185   float y0 = -5.0;
00186   float y1 = dy;
00187 
00188   gluOrtho2D(x0,x1,y0,y1);
00189 
00190   glutDisplayFunc(display);
00191 
00192   xGraphics.set();
00193 
00194 
00195   //
00196   //  Finish with graphics initialization
00197 
00198   shape01(pts);
00199 
00200 
00201   gobjContainer * c = gobjContainer::global;
00202 /*
00203   c->push_back(new gobjglColor3f(1.0,0.0,0.0));
00204 
00205   c->push_back( new gobjGL_LINE_LOOP() );
00206   for (unsigned int i=0; i<pts.size(); ++i)
00207     c->push_back( new gobjglVertex2f(pts[i].x,pts[i].y) );
00208   c->push_back( new gobjglEnd() );
00209 */
00210 
00211   polytrimon p(pts);
00212 
00213   c->push( new gobjglBegin(GL_TRIANGLES) );
00214   p.tessellate( drawtri() );
00215   c->push( new gobjglEnd() );
00216 
00217   glutMainLoop();
00218 }
00219 
00220   
00221 
00222 
00223 
00224 
00225 int main(int argc, char** argv)
00226 {
00227   test02(argc,argv);
00228 
00229   return 0;
00230 }
00231 
00232 
00233 
00234 

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