proj home

Files   Classes   Functions   Hierarchy  

boxOBBhalfspaceD2test Class Reference

Orientated Bounding Boxes test. More...

#include <boxOBBhalfspaceD2test.h>

Collaboration diagram for boxOBBhalfspaceD2test:

List of all members.

Public Member Functions

void test01 (int &argc, char **argv)
 Load two OBBsepaxisD2 boxes and display.

Static Public Member Functions

static void display01 ()
 Display handler.
static void keyboard01 (unsigned char key, int x, int y)
 Keyboard handler for test01.
static void update01 ()
 Update for test01 before graphics display.
static int unittest01 ()
 Test the boxOBBhalfspaceD2<PT,PD>::construct(.
static int unittest02 (int &argc, char **argv)
 Test if the point q is inside the box.

Public Attributes

gobjContainer xGraphics
 Global graphics container.

Static Public Attributes

static boxOBBhalfspaceD2
< point2< double >, double > * 
Aptr
 OBB object A.
static boxOBBhalfspaceD2
< point2< double >, double > * 
Bptr
 OBB object B.
static boolhelp = 0
 Toggle the help menu.
static gobjContainer boxes
 Graphics to display the boxes.


Detailed Description

Orientated Bounding Boxes test.

Definition at line 13 of file boxOBBhalfspaceD2test.h.


Member Function Documentation

void boxOBBhalfspaceD2test::display01 (  )  [static]

Display handler.

Definition at line 24 of file boxOBBhalfspaceD2test.cpp.

References gobjContainer::draw(), glerrordisplay(), and gobj::global.

Referenced by test01().

00025 {
00026   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00027 
00028   gobj::global->draw();
00029 
00030   glerrordisplay();
00031   
00032   glutSwapBuffers();
00033 }

void boxOBBhalfspaceD2test::keyboard01 ( unsigned char  key,
int  x,
int  y 
) [static]

Keyboard handler for test01.

Definition at line 35 of file boxOBBhalfspaceD2test.cpp.

References Aptr, boxOBBhalfspaceD2< PT, PD >::arm1, boxOBBhalfspaceD2< PT, PD >::arm2, Bptr, boxOBBhalfspaceD2< PT, PD >::center, delta, transrotate2D::eval(), help, update01(), point2< T >::x, and point2< T >::y.

Referenced by test01().

00036 {
00037   static double delta = 0.1;
00038 
00039   assert(Aptr!=0);
00040   assert(Bptr!=0);
00041 
00042   switch (key)
00043   {
00044     case 27:
00045       exit(0);
00046       break;
00047 
00048     case 'j': Bptr->center.x += delta; break; 
00049     case 'J': Bptr->center.x -= delta; break; 
00050     case 'k': Bptr->center.y += delta; break; 
00051     case 'K': Bptr->center.y -= delta; break; 
00052     case 'l': 
00053     {
00054       transrotate2D tr(delta); 
00055       tr.eval(Bptr->arm1);
00056       tr.eval(Bptr->arm2);
00057       break;
00058     }
00059     case 'L': 
00060     {
00061       transrotate2D tr(-delta); 
00062       tr.eval(Bptr->arm1);
00063       tr.eval(Bptr->arm2);
00064       break;
00065     }
00066 
00067     case 'a': Aptr->center.x += delta; break; 
00068     case 'A': Aptr->center.x -= delta; break; 
00069     case 's': Aptr->center.y += delta; break; 
00070     case 'S': Aptr->center.y -= delta; break; 
00071     case 'd': 
00072     {
00073       transrotate2D tr(delta); 
00074       tr.eval(Aptr->arm1);
00075       tr.eval(Aptr->arm2);
00076       break;
00077     }
00078     case 'D': 
00079     {
00080       transrotate2D tr(-delta); 
00081       tr.eval(Aptr->arm1);
00082       tr.eval(Aptr->arm2);
00083       break;
00084     }
00085 
00086     case 'p': 
00087       cout << (stringc)(*Aptr) << endl;
00088       cout << (stringc)(*Bptr) << endl;
00089       break;
00090 
00091     case '+': delta *= 10.0; if (delta==0.0) delta=0.1; break;
00092     case '-': delta /= 10.0; break;
00093 
00094     case 'h': if (help!=0) *help = !*help; break;
00095   }
00096 
00097   update01();
00098   glutPostRedisplay();
00099 }

void boxOBBhalfspaceD2test::test01 ( int &  argc,
char **  argv 
)

Load two OBBsepaxisD2 boxes and display.

Definition at line 187 of file boxOBBhalfspaceD2test.cpp.

References Aptr, boxes, Bptr, display01(), gobjpush, help, gobjSwitch< BOOL >::isdrawn, keyboard01(), commandline::mapvar(), gobjContainer::set(), zpr::update(), update01(), and xGraphics.

00188 {
00189   glutInit(&argc,argv);
00190   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00191   glutInitWindowSize(800,600);
00192   glutCreateWindow("");
00193   glutDisplayFunc(display01);
00194   glutKeyboardFunc(keyboard01);
00195 
00196   OpenGLinitialisation();
00197 
00198   glEnable(GL_DEPTH_TEST);
00199   glEnable(GL_CULL_FACE);
00200   glEnable(GL_NORMALIZE);
00201 
00202   zpr zz;
00203 
00204   xGraphics.set();
00205 
00206   commandline cmd(argc,argv);
00207 
00208   string in;
00209 
00210   cmd.mapvar(in,"in");
00211   if ( in.empty() )
00212   {
00213     cout << "error: in=filename expected" << endl;
00214     return;
00215   }
00216 
00217   ifstream filein(in.c_str());
00218   assert(filein.good()==true);
00219   if (filein.good()==false)
00220     return;
00221 
00222   typedef point2<double> pt2;
00223 
00224   pt2 center;
00225   pt2 arm1;
00226   pt2 arm2;
00227   double arm1len;
00228   double arm2len;
00229 
00230   filein >> center;
00231   filein >> arm1;
00232   filein >> arm2;
00233   filein >> arm1len;
00234   filein >> arm2len;
00235   boxOBBhalfspaceD2<point2<double>,double> 
00236     A(center,arm1,arm2,arm1len,arm2len);
00237 
00238   filein >> center;
00239   filein >> arm1;
00240   filein >> arm2;
00241   filein >> arm1len;
00242   filein >> arm2len;
00243   boxOBBhalfspaceD2<point2<double>,double> 
00244     B(center,arm1,arm2,arm1len,arm2len);
00245 
00246 
00247   Aptr = & A;
00248   Bptr = & B;
00249   gobjpush(&boxes);
00250 
00251   update01();
00252 
00253   menusystem * menu = 
00254     new menusystem(0,0,true,point2<GLint>(20,20),10);
00255 
00256   gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true);
00257   help = & menuswitch->isdrawn;
00258   gobjpush(menuswitch);
00259 
00260   menu->addfont12("OBB intersection test");
00261   menu->addnewline();
00262   menu->addnewline();
00263   menu->addfont10("j J   Move box B left or right.");
00264   menu->addnewline();
00265   menu->addfont10("k K   Move box B up or down.");
00266   menu->addnewline();
00267   menu->addfont10("l L   Rotate box B.");
00268   menu->addnewline();
00269 
00270   menu->addfont10("a A   Move box A left or right.");
00271   menu->addnewline();
00272   menu->addfont10("s S   Move box A up or down.");
00273   menu->addnewline();
00274   menu->addfont10("d D   Rotate box A.");
00275   menu->addnewline();
00276 
00277   menu->addnewline();
00278   menu->addfont10("p     Print boxes to terminal.");
00279   menu->addnewline();
00280   menu->addfont10("+ -   Increase or decrease change.");
00281   menu->addnewline();
00282   menu->addfont10("h    Toggle this help menu.");
00283   menu->addnewline();
00284   menu->addfont10("ESC   Quit");
00285 
00286 
00287   zz.update();
00288   glutMainLoop();
00289 }

