proj home

Files   Classes   Functions   Hierarchy  

d2simplextest.cpp

Go to the documentation of this file.
00001 
00002 #include <d2arrow.h>
00003 #include <d2simplex.h>
00004 #include <d2simplextest.h>
00005 #include <gobj.h>
00006 #include <graphmisc.h>
00007 #include <mathlib.h>
00008 #include <menusystem.h>
00009 #include <primitivewindow.h>
00010 #include <zpr.h>
00011 
00012 
00013 typedef point2<double> pt2;
00014 typedef point2<double> const pt2c;  
00015 
00016 
00017 
00018 void d2simplextest::keyboard(unsigned char key, int x, int y)
00019 { 
00020   menu->read(key); 
00021 }
00022 
00023 d2simplextest::d2simplextest(int & argc, char** argv)
00024   : myglutgui(argc,argv), si(A,B)
00025 {
00026   OpenGLinitialisation();
00027   
00028   glEnable(GL_DEPTH_TEST);
00029   glEnable(GL_CULL_FACE);
00030 
00031   globalSet();
00032   menu = new d2simplextestmenu01(this); 
00033 
00034   xGraphics.set();
00035   xGraphics.push( menu );
00036   xGraphics.push( & si );
00037 }
00038 
00039 void d2simplextest::test01()
00040 {
00041   glMatrixMode(GL_MODELVIEW);
00042   glLoadIdentity();
00043   gluLookAt
00044   (
00045     2.0,0.0,3.0, 
00046     2.0,0.0,0.0, 
00047     0.0,1.0,0.0
00048   );
00049 
00050   zz.update();
00051 
00052 
00053 /*
00054   glMatrixMode(GL_PROJECTION);
00055   glLoadIdentity();
00056 
00057   //glFrustum(2.0,10.5,-1.0,6.0,1.5,20.1);
00058 
00059   double z0=0.4;
00060   double z1=10.1;
00061   cout << SHOW(z1/z0) << endl;
00062   glFrustum(500.5,15.5,-2.5,6.0,z0,z1);
00063   
00064   glMatrixMode(GL_MODELVIEW);
00065 
00066 */
00067 
00068 
00069   //zpr::readProjection();
00070   //zpr::printInfo();
00071 
00072 
00073   //zpr::setViewVolume(-0.5,3.5,-0.5,1.0,0.1,4.1);
00074   //zpr::setViewVolume(2.0,3.5,-1.0,8.0,0.9,4.0);
00075 
00076 //cout << SHOW(zpr::zNear) << endl;
00077 //cout << SHOW(zpr::zFar) << endl;
00078 
00079   A.v[0] = pt2(0.0,0.0);
00080   A.v[1] = pt2(1.0,0.0);
00081   A.v[2] = pt2(0.5,0.5);
00082 
00083   B.v[0] = pt2(.2,.23);
00084   B.v[1] = pt2(.4,.23);
00085   B.v[2] = pt2(.4,.5);
00086 
00087   B.translate( pt2(2.0,0.0) );
00088 
00089 
00090   //zpr::printInfo();
00091 
00092   glutPostRedisplay();
00093 
00094   glutMainLoop();
00095 }
00096 
00097 d2simplextest::~d2simplextest()
00098 {
00099   delete menu;
00100   menu = 0;
00101 }
00102 
00103 
00104 void d2simplextest::display()
00105 {
00106   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00107 
00108   //menu.draw();
00109   //si.draw();
00110 
00111   xGraphics.draw();
00112 
00113   glerrordisplay();
00114   glutSwapBuffers();
00115 }
00116 
00117 void d2simplextest::intersection()
00118 {
00119   si.intersection = A.intersects(B);
00120 //cout << SHOW(si.intersection) << endl;
00121 }
00122 
00123 
00124 
00125 
00126 
00127 d2simplextestmenu01::d2simplextestmenu01(d2simplextest * _test)
00128   : menusystem(this,0,true,point2<int>(60,30),20), test(_test)
00129 {
00130   assert(test!=0);
00131 
00132   addfont12("Simplex and Simplex Intersection");
00133   addnewline();
00134   addnewline();
00135   addfont10("'j' 'J'  Rotate A anti clockwise and clockwise");
00136   addnewline();
00137   addfont10("'k' 'K'  Translate A right and left");
00138   addnewline();
00139   addfont10("'l' 'L'  Translate A up and down");
00140   addnewline();
00141   addfont10("'u' 'U'  Rotate B anti clockwise and clockwise");
00142   addnewline();
00143   addfont10("'i' 'I'  Translate B right and left");
00144   addnewline();
00145   addfont10("'o' 'O'  Translate B up and down");
00146 
00147   addnewline();
00148   addnewline();
00149   addfont10("ESC      Quit");
00150 }
00151 
00152 
00153 void d2simplextestmenu01::readImmediate(char const key)
00154 {
00155   static double delta = 0.02;
00156   static double theta = 0.1;
00157 
00158   switch (key)
00159   {
00160     case 27:
00161       exit(0);
00162       break;
00163 
00164     case 'j':
00165       test->A.rotate(theta);
00166       break;
00167 
00168     case 'J':
00169       test->A.rotate(-theta);
00170       break;
00171 
00172     case 'k':
00173       test->A.translate( pt2(delta,0.0) );
00174       break;
00175 
00176     case 'K':
00177       test->A.translate( pt2(-delta,0.0) );
00178       break;
00179 
00180 
00181     case 'l':
00182       test->A.translate( pt2(0.0,delta) );
00183       break;
00184 
00185     case 'L':
00186       test->A.translate( pt2(0.0,-delta) );
00187       break;
00188 
00189     case 'u':
00190       test->B.rotate(theta);
00191       break;
00192 
00193     case 'U':
00194       test->B.rotate(-theta);
00195       break;
00196 
00197     case 'i':
00198       test->B.translate( pt2(delta,0.0) );
00199       break;
00200 
00201     case 'I':
00202       test->B.translate( pt2(-delta,0.0) );
00203       break;
00204 
00205 
00206     case 'o':
00207       test->B.translate( pt2(0.0,delta) );
00208       break;
00209 
00210     case 'O':
00211       test->B.translate( pt2(0.0,-delta) );
00212       break;
00213 
00214   }
00215 
00216   test->intersection();
00217 
00218   glutPostRedisplay();
00219 }
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 

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