Files Classes Functions Hierarchy
00001 #include <cassert> 00002 #include <fstream> 00003 #include <iostream> 00004 using namespace std; 00005 00006 #include <circleD2.h> 00007 #include <circleD2test.h> 00008 #include <commandline.h> 00009 #include <gobj.h> 00010 #include <graphmisc.h> 00011 #include <menusystem.h> 00012 #include <zpr.h> 00013 00014 00015 circleD2<point2<double>,double> * circleD2test::Aptr; 00016 boxOBBhalfspaceD2<point2<double>,double> * circleD2test::Bptr; 00017 bool * circleD2test::help = 0; 00018 00019 00020 gobjContainer circleD2test::shapes(true); 00021 00022 00023 void circleD2test::keyboard01(unsigned char key, int x, int y) 00024 { 00025 static double delta = 0.1; 00026 00027 assert(Aptr!=0); 00028 assert(Bptr!=0); 00029 00030 switch (key) 00031 { 00032 case 27: 00033 exit(0); 00034 break; 00035 00036 case 'j': Bptr->center.x += delta; break; 00037 case 'J': Bptr->center.x -= delta; break; 00038 case 'k': Bptr->center.y += delta; break; 00039 case 'K': Bptr->center.y -= delta; break; 00040 case 'l': 00041 { 00042 transrotate2D tr(delta); 00043 tr.eval(Bptr->arm1); 00044 tr.eval(Bptr->arm2); 00045 break; 00046 } 00047 00048 case 'a': Aptr->center.x += delta; break; 00049 case 'A': Aptr->center.x -= delta; break; 00050 case 's': Aptr->center.y += delta; break; 00051 case 'S': Aptr->center.y -= delta; break; 00052 00053 case '+': delta *= 10.0; if (delta==0.0) delta=0.1; break; 00054 case '-': delta /= 10.0; break; 00055 00056 case 'h': if (help!=0) *help = !*help; break; 00057 } 00058 00059 update01(); 00060 glutPostRedisplay(); 00061 } 00062 00063 00064 void circleD2test::display01() 00065 { 00066 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00067 00068 gobj::global->draw(); 00069 00070 glerrordisplay(); 00071 00072 glutSwapBuffers(); 00073 } 00074 00075 void circleD2test::test01(int & argc, char** argv) 00076 { 00077 glutInit(&argc,argv); 00078 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00079 glutInitWindowSize(800,600); 00080 glutCreateWindow(""); 00081 glutDisplayFunc(display01); 00082 glutKeyboardFunc(keyboard01); 00083 00084 OpenGLinitialisation(); 00085 00086 glEnable(GL_DEPTH_TEST); 00087 glEnable(GL_CULL_FACE); 00088 glEnable(GL_NORMALIZE); 00089 00090 zpr zz; 00091 00092 xGraphics.set(); 00093 00094 commandline cmd(argc,argv); 00095 00096 string in; 00097 00098 cmd.mapvar(in,"in"); 00099 if ( in.empty() ) 00100 { 00101 cout << "error: in=filename expected" << endl; 00102 return; 00103 } 00104 00105 ifstream filein(in.c_str()); 00106 assert(filein.good()==true); 00107 if (filein.good()==false) 00108 return; 00109 00110 typedef point2<double> pt2; 00111 00112 pt2 center; 00113 pt2 arm1; 00114 pt2 arm2; 00115 double arm1len; 00116 double arm2len; 00117 00118 filein >> center; 00119 filein >> arm1len; 00120 circleD2<pt2,double> A(center,arm1len); 00121 00122 filein >> center; 00123 filein >> arm1; 00124 filein >> arm2; 00125 filein >> arm1len; 00126 filein >> arm2len; 00127 boxOBBhalfspaceD2<pt2,double> 00128 B(center,arm1,arm2,arm1len,arm2len); 00129 00130 Aptr = & A; 00131 Bptr = & B; 00132 gobjpush(&shapes); 00133 00134 update01(); 00135 00136 menusystem * menu = 00137 new menusystem(0,0,true,point2<GLint>(60,30),10); 00138 00139 gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true); 00140 help = & menuswitch->isdrawn; 00141 gobjpush(menuswitch); 00142 00143 menu->addfont12("Circle and Box Intersection"); 00144 menu->addnewline(); 00145 menu->addnewline(); 00146 menu->addfont10("j J Move box B left or right."); 00147 menu->addnewline(); 00148 menu->addfont10("k K Move box B up or down."); 00149 menu->addnewline(); 00150 menu->addfont10("l L Rotate box B."); 00151 menu->addnewline(); 00152 00153 menu->addfont10("a A Move box A left or right."); 00154 menu->addnewline(); 00155 menu->addfont10("s S Move box A up or down."); 00156 menu->addnewline(); 00157 00158 menu->addnewline(); 00159 menu->addfont10("+ - Increase or decrease change."); 00160 menu->addnewline(); 00161 menu->addfont10("h Toggle this help menu."); 00162 menu->addnewline(); 00163 menu->addfont10("ESC Quit"); 00164 00165 zz.update(); 00166 glutMainLoop(); 00167 } 00168 00169 void circleD2test::update01() 00170 { 00171 assert(Aptr!=0); 00172 assert(Bptr!=0); 00173 00174 vector< point2<double> > pts(4); 00175 00176 shapes.nuke(); 00177 00178 shapes.push(new gobjglColor3ub(184,134,11)); 00179 00180 typedef point3<double> pt3; 00181 00182 gobjMyCircle * cir = new gobjMyCircle(); 00183 shapes.push(cir); 00184 shapes.push 00185 ( 00186 new gobjMyCircleDraw 00187 ( 00188 Aptr->radius, 00189 pt3(Aptr->center.x,Aptr->center.y,0.0), 00190 *cir 00191 ) 00192 ); 00193 00194 Bptr->cornerpoints(pts[0],pts[1],pts[2],pts[3]); 00195 00196 shapes.push(new gobjglBegin(GL_LINES)); 00197 00198 shapes.push(new gobjglColor3ub(0,191,255)); 00199 00200 shapes.push(new gobjglVertex2f(pts[0])); 00201 shapes.push(new gobjglVertex2f(pts[1])); 00202 shapes.push(new gobjglVertex2f(pts[1])); 00203 shapes.push(new gobjglVertex2f(pts[2])); 00204 shapes.push(new gobjglVertex2f(pts[2])); 00205 shapes.push(new gobjglVertex2f(pts[3])); 00206 shapes.push(new gobjglVertex2f(pts[3])); 00207 shapes.push(new gobjglVertex2f(pts[0])); 00208 00209 shapes.push(new gobjglColor3ub(255,0,255)); 00210 shapes.push(new gobjglVertex2f(Aptr->center)); 00211 shapes.push(new gobjglVertex2f(Bptr->center)); 00212 00213 shapes.push(new gobjglEnd()); 00214 00215 static GLUquadricObj * qobj = gluNewQuadric(); 00216 00217 bool intersection = (Aptr->intersects(*Bptr)); 00218 if (intersection) 00219 { 00220 double transparency=0.4; 00221 00222 shapes.push(new gobjglEnable(GL_BLEND)); 00223 shapes.push( 00224 new gobjglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) ); 00225 shapes.push( 00226 new gobjglColor4f(1.0,0.0,0.0,transparency)); 00227 00228 shapes.push(new gobjglBegin(GL_TRIANGLES)); 00229 00230 Bptr->cornerpoints(pts[0],pts[1],pts[2],pts[3]); 00231 shapes.push(new gobjglVertex2f(pts[0])); 00232 shapes.push(new gobjglVertex2f(pts[1])); 00233 shapes.push(new gobjglVertex2f(pts[2])); 00234 shapes.push(new gobjglVertex2f(pts[2])); 00235 shapes.push(new gobjglVertex2f(pts[3])); 00236 shapes.push(new gobjglVertex2f(pts[0])); 00237 shapes.push(new gobjglEnd()); 00238 00239 shapes.push(new gobjglPushMatrix()); 00240 shapes.push(new gobjglTranslatef(Aptr->center.x,Aptr->center.y,0.0)); 00241 00242 shapes.push( new gobjgluDisk(qobj, 0.0, Aptr->radius, 30, 1) ); 00243 shapes.push(new gobjglPopMatrix()); 00244 00245 shapes.push(new gobjglDisable(GL_BLEND)); 00246 } 00247 } 00248 00249
1.5.8