int boxOBBhalfspaceD2test::unittest01 (  )  [static]

Test the boxOBBhalfspaceD2<PT,PD>::construct(.

..) function.

Definition at line 292 of file boxOBBhalfspaceD2test.cpp.

References assertreturnOS, boxOBBhalfspaceD2< PT, PD >::center, boxOBBhalfspaceD2< PT, PD >::construct(), and boxOBBhalfspaceD2< PT, PD >::cornerpoints().

Referenced by main().

00293 {
00294   typedef point2<double> pt2;
00295   pt2 pi[4] = 
00296   { 
00297     pt2(6.0,0.0), pt2(7.0,0.0), 
00298     pt2(7.0,3.0), pt2(6.0,3.0)
00299   };
00300 
00301   boxOBBhalfspaceD2<pt2,double> bx;
00302   bx.construct(pi[0],pi[1],pi[2],pi[3]);
00303 
00304   assertreturnOS( 
00305     zero<double>::test( (bx.center-pt2(6.5,1.5)).dot() ) );
00306 
00307   pt2 zi[4];
00308   bx.cornerpoints(zi[0],zi[1],zi[2],zi[3]);
00309 
00310   for (uint i=0; i<4; ++i)
00311     assertreturnOS( zero<double>::test( (pi[i]-zi[i]).dot() ) );
00312 
00313   return 0;
00314 }

