proj home

Files   Classes   Functions   Hierarchy  

windowscaleD2test.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <commandline.h>
00005 #include <graphmisc.h>
00006 #include <mathdefaults.h>
00007 #include <pointsgraph.h>
00008 #include <windowscaleD2.h>
00009 #include <windowscaleD2test.h>
00010 #include <zpr.h>
00011 
00012 string windowscaleD2test::doc[] = 
00013 {
00014   "",
00015   "Basic tests converting between 2D windows on windowscaleD2 class.",
00016   ""
00017 };
00018 
00019 windowscaleD2test* windowscaleD2test::windowtest=0;
00020 
00021 int windowscaleD2test::test001(int argc, char** argv)
00022 {
00023   windowscaleD2 w1;
00024   w1.unitwindow();
00025 
00026   assertreturnOS( w1.isinside(.2,.7) );
00027   assertreturnOS( ! w1.isinside(-.2,.7) );
00028 
00029   string s1(".2 -1 5.7 8");
00030   windowscaleD2 w2;
00031   w2.serializeInverse(s1);
00032   cout << "w2=" << (stringc)w2 << endl;
00033   
00034   windowscaleD2 w3 = windowscaleD2::unitcentered;
00035   w3.scalexy(2.0);
00036   w3.update();
00037   cout << "w3=" << (stringc) w3 << endl;
00038 
00039   double x;
00040   double y;
00041   x=-1.0;
00042   y=-1.0;
00043   cout << SHOW(x) << " " << SHOW(y) << endl;
00044   cout << "Convert from window w3 to w2" << endl;
00045   w2.convertfrom(x,y,w3);
00046   cout << SHOW(x) << " " << SHOW(y) << endl;
00047   assertreturnOS( x==.2);
00048   assertreturnOS( y==-1);
00049   
00050   x=1.0;
00051   y=1.0;
00052   cout << SHOW(x) << " " << SHOW(y) << endl;
00053   cout << "Convert from window w3 to w2" << endl;
00054   w2.convertfrom(x,y,w3);
00055   cout << SHOW(x) << " " << SHOW(y) << endl;
00056   assertreturnOS( x==5.7);
00057   assertreturnOS( y==8);
00058 
00059   return 0;
00060 }
00061 
00062 void windowscaleD2test::keyboard01
00063 (
00064   unsigned char key, 
00065   int x, 
00066   int y
00067 )
00068 {
00069   switch (key)
00070   {
00071     case 27:
00072       exit(0);
00073       break;
00074 
00075     case 'r':
00076     {
00077       cout << "Resetting the camera." << endl;
00078       glMatrixMode(GL_MODELVIEW);
00079 
00080       glLoadIdentity();
00081       gluLookAt
00082       (
00083         0.0, 0.0, 2.0,  // Eye  - creates a x: [-2,2] y: [-2,2] screen.
00084         0.0, 0.0, 0.0,  // Center
00085         0.0, 1.0, 0.0   // Up
00086       );
00087       glutPostRedisplay();
00088     }
00089     break;
00090 
00091     case 'i':
00092     {
00093       if (windowtest==0)
00094         break; 
00095       cout << "graph=6 example, incrementing time." << endl;
00096 
00097       assert(windowtest!=0);
00098       windowscaleD2test& wt(*windowtest);
00099 
00100       wt.f04time += windowtest->f04timedx;
00101       wt.f04pg->push_back(wt.f04(wt.f04time)); 
00102       glutPostRedisplay();
00103     }
00104     break;
00105 
00106 
00107   }
00108 }
00109 
00110 void windowscaleD2test::display01()
00111 { 
00112   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00113 
00114   gobj::global->draw();
00115 
00116   glerrordisplay();
00117   
00118   glutSwapBuffers();
00119 }
00120 
00121 
00122 void windowscaleD2test::test002(int argc, char** argv)
00123 {
00124   glutInit(&argc,argv);
00125   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00126   glutInitWindowSize(600,600);
00127   glutCreateWindow("");
00128   glutDisplayFunc(display01);
00129   glutKeyboardFunc(keyboard01);
00130 
00131   OpenGLinitialisation();
00132 
00133   glEnable(GL_DEPTH_TEST);
00134   glEnable(GL_CULL_FACE);
00135   glEnable(GL_NORMALIZE);
00136 
00137   xGraphics.set();
00138 
00139   //pointsgraph* pg = new pointsgraph();
00140   //pg->screen.construct(-1.0,-2.0,1.0,2.0);
00141   //pg->world.construct(0.0,0.0,2.0,2.0);
00142   pointsgraph* pg = new pointsgraph(
00143     windowscaleD2(-1.0,-2.0,1.0,2.0),
00144     windowscaleD2(0.0,0.0,2.0,2.0));
00145 
00146   commandline cmd(argc,argv);
00147 
00148   int graph=1;
00149   cmd.mapvar(graph,"graph");
00150 
00151   switch (graph)
00152   {
00153     case 1: 
00154     {
00155       // y =1-x^2 x=[-1,1]
00156       y01 f01;
00157       pg->samplefunction(f01,1000);
00158     }
00159     break;
00160 
00161     case 2:
00162     {
00163       y01 f01;
00164       pg->samplefunction(f01,1000);
00165 //for (uint i=0; i<pg->pts.size(); ++i)
00166 //  {  cout << i << ": " <<  pg->pts[i] << endl; }
00167   
00168 //cout << SHOW((stringc)(pg->screen)) << endl;
00169       pg->world.shiftxy((double)-1.0,(double)-1.0);
00170       pg->screen_rescaley();
00171     }
00172     break;
00173 
00174     case 3:
00175     {
00176       y02 f01;
00177       pg->screen.xmin=0;
00178       pg->screen.xmax=PI*2;
00179       pg->samplefunction(f01,200);
00180       pg->world.shiftxy((double)-1.0,(double)-1.0);
00181       pg->screen_rescaley();
00182 for (uint i=0; i<pg->pts.size(); ++i)
00183   {  cout << i << ": " <<  pg->pts[i] << endl; }
00184 cout << SHOW((stringc)(pg->screen)) << endl;
00185     }
00186     break;
00187 
00188     case 4:
00189     {
00190       // Turned off with singularity.
00191       pointsgraph::isinside=false; 
00192       y03 f01;
00193       double h=3.0;
00194       pg->domain(-h,h);
00195       pg->samplefunction(f01,8);
00196       pg->world.shiftxy((double)-1.0,(double)-1.0);
00197 //      pg->screen_rescaley();
00198 for (uint i=0; i<pg->pts.size(); ++i)
00199   {  cout << i << ": " <<  pg->pts[i] << endl; }
00200     };
00201 
00202     case 5:
00203     {
00204       y02 f01;
00205       pg->domain(-PI*3,PI*3);
00206       pg->samplefunction(f01,200);
00207       pg->domain(-PI*0.5,PI*0.5);
00208       pg->clipwindow=true;
00209       pg->world.shiftxy((double)-1.0,(double)-1.0);
00210       pg->screen_rescaley();
00211 for (uint i=0; i<pg->pts.size(); ++i)
00212   {  cout << i << ": " <<  pg->pts[i] << endl; }
00213 cout << SHOW((stringc)(pg->screen)) << endl;
00214 cout << "Function with larger domain created." << endl;
00215 cout << "  Displaying a section of the sin graph." << endl;
00216     }
00217     break;
00218 
00219     case 6:
00220     {
00221       windowtest=this;
00222 
00223       delete pg;
00224       f04pg = new pointsgraphtime(10);
00225       pg = f04pg;
00226       pg->screen = 
00227         windowscaleD2(0.0,-1.0,1.0,1.0);
00228       pg->world = 
00229         windowscaleD2(-1.0,-1.0,1.0,1.0);
00230       pg->update();
00231 
00232       f04time=0.0;
00233       f04pg->push_back( f04(f04time) );
00234       f04timedx=0.1;
00235 
00236     }
00237     break;
00238 
00239   }
00240 
00241 /*
00242   uint N=10;
00243   double dx = 1.0;
00244   dx /= (N-1);
00245 
00246   double x;
00247   double y;
00248   for (uint i=0; i<N; ++i)
00249   {
00250     x = dx*i;
00251     pg->screen.unitscaleInverse_x(x);
00252     f01(y,x);
00253     
00254     pg->pts.push_back( point2<double>(x,y) ); 
00255   }
00256 */
00257 
00258   gobjpush(new gobjglPushAttrib(GL_CURRENT_BIT));
00259   gobjpush(new gobjglPushAttrib(GL_LIGHTING_BIT));
00260   gobjpush(new gobjglColor3d(1.0,.02,.13));
00261   gobjpush(new gobjglDisable(GL_LIGHTING));
00262   gobjpush(pg);
00263   gobjpush(new gobjglPopAttrib());
00264   gobjpush(new gobjglPopAttrib());
00265 
00266   pointsgraph_axes_circle* a2 = new pointsgraph_axes_circle();
00267   double xval[] = { 0,1,2,-1,-2 };
00268   copy(xval,xval+5,back_inserter(a2->xaxis));
00269   double yval[] = { 1,2,-1,-2 };
00270   copy(yval,yval+4,back_inserter(a2->yaxis));
00271   a2->update();
00272   gobjpush(a2);
00273   
00274 
00275   zpr zz;
00276   zz.update();
00277   glutMainLoop();
00278 }
00279 

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