proj home

Files   Classes   Functions   Hierarchy  

triangles3Tdisplaytest.cpp

Go to the documentation of this file.
00001 #include <cassert>
00002 #include <vector>
00003 using namespace std;
00004 
00005 
00006 #include <commandline.h>
00007 #include <gobj.h>
00008 #include <graphmisc.h>
00009 #include <point.h>
00010 #include <random.h>
00011 #include <triangles3Tdisplay.h>
00012 #include <triangles3Tdisplaytest.h>
00013 #include <triangles3Tdisplaymulticolored.h>
00014 #include <zpr.h>
00015 
00016 
00017 triangles3Tdisplaytest::triangles3Tdisplaytest()
00018   : xGraphics(true)
00019 {
00020 }
00021 
00022 void triangles3Tdisplaytest::pipe01
00023 (
00024   uintc n,
00025   vector<point3<uint> > & tri,
00026   vector<point3<double> > & pts
00027 )
00028 {
00029   uint pts0 = pts.size();
00030   doublec pi(3.141592654);
00031 
00032   assert(n>1);
00033   double angle = pi*2.0/ (double)n;
00034 
00035   for (uint i=0; i<n; ++i)
00036   {
00037     pts.push_back
00038     ( 
00039       point3<double>
00040       ( 
00041         cos(angle*(double)i), 
00042         0.0,
00043         sin(angle*(double)i) 
00044       )
00045     );
00046   }
00047 
00048   for (uint i=0; i<n; ++i)
00049   {
00050     pts.push_back
00051     ( 
00052       point3<double>( pts[pts0+i].x, 1.0, pts[pts0+i].z)
00053     );
00054   }
00055 
00056   for (uint i=1; i<n; ++i)
00057     tri.push_back( point3<uint>(pts0+i-1, pts0+i-1+n, pts0+i) );
00058   tri.push_back( point3<uint>(pts0+n-1, pts0+n-1+n, pts0) );
00059 
00060   for (uint i=1; i<n; ++i)
00061     tri.push_back( point3<uint>(pts0+i-1+n, pts0+i+n, pts0+i) );
00062   tri.push_back( point3<uint>(pts0+n-1+n, pts0+n, pts0) );
00063 }
00064 
00065 
00066 
00067 void triangles3Tdisplaytest::display01()
00068 {
00069   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00070 
00071   gobj::global->draw();
00072 
00073   glerrordisplay();
00074   
00075   glutSwapBuffers();
00076 }
00077 
00078 void triangles3Tdisplaytest::keyboard01(unsigned char key, int x, int y)
00079 {
00080   switch (key)
00081   {
00082     case 27:
00083       exit(0);
00084       break;
00085   }
00086 }
00087 
00088 void triangles3Tdisplaytest::test01(int argc, char** argv)
00089 {
00090   glutInit(&argc,argv);
00091   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00092   glutInitWindowSize(800,600);
00093   glutCreateWindow("");
00094   glutDisplayFunc(triangles3Tdisplaytest::display01);
00095   glutKeyboardFunc(triangles3Tdisplaytest::keyboard01);
00096 
00097   OpenGLinitialisation();
00098 
00099   glEnable(GL_DEPTH_TEST);
00100   glEnable(GL_CULL_FACE);
00101   glEnable(GL_NORMALIZE);
00102 
00103 
00104   xGraphics.set();
00105 
00106   vector< point3<double> > pts;
00107   vector< point3<uint> > tri;
00108 
00109   commandline cmd(argc,argv);
00110   uint n(80);
00111   cmd.mapvar(n,"n");
00112 
00113   pipe01(n,tri,pts);
00114 
00115   //gobjpush(new gobjglColor3ub(184,134,11) );
00116   gobjpush(new gobjglColor3ub(119,136,153) );
00117 
00118   triangles3Tdisplay<GLfloat,double> * tridisp =
00119     new triangles3Tdisplay<GLfloat,double>(tri.size(), & tri[0], & pts[0]);
00120   gobjpush(tridisp);
00121 
00122   cout << print(pts.begin(),pts.end(),"\n") << endl;
00123   //cout << printvecfunc(& pts[0],pts.size(),"\n") << endl;
00124   //cout << printvecfunc(tridisp->vi,tridisp->visize,"\n") << endl;
00125 
00126   //triangles3Tdisplay<> tridisp(tri.size(), & tri[0], & pts[0] );
00127   //gobjpush(&tridisp);
00128 
00129 
00130 
00132   zpr zz;
00133   glutMainLoop();
00134 }
00135 
00136 
00137 
00138 void triangles3Tdisplaytest::pipe02
00139 (
00140   uintc n,
00141   vector<point3<uint> > & tri,
00142   vector<point3<double> > & pts,
00143   vector<point3<double> > & normals
00144 )
00145 {
00146   uint pts0 = pts.size();
00147   doublec pi(3.141592654);
00148 
00149   assert(n>1);
00150   double angle = pi*2.0/ (double)n;
00151 
00152   for (uint i=0; i<n; ++i)
00153   {
00154     pts.push_back
00155     ( 
00156       point3<double>
00157       ( 
00158         cos(angle*(double)i), 
00159         0.0,
00160         sin(angle*(double)i) 
00161       )
00162     );
00163     normals.push_back( pts[pts0+i] );
00164   }
00165 
00166   for (uint i=0; i<n; ++i)
00167   {
00168     pts.push_back
00169     ( 
00170       point3<double>( pts[pts0+i].x, 1.0, pts[pts0+i].z)
00171     );
00172     normals.push_back( pts[pts0+i] );
00173   }
00174 
00175   for (uint i=1; i<n; ++i)
00176     tri.push_back( point3<uint>(pts0+i-1, pts0+i-1+n, pts0+i) );
00177   tri.push_back( point3<uint>(pts0+n-1, pts0+n-1+n, pts0) );
00178 
00179   for (uint i=1; i<n; ++i)
00180     tri.push_back( point3<uint>(pts0+i-1+n, pts0+i+n, pts0+i) );
00181   tri.push_back( point3<uint>(pts0+n-1+n, pts0+n, pts0) );
00182 }
00183 
00184 
00185 
00186 
00187 void triangles3Tdisplaytest::test02(int argc, char** argv)
00188 {
00189   glutInit(&argc,argv);
00190   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00191   glutInitWindowSize(800,600);
00192   glutCreateWindow("");
00193   glutDisplayFunc(triangles3Tdisplaytest::display01);
00194   glutKeyboardFunc(triangles3Tdisplaytest::keyboard01);
00195 
00196   OpenGLinitialisation();
00197 
00198   glEnable(GL_DEPTH_TEST);
00199   glEnable(GL_CULL_FACE);
00200   glEnable(GL_NORMALIZE);
00201 
00202 
00203   xGraphics.set();
00204 
00205   vector< point3<double> > pts;
00206   vector< point3<uint> > tri;
00207   vector< point3<double> > normals;
00208 
00209   commandline cmd(argc,argv);
00210   uint n(80);
00211   cmd.mapvar(n,"n");
00212 
00213   pipe02(n,tri,pts,normals);
00214 
00215   gobjpush(new gobjglColor3ub(119,136,153) );
00216   triangles3TdisplayN<GLfloat,double> * tridisp =
00217     new triangles3TdisplayN<GLfloat,double>(tri.size(), & tri[0], & pts[0], & normals[0]);
00218   gobjpush(tridisp);
00219 
00220 /*
00221   triangles3fdisplayN<> * tridisp =
00222     new triangles3fdisplayN<>(tri.size(), & tri[0], & pts[0], & normals[0]);
00223   gobjpush(tridisp);
00224 */
00225 
00226 /*
00227   cout << printvecfunc(& pts[0],pts.size(),"\n") << endl;
00228   //cout << printvecfunc(tridisp->vi,tridisp->visize,"\n") << endl;
00229 
00230   //triangles3fdisplay<> tridisp(tri.size(), & tri[0], & pts[0] );
00231   //gobjpush(&tridisp);
00232 */
00233 
00235   zpr zz;
00236   glutMainLoop();
00237 }
00238 
00239 
00240 
00241 
00242 void triangles3Tdisplaytest::test03(int argc, char** argv)
00243 {
00244   glutInit(&argc,argv);
00245   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00246   glutInitWindowSize(800,600);
00247   glutCreateWindow("");
00248   glutDisplayFunc(triangles3Tdisplaytest::display01);
00249   glutKeyboardFunc(triangles3Tdisplaytest::keyboard01);
00250 
00251   OpenGLinitialisation();
00252 
00253   glEnable(GL_DEPTH_TEST);
00254   glEnable(GL_CULL_FACE);
00255   glEnable(GL_NORMALIZE);
00256 
00257 
00258   xGraphics.set();
00259 
00260   vector< point3<double> > pts;
00261   vector< point3<uint> > tri;
00262   vector< point3<double> > normals;
00263   vector< point3<double> > colors;
00264 
00265   commandline cmd(argc,argv);
00266   uint n(80);
00267   cmd.mapvar(n,"n");
00268 
00269   pipe02(n,tri,pts,normals);
00270 
00271   random11<double> r;
00272   for (uint i=0; i<pts.size(); ++i)
00273     colors.push_back( point3<double>(r(),r(),r()) );
00274 
00275   //gobjpush(new gobjglColor3ub(119,136,153) );
00276   triangles3TdisplayNC<GLfloat,double,double> * tridisp =
00277     new triangles3TdisplayNC<GLfloat,double,double>
00278       (tri.size(), & tri[0], & pts[0], & normals[0], & colors[0]);
00279   gobjpush(tridisp);  
00280 
00282   zpr zz;
00283   glutMainLoop();
00284 }
00285 
00286 
00287 void triangles3Tdisplaytest::test04(int argc, char** argv)
00288 {
00289   glutInit(&argc,argv);
00290   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00291   glutInitWindowSize(800,600);
00292   glutCreateWindow("");
00293   glutDisplayFunc(triangles3Tdisplaytest::display01);
00294   glutKeyboardFunc(triangles3Tdisplaytest::keyboard01);
00295 
00296   OpenGLinitialisation();
00297 
00298   glEnable(GL_DEPTH_TEST);
00299   glEnable(GL_CULL_FACE);
00300   glEnable(GL_NORMALIZE);
00301 
00302 
00303   xGraphics.set();
00304 
00305   vector< point3<double> > pts;
00306   vector< point3<uint> > tri;
00307   vector< point3<double> > normals;
00308   vector< point3<double> > colors;
00309 
00310   commandline cmd(argc,argv);
00311   uint n(80);
00312   cmd.mapvar(n,"n");
00313 
00314   pipe02(n,tri,pts,normals);
00315 
00316   random11<double> r;
00317   for (uint i=0; i<tri.size(); ++i)
00318     colors.push_back( point3<double>(r(),r(),r()) );
00319 
00320   triangles3TdisplayNCpertriangle<GLfloat,double,double> * tridisp =
00321     new triangles3TdisplayNCpertriangle<GLfloat,double,double>
00322       (tri.size(), & tri[0], & pts[0], & normals[0], & colors[0]);
00323   gobjpush(tridisp);  
00324 
00326   zpr zz;
00327   glutMainLoop();
00328 }
00329 
00330 
00331 
00332 void triangles3Tdisplaytest::test05(int argc, char** argv)
00333 {
00334   glutInit(&argc,argv);
00335   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00336   glutInitWindowSize(800,600);
00337   glutCreateWindow("");
00338   glutDisplayFunc(triangles3Tdisplaytest::display01);
00339   glutKeyboardFunc(triangles3Tdisplaytest::keyboard01);
00340 
00341   OpenGLinitialisation();
00342 
00343   glEnable(GL_DEPTH_TEST);
00344   glEnable(GL_CULL_FACE);
00345   glEnable(GL_NORMALIZE);
00346 
00347   xGraphics.set();
00348 
00349   vector< point3<double> > pts;
00350   vector< point3<uint> > tri;
00351   vector< point3<double> > colors;
00352 
00353   commandline cmd(argc,argv);
00354   uint n(80);
00355   cmd.mapvar(n,"n");
00356 
00357   pipe01(n,tri,pts);
00358 
00359 /*
00360   random11<double> r;
00361   for (uint i=0; i<tri.size(); ++i)
00362     colors.push_back( point3<double>(r(),r(),r()) );
00363 
00364   triangles3TdisplayCpertriangle<GLfloat,double,double> * tridisp =
00365     new triangles3TdisplayCpertriangle<GLfloat,double,double>
00366       (tri.size(), & tri[0], & pts[0], & colors[0]);
00367   gobjpush(tridisp);  
00368 */
00369 
00370   triangles3Tdisplaymulticolored<GLfloat,double> * tridisp =
00371     new triangles3Tdisplaymulticolored<GLfloat,double>
00372       (tri.size(), & tri[0], & pts[0]);
00373   gobjpush(tridisp);
00374 
00376   zpr zz;
00377   zz.update();
00378   glutMainLoop();
00379 }
00380 
00381 

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