int boxOBBhalfspaceD2test::unittest02 ( int &  argc,
char **  argv 
) [static]

Test if the point q is inside the box.

./main prog=13 p0=0.0,0.0 p1=1.0,0.0 p2=1.0,1.0 p3=0.0,1.0 q=.2,.3

Definition at line 316 of file boxOBBhalfspaceD2test.cpp.

References boxOBBhalfspaceD2< PT, PD >::construct(), boxOBBhalfspaceD2< PT, PD >::intersects(), commandline::mapvar(), and point2< T >::serializeInverseBrackets().

Referenced by main().

00317 {
00318   typedef point2<double> pt2;
00319 
00320   commandline cmd(argc,argv);
00321 
00322   string p[5];
00323   string pstr[5]={"p0","p1","p2","p3","q"};
00324 
00325   pt2 pi[5];
00326 
00327   bool inside(true);
00328   cmd.mapvar(inside,"inside");
00329 
00330   for (uint i=0; i<5; ++i)
00331   {
00332     cmd.mapvar(p[i],pstr[i]);
00333     if ( p[i].empty() )
00334       return 1;
00335 
00336     pi[i].serializeInverseBrackets(p[i]);
00337 
00338     cout << "pi[" << i << "]=" << pi[i] << endl;
00339   }
00340 
00341   boxOBBhalfspaceD2<pt2,double> bx;
00342   bx.construct(pi[0],pi[1],pi[2],pi[3]);
00343   
00344   if (inside)
00345   {
00346     if (bx.intersects(pi[4])==false)
00347       return 1;
00348 
00349     return 0;
00350   }
00351 
00352   if (bx.intersects(pi[4])==true)
00353     return 1;
00354 
00355   return 0;
00356 }

void boxOBBhalfspaceD2test::update01 (  )  [static]

Update for test01 before graphics display.

Definition at line 101 of file boxOBBhalfspaceD2test.cpp.

References Aptr, boxes, Bptr, boxOBBhalfspaceD2< PT, PD >::center, boxOBBhalfspaceD2< PT, PD >::cornerpoints(), pointsdisplay2D< T >::gq, boxOBBhalfspaceD2< PT, PD >::intersects(), gobjContainer::nuke(), pts, gobjContainer::push(), boxOBBhalfspaceD2< PT, PD >::qi, and gobjQuadric::radius.

Referenced by keyboard01(), and test01().

00102 {
00103   assert(Aptr!=0);
00104   assert(Bptr!=0);
00105 
00106   bool intersection = (Aptr->intersects(*Bptr));
00107 
00108   vector< point2<double> > pts(4);
00109   Aptr->cornerpoints(pts[0],pts[1],pts[2],pts[3]);
00110 
00111   boxes.nuke();
00112 
00113   boxes.push(new gobjglColor3ub(184,134,11));
00114 
00115   vector<point2<double> > v(&Aptr->qi[0],&Aptr->qi[0]+4);
00116   pointsdisplay2D<point2<double> > qidp(boxes,v,true,true,false);
00117   qidp.gq->radius=0.01;
00118 
00119   boxes.push(new gobjglBegin(GL_LINES));
00120   boxes.push(new gobjglVertex2f(pts[0]));
00121   boxes.push(new gobjglVertex2f(pts[1]));
00122   boxes.push(new gobjglVertex2f(pts[1]));
00123   boxes.push(new gobjglVertex2f(pts[2]));
00124   boxes.push(new gobjglVertex2f(pts[2]));
00125   boxes.push(new gobjglVertex2f(pts[3]));
00126   boxes.push(new gobjglVertex2f(pts[3]));
00127   boxes.push(new gobjglVertex2f(pts[0]));
00128 
00129   Bptr->cornerpoints(pts[0],pts[1],pts[2],pts[3]);
00130 
00131   boxes.push(new gobjglColor3ub(0,191,255));
00132 
00133 
00134 
00135   boxes.push(new gobjglVertex2f(pts[0]));
00136   boxes.push(new gobjglVertex2f(pts[1]));
00137   boxes.push(new gobjglVertex2f(pts[1]));
00138   boxes.push(new gobjglVertex2f(pts[2]));
00139   boxes.push(new gobjglVertex2f(pts[2]));
00140   boxes.push(new gobjglVertex2f(pts[3]));
00141   boxes.push(new gobjglVertex2f(pts[3]));
00142   boxes.push(new gobjglVertex2f(pts[0]));
00143 
00144   boxes.push(new gobjglColor3ub(255,0,255));
00145   boxes.push(new gobjglVertex2f(Aptr->center));
00146   boxes.push(new gobjglVertex2f(Bptr->center));
00147 
00148   boxes.push(new gobjglEnd());
00149 
00150   boxes.push(new gobjglColor3ub(0,191,255));
00151   pointsdisplay2D<point2<double> > pidp(boxes,pts,true,true,false);
00152   pidp.gq->radius=0.01;
00153 
00154   if (intersection)
00155   {
00156     double transparency=0.4;
00157     Aptr->cornerpoints(pts[0],pts[1],pts[2],pts[3]);
00158     //boxes.push(new gobjglColor3ub(255,0,0));
00159 
00160     boxes.push(new gobjglEnable(GL_BLEND));
00161     boxes.push(
00162       new gobjglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) );
00163     boxes.push(
00164       new gobjglColor4f(1.0,0.0,0.0,transparency));
00165 
00166     boxes.push(new gobjglBegin(GL_TRIANGLES));
00167     boxes.push(new gobjglVertex2f(pts[0]));
00168     boxes.push(new gobjglVertex2f(pts[1]));
00169     boxes.push(new gobjglVertex2f(pts[2]));
00170     boxes.push(new gobjglVertex2f(pts[2]));
00171     boxes.push(new gobjglVertex2f(pts[3]));
00172     boxes.push(new gobjglVertex2f(pts[0]));
00173 
00174     Bptr->cornerpoints(pts[0],pts[1],pts[2],pts[3]);
00175     boxes.push(new gobjglVertex2f(pts[0]));
00176     boxes.push(new gobjglVertex2f(pts[1]));
00177     boxes.push(new gobjglVertex2f(pts[2]));
00178     boxes.push(new gobjglVertex2f(pts[2]));
00179     boxes.push(new gobjglVertex2f(pts[3]));
00180     boxes.push(new gobjglVertex2f(pts[0]));
00181     boxes.push(new gobjglEnd());
00182 
00183     boxes.push(new gobjglDisable(GL_BLEND));
00184   }
00185 }


Member Data Documentation

boxOBBhalfspaceD2< point2< double >, double > * boxOBBhalfspaceD2test::Aptr [static]

OBB object A.

Definition at line 18 of file boxOBBhalfspaceD2test.h.

Referenced by keyboard01(), test01(), and update01().

Graphics to display the boxes.

Definition at line 26 of file boxOBBhalfspaceD2test.h.

Referenced by test01(), and update01().

boxOBBhalfspaceD2< point2< double >, double > * boxOBBhalfspaceD2test::Bptr [static]

OBB object B.

Definition at line 20 of file boxOBBhalfspaceD2test.h.

Referenced by keyboard01(), test01(), and update01().

Toggle the help menu.

Definition at line 23 of file boxOBBhalfspaceD2test.h.

Referenced by keyboard01(), and test01().

Global graphics container.

Definition at line 29 of file boxOBBhalfspaceD2test.h.

Referenced by test01().


The documentation for this class was generated from the following files:

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