Files Classes Functions Hierarchy
00001 #include <cassert> 00002 #include <fstream> 00003 #include <iostream> 00004 using namespace std; 00005 00006 #include <angles.h> 00007 #include <commandline.h> 00008 #include <cylinder.h> 00009 #include <disk.h> 00010 #include <diskinttest.h> 00011 #include <gobj.h> 00012 #include <graphmisc.h> 00013 #include <line.h> 00014 #include <menusystem.h> 00015 #include <point.h> 00016 #include <planepointsurface.h> 00017 #include <pointsurface.h> 00018 #include <zpr.h> 00019 00020 cylinder * diskinttest::C1ptr; 00021 cylinder * diskinttest::C2ptr; 00022 disk * diskinttest::D1ptr; 00023 disk * diskinttest::D2ptr; 00024 plane * diskinttest::P1ptr; 00025 gobjMyCircleDraw * diskinttest::D1cd; 00026 gobjMyCircleDraw * diskinttest::D2cd; 00027 gobjContainer * diskinttest::diskintersection; 00028 gobjgluCylinder * diskinttest::C1cd; 00029 gobjgluCylinder * diskinttest::C2cd; 00030 gobjContainer * diskinttest::cylinderintersection; 00031 float diskinttest::transparency = 0.6; 00032 bool * diskinttest::help = 0; 00033 bool diskinttest::cylinderscollide = false; 00034 00035 00036 00037 void diskinttest::display01() 00038 { 00039 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00040 00041 gobj::global->draw(); 00042 00043 glerrordisplay(); 00044 00045 glutSwapBuffers(); 00046 } 00047 00048 void diskinttest::keyboard01(unsigned char key, int x, int y) 00049 { 00050 static double delta = 0.1; 00051 static bool mode=true; 00052 00053 switch (key) 00054 { 00055 case 27: 00056 exit(0); 00057 break; 00058 case 'j': 00059 if (mode) 00060 D1ptr->pos.x += delta; 00061 else 00062 D1ptr->nml.x += delta; 00063 break; 00064 case 'J': 00065 if (mode) 00066 D1ptr->pos.x -= delta; 00067 else 00068 D1ptr->nml.x -= delta; 00069 break; 00070 00071 case 'k': 00072 if (mode) 00073 D1ptr->pos.y += delta; 00074 else 00075 D1ptr->nml.y += delta; 00076 break; 00077 case 'K': 00078 if (mode) 00079 D1ptr->pos.y -= delta; 00080 else 00081 D1ptr->nml.y -= delta; 00082 00083 break; 00084 00085 case 'l': 00086 if (mode) 00087 D1ptr->pos.z += delta; 00088 else 00089 D1ptr->nml.z += delta; 00090 break; 00091 case 'L': 00092 if (mode) 00093 D1ptr->pos.z -= delta; 00094 else 00095 D1ptr->nml.z -= delta; 00096 break; 00097 00098 case '+': delta *= 10.0; if (delta==0.0) delta=0.1; break; 00099 case '-': delta /= 10.0; break; 00100 00101 case 'm': mode = !mode; break; 00102 00103 case 'p': 00104 cout << (stringc)*D1ptr << endl; 00105 break; 00106 } 00107 00108 update01(); 00109 glutPostRedisplay(); 00110 } 00111 00112 void diskinttest::test01(int & argc, char** argv) 00113 { 00114 glutInit(&argc,argv); 00115 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00116 glutInitWindowSize(800,600); 00117 glutCreateWindow(""); 00118 glutDisplayFunc(display01); 00119 glutKeyboardFunc(keyboard01); 00120 00121 OpenGLinitialisation(); 00122 00123 glEnable(GL_DEPTH_TEST); 00124 glEnable(GL_CULL_FACE); 00125 glEnable(GL_NORMALIZE); 00126 00127 zpr zz; 00128 00129 xGraphics.set(); 00130 00131 commandline cmd(argc,argv); 00132 00133 string in; 00134 00135 cmd.mapvar(in,"in"); 00136 if ( in.empty() ) 00137 { 00138 cout << "error: in=filename expected" << endl; 00139 return; 00140 } 00141 00142 ifstream filein(in.c_str()); 00143 assert(filein.good()==true); 00144 if (filein.good()==false) 00145 return; 00146 00147 point3<double> nml; 00148 point3<double> pos; 00149 double radius; 00150 double d; 00151 00152 filein >> nml.x; 00153 filein >> nml.y; 00154 filein >> nml.z; 00155 filein >> pos.x; 00156 filein >> pos.y; 00157 filein >> pos.z; 00158 filein >> radius; 00159 00160 disk D1(nml,pos,radius); 00161 D1ptr = & D1; 00162 00163 00164 cout << "disk: " << (stringc)D1 << endl; 00165 00166 filein >> nml.x; 00167 filein >> nml.y; 00168 filein >> nml.z; 00169 filein >> d; 00170 00171 plane P1(nml,d); 00172 P1ptr = &P1; 00173 00174 cout << "plane: " << (stringc)P1 << endl; 00175 00176 planepointsurface f1(P1); 00177 pointsurface<> ps1(6000); 00178 ps1.pre.push(new gobjglColor3ub(184,134,11) ); 00179 ps1.addsurface2D(f1); 00180 gobjpush(&ps1); 00181 00182 gobjpush(new gobjglColor3ub(255,255,0)); 00183 gobjMyCircle * cir = new gobjMyCircle(); 00184 gobjMyCircleDraw * cird = 00185 new gobjMyCircleDraw(D1.radius,D1.pos,D1.nml,*cir); 00186 gobjpush(cir); 00187 gobjpush(cird); 00188 00189 D1cd = cird; 00190 00191 diskintersection = new gobjContainer(true); 00192 gobjpush(diskintersection); 00193 00194 update01(); 00195 00196 menusystem * menu = 00197 new menusystem(0,0,true,point2<GLint>(60,30),20); 00198 gobjpush(menu); 00199 00200 menu->addfont12("Disk and Plane Intersection"); 00201 menu->addnewline(); 00202 menu->addnewline(); 00203 menu->addfont10("'j' 'J' x position/normal"); 00204 menu->addnewline(); 00205 menu->addfont10("'k' 'K' y position/normal"); 00206 menu->addnewline(); 00207 menu->addfont10("'l' 'L' z position/normal"); 00208 menu->addnewline(); 00209 menu->addfont10("'m' Toggle position/normal mode"); 00210 menu->addnewline(); 00211 menu->addfont10("'p' Print the disk and plane to terminal."); 00212 menu->addnewline(); 00213 menu->addnewline(); 00214 menu->addfont10("ESC Quit"); 00215 00216 zz.update(); 00217 glutMainLoop(); 00218 } 00219 00220 00221 void diskinttest::update01() 00222 { 00223 assert(D1ptr!=0); 00224 assert(P1ptr!=0); 00225 00226 D1ptr->nml.normalize(); 00227 D1cd->center = D1ptr->pos; 00228 D1cd->axis = D1ptr->nml; 00229 00230 point3<double> p0; 00231 point3<double> p1; 00232 00233 diskintersection->nuke(); 00234 if (D1ptr->intersects(p0,p1,*P1ptr)) 00235 { 00236 diskintersection->push(new gobjglPushAttrib(GL_LIGHTING)); 00237 diskintersection->push(new gobjglPushAttrib(GL_CURRENT_BIT)); 00238 diskintersection->push(new gobjglDisable(GL_LIGHTING)); 00239 diskintersection->push(new gobjglColor3ub(255,0,0)); 00240 00241 diskintersection->push(new gobjglBegin(GL_LINES)); 00242 diskintersection->push(new gobjglVertex3d(p0)); 00243 diskintersection->push(new gobjglVertex3d(p1)); 00244 diskintersection->push(new gobjglEnd()); 00245 00246 diskintersection->push(new gobjglPopAttrib()); 00247 diskintersection->push(new gobjglPopAttrib()); 00248 } 00249 00250 00251 } 00252 00253 void diskinttest::keyboard02(unsigned char key, int x, int y) 00254 { 00255 static double delta = 0.1; 00256 static bool mode=true; 00257 00258 switch (key) 00259 { 00260 case 27: 00261 exit(0); 00262 break; 00263 00264 case 'j': 00265 if (mode) 00266 D2ptr->pos.x += delta; 00267 else 00268 D2ptr->nml.x += delta; 00269 break; 00270 case 'J': 00271 if (mode) 00272 D2ptr->pos.x -= delta; 00273 else 00274 D2ptr->nml.x -= delta; 00275 break; 00276 00277 case 'k': 00278 if (mode) 00279 D2ptr->pos.y += delta; 00280 else 00281 D2ptr->nml.y += delta; 00282 break; 00283 case 'K': 00284 if (mode) 00285 D2ptr->pos.y -= delta; 00286 else 00287 D2ptr->nml.y -= delta; 00288 break; 00289 00290 case 'l': 00291 if (mode) 00292 D2ptr->pos.z += delta; 00293 else 00294 D2ptr->nml.z += delta; 00295 break; 00296 case 'L': 00297 if (mode) 00298 D2ptr->pos.z -= delta; 00299 else 00300 D2ptr->nml.z -= delta; 00301 break; 00302 00303 case '+': delta *= 10.0; if (delta==0.0) delta=0.1; break; 00304 case '-': delta /= 10.0; break; 00305 00306 case 'm': mode = !mode; break; 00307 00308 case 'p': 00309 cout << (stringc)*D1ptr << endl; 00310 cout << (stringc)*D2ptr << endl; 00311 break; 00312 00313 case 'x': D2ptr->radius += delta; break; 00314 case 'X': D2ptr->radius -= delta; break; 00315 00316 case 'h': if (help!=0) *help = !*help; break; 00317 00318 00319 } 00320 update02(); 00321 glutPostRedisplay(); 00322 } 00323 00324 00325 void diskinttest::test02(int & argc, char** argv) 00326 { 00327 glutInit(&argc,argv); 00328 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00329 glutInitWindowSize(800,600); 00330 glutCreateWindow(""); 00331 glutDisplayFunc(display01); 00332 glutKeyboardFunc(keyboard02); 00333 00334 OpenGLinitialisation(); 00335 00336 glEnable(GL_DEPTH_TEST); 00337 glEnable(GL_CULL_FACE); 00338 glEnable(GL_NORMALIZE); 00339 00340 zpr zz; 00341 00342 xGraphics.set(); 00343 00344 commandline cmd(argc,argv); 00345 00346 string in; 00347 00348 cmd.mapvar(in,"in"); 00349 if ( in.empty() ) 00350 { 00351 cout << "error: in=filename expected" << endl; 00352 return; 00353 } 00354 00355 ifstream filein(in.c_str()); 00356 assert(filein.good()==true); 00357 if (filein.good()==false) 00358 return; 00359 00360 point3<double> nml; 00361 point3<double> pos; 00362 double radius; 00363 00364 filein >> nml.x; 00365 filein >> nml.y; 00366 filein >> nml.z; 00367 filein >> pos.x; 00368 filein >> pos.y; 00369 filein >> pos.z; 00370 filein >> radius; 00371 00372 nml.normalize(); 00373 disk D1(nml,pos,radius); 00374 00375 filein >> nml.x; 00376 filein >> nml.y; 00377 filein >> nml.z; 00378 filein >> pos.x; 00379 filein >> pos.y; 00380 filein >> pos.z; 00381 filein >> radius; 00382 00383 nml.normalize(); 00384 disk D2(nml,pos,radius); 00385 00386 //gobjpush(new myaxes(1.0)); 00387 00388 gobjpush(new gobjglColor3ub(255,255,0)); 00389 gobjMyCircle * cir = new gobjMyCircle(); 00390 gobjMyCircleDraw * cird = 00391 new gobjMyCircleDraw(D1.radius,D1.pos,D1.nml,*cir); 00392 gobjpush(cir); 00393 gobjpush(cird); 00394 00395 D1ptr = &D1; 00396 D1cd = cird; 00397 00398 gobjpush(new gobjglColor3ub(153,50,204)); 00399 cird = new gobjMyCircleDraw(D2.radius,D2.pos,D2.nml,*cir); 00400 gobjpush(cird); 00401 00402 D2ptr = &D2; 00403 D2cd = cird; 00404 00405 diskintersection = new gobjContainer(true); 00406 gobjpush(diskintersection); 00407 00408 00409 menusystem * menu = 00410 new menusystem(0,0,true,point2<GLint>(60,30),20); 00411 00412 gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true); 00413 help = & menuswitch->isdrawn; 00414 gobjpush(menuswitch); 00415 00416 menu->addfont12("Disk and Disk Intersection"); 00417 menu->addnewline(); 00418 menu->addnewline(); 00419 menu->addfont10("'j' 'J' x position/normal"); 00420 menu->addnewline(); 00421 menu->addfont10("'k' 'K' y position/normal"); 00422 menu->addnewline(); 00423 menu->addfont10("'l' 'L' z position/normal"); 00424 menu->addnewline(); 00425 menu->addfont10("'m' Toggle position/normal mode"); 00426 menu->addnewline(); 00427 menu->addfont10("'p' Print the two disks to terminal."); 00428 menu->addnewline(); 00429 menu->addfont10("'x' 'X' Vary disk 2's radius."); 00430 menu->addnewline(); 00431 menu->addfont10("'h' Toggle this help menu."); 00432 menu->addnewline(); 00433 menu->addnewline(); 00434 menu->addfont10("ESC Quit"); 00435 00436 00437 update02(); 00438 00439 zz.update(); 00440 glutMainLoop(); 00441 } 00442 00443 void diskinttest::update02() 00444 { 00445 assert(D1ptr!=0); 00446 assert(D2ptr!=0); 00447 00448 D1ptr->nml.normalize(); 00449 D2ptr->nml.normalize(); 00450 00451 point3<double> p0; 00452 point3<double> p1; 00453 diskintersection->nuke(); 00454 if (D1ptr->intersects(p0,p1,*D2ptr)) 00455 { 00456 diskintersection->push(new gobjglPushAttrib(GL_LIGHTING)); 00457 diskintersection->push(new gobjglPushAttrib(GL_CURRENT_BIT)); 00458 diskintersection->push(new gobjglDisable(GL_LIGHTING)); 00459 diskintersection->push(new gobjglColor3ub(255,0,0)); 00460 00461 diskintersection->push(new gobjglBegin(GL_LINES)); 00462 diskintersection->push(new gobjglVertex3d(p0)); 00463 diskintersection->push(new gobjglVertex3d(p1)); 00464 diskintersection->push(new gobjglEnd()); 00465 00466 diskintersection->push(new gobjglPopAttrib()); 00467 diskintersection->push(new gobjglPopAttrib()); 00468 } 00469 00470 00471 D1cd->axis = D1ptr->nml; 00472 D2cd->axis = D2ptr->nml; 00473 D1cd->center = D1ptr->pos; 00474 D2cd->center = D2ptr->pos; 00475 D2cd->radiusset(D2ptr->radius); 00476 00477 } 00478 00479 void diskinttest::keyboard03(unsigned char key, int x, int y) 00480 { 00481 static double delta = 0.1; 00482 static bool mode=true; 00483 00484 switch (key) 00485 { 00486 case 27: 00487 exit(0); 00488 break; 00489 00490 case 't': 00491 transparency += delta; 00492 unitbound(transparency); 00493 break; 00494 case 'T': 00495 transparency -= delta; 00496 unitbound(transparency); 00497 break; 00498 00499 case 'j': 00500 if (mode) 00501 C1ptr->pos.x += delta; 00502 else 00503 C1ptr->nml.x += delta; 00504 break; 00505 case 'J': 00506 if (mode) 00507 C1ptr->pos.x -= delta; 00508 else 00509 C1ptr->nml.x -= delta; 00510 break; 00511 case 'k': 00512 if (mode) 00513 C1ptr->pos.y += delta; 00514 else 00515 C1ptr->nml.y += delta; 00516 break; 00517 case 'K': 00518 if (mode) 00519 C1ptr->pos.y -= delta; 00520 else 00521 C1ptr->nml.y -= delta; 00522 break; 00523 case 'l': 00524 if (mode) 00525 C1ptr->pos.z += delta; 00526 else 00527 C1ptr->nml.z += delta; 00528 break; 00529 case 'L': 00530 if (mode) 00531 C1ptr->pos.z -= delta; 00532 else 00533 C1ptr->nml.z -= delta; 00534 break; 00535 00536 case '+': delta *= 10.0; if (delta==0.0) delta=0.1; break; 00537 case '-': delta /= 10.0; break; 00538 00539 case 'm': mode = !mode; break; 00540 00541 case 'p': 00542 cout << (stringc)*C1ptr << endl; 00543 cout << (stringc)*C2ptr << endl; 00544 break; 00545 00546 case 'x': C1ptr->radius += delta; break; 00547 case 'X': C1ptr->radius -= delta; break; 00548 00549 case 'h': if (help!=0) *help = !*help; break; 00550 } 00551 00552 update03(); 00553 glutPostRedisplay(); 00554 } 00555 00556 00557 void diskinttest::update03lineline() 00558 { 00559 if (C1ptr==0) 00560 return; 00561 if (C2ptr==0) 00562 return; 00563 if (D1cd==0) 00564 return; 00565 if (D2cd==0) 00566 return; 00567 00568 if (zero<double>::test(C1ptr->height)) 00569 return; 00570 if (zero<double>::test(C2ptr->height)) 00571 return; 00572 00573 00574 00575 00576 typedef point3<double> pt3; 00577 line<pt3,double> L1(C1ptr->nml,C1ptr->pos); 00578 L1.normalize(C1ptr->height); 00579 line<pt3,double> L2(C2ptr->nml,C2ptr->pos); 00580 L2.normalize(C2ptr->height); 00581 00582 double t1; 00583 double t2; 00584 bool res; 00585 res = L1.lineD3minimized(t1,t2,L2); 00586 00587 if (res==false) 00588 return; 00589 00590 unitbound(t1); 00591 unitbound(t2); 00592 00593 disk D1(L1.nml,L1(t1),C1ptr->radius); 00594 disk D2(L2.nml,L2(t2),C2ptr->radius); 00595 00596 D1cd->center = D1.pos; 00597 D1cd->axis = D1.nml; 00598 D1cd->radiusset(D1.radius); 00599 D2cd->center = D2.pos; 00600 D2cd->axis = D2.nml; 00601 D2cd->radiusset(D2.radius); 00602 00603 00604 // Infinite cylinders intersection case only. 00605 point3<double> p0; 00606 point3<double> p1; 00607 cylinderscollide = D1.intersects(p0,p1,D2); 00608 00609 00610 cylinderintersection->push(new gobjglPushAttrib(GL_LIGHTING)); 00611 cylinderintersection->push(new gobjglPushAttrib(GL_CURRENT_BIT)); 00612 00613 cylinderintersection->push(new gobjglDisable(GL_LIGHTING) ); 00614 00615 cylinderintersection->push(new gobjglBegin(GL_LINES)); 00616 00617 // Write the minimal line. 00618 //cylinderintersection->push( 00619 // new gobjglColor4ub(127,255,212,(GLubyte)(floor(transparency*256)))); 00620 cylinderintersection->push( new gobjglColor3ub(127,255,212)); 00621 cylinderintersection->push(new gobjglVertex3d(L1(t1))); 00622 cylinderintersection->push(new gobjglVertex3d(L2(t2))); 00623 00624 00625 // Write cylinder1's axis. 00626 //cylinderintersection->push( 00627 // new gobjglColor4ub(255,20,147,(GLubyte)(floor(transparency*256)))); 00628 cylinderintersection->push( new gobjglColor3ub(255,20,147)); 00629 cylinderintersection->push(new gobjglVertex3d(L1(0.0))); 00630 cylinderintersection->push(new gobjglVertex3d(L1(1.0))); 00631 00632 // Write cylinder2's axis. 00633 //cylinderintersection->push( 00634 // new gobjglColor4ub(255,140,0,(GLubyte)(floor(transparency*256)))); 00635 cylinderintersection->push( new gobjglColor3ub(255,140,0)); 00636 cylinderintersection->push(new gobjglVertex3d(L2(0.0))); 00637 cylinderintersection->push(new gobjglVertex3d(L2(1.0))); 00638 00639 cylinderintersection->push(new gobjglEnd()); 00640 00641 cylinderintersection->push(new gobjglPopAttrib()); 00642 cylinderintersection->push(new gobjglPopAttrib()); 00643 00644 00645 00646 00647 00648 00649 00650 } 00651 00652 00653 void diskinttest::update03() 00654 { 00655 assert(C1ptr!=0); 00656 assert(C1cd!=0); 00657 assert(C2ptr!=0); 00658 assert(C2cd!=0); 00659 assert(cylinderintersection!=0); 00660 00661 00662 00663 C1cd->baseRadius = C1ptr->radius; 00664 C1cd->topRadius = C1ptr->radius; 00665 C1cd->height = C1ptr->height; 00666 00667 C2cd->baseRadius = C2ptr->radius; 00668 C2cd->topRadius = C2ptr->radius; 00669 C2cd->height = C2ptr->height; 00670 00671 static uint c1=0; 00672 static uint c2=0; 00673 00674 if (c1!=0) 00675 cylinderintersection->kill(c1); 00676 if (c2!=0) 00677 cylinderintersection->kill(c2); 00678 00679 cylinderintersection->nuke(); 00680 00681 update03lineline(); 00682 00683 cylinderintersection->push(new gobjglEnable(GL_BLEND)); 00684 cylinderintersection->push( 00685 new gobjglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) ); 00686 00687 00688 cylinderintersection->push(new gobjglPushMatrix()); 00689 00690 cylinderintersection->push(new gobjglTranslated(C1ptr->pos)); 00691 00692 double th1; 00693 point3<double> axis; 00694 00695 angles::rotateaboutaxis(th1,axis,C1ptr->nml); 00696 00697 th1 *= angles::radtodeg; 00698 cylinderintersection->push(new gobjglRotated(th1,axis.x,axis.y,axis.z)); 00699 00700 cylinderintersection->push(new myaxes(1.0)); 00701 if (cylinderscollide==false) 00702 cylinderintersection->push( 00703 new gobjglColor4f(0.0,0.0,1.0,transparency)); 00704 else 00705 cylinderintersection->push( 00706 new gobjglColor4f(1.0,0.0,0.0,transparency)); 00707 00708 cylinderintersection->push(C1cd); 00709 c1 = cylinderintersection->vg.size()-1; 00710 00711 cylinderintersection->push(new gobjglPopMatrix()); 00712 00713 00714 cylinderintersection->push(new gobjglPushMatrix()); 00715 00716 cylinderintersection->push(new gobjglTranslated(C2ptr->pos)); 00717 angles::rotateaboutaxis(th1,axis,C2ptr->nml); 00718 th1 *= angles::radtodeg; 00719 cylinderintersection->push(new gobjglRotated(th1,axis.x,axis.y,axis.z)); 00720 00721 cylinderintersection->push(new myaxes(1.0)); 00722 00723 if (cylinderscollide==false) 00724 cylinderintersection->push( 00725 new gobjglColor4f(0.0,1.0,1.0,transparency)); 00726 else 00727 cylinderintersection->push( 00728 new gobjglColor4f(1.0,0.0,0.0,transparency)); 00729 00730 cylinderintersection->push(C2cd); 00731 c2 = cylinderintersection->vg.size()-1; 00732 00733 cylinderintersection->push(new gobjglPopMatrix()); 00734 00735 00736 00737 cylinderintersection->push(new gobjglDisable(GL_BLEND)); 00738 00739 00740 00741 00742 } 00743 00744 00745 00746 void diskinttest::test03(int & argc, char** argv) 00747 { 00748 glutInit(&argc,argv); 00749 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00750 glutInitWindowSize(800,600); 00751 glutCreateWindow(""); 00752 glutDisplayFunc(display01); 00753 glutKeyboardFunc(keyboard03); 00754 00755 OpenGLinitialisation(); 00756 00757 glEnable(GL_DEPTH_TEST); 00758 glEnable(GL_CULL_FACE); 00759 glEnable(GL_NORMALIZE); 00760 00761 zpr zz; 00762 00763 xGraphics.set(); 00764 gobjpush(new myaxes(1.0)); 00765 00766 commandline cmd(argc,argv); 00767 00768 string in; 00769 cmd.mapvar(in,"in"); 00770 if ( in.empty() ) 00771 { 00772 cout << "error: in=filename expected" << endl; 00773 return; 00774 } 00775 00776 ifstream filein(in.c_str()); 00777 assert(filein.good()==true); 00778 if (filein.good()==false) 00779 return; 00780 00781 point3<double> nml; 00782 point3<double> pos; 00783 double radius; 00784 double height; 00785 00786 filein >> nml.x; 00787 filein >> nml.y; 00788 filein >> nml.z; 00789 filein >> pos.x; 00790 filein >> pos.y; 00791 filein >> pos.z; 00792 filein >> radius; 00793 filein >> height; 00794 00795 cylinder C1(nml,pos,radius,height); 00796 00797 filein >> nml.x; 00798 filein >> nml.y; 00799 filein >> nml.z; 00800 filein >> pos.x; 00801 filein >> pos.y; 00802 filein >> pos.z; 00803 filein >> radius; 00804 filein >> height; 00805 00806 cylinder C2(nml,pos,radius,height); 00807 00808 //cout << (stringc)C1 << endl; 00809 //cout << (stringc)C2 << endl; 00810 00811 00812 typedef point2<double> pt2; 00813 typedef point3<double> pt3; 00814 00815 00816 GLUquadricObj * quad = gluNewQuadric(); 00817 C1cd = new 00818 gobjgluCylinder(quad,C1.radius,C1.radius,C1.height,20,20); 00819 C2cd = new 00820 gobjgluCylinder(quad,C2.radius,C2.radius,C2.height,20,20); 00821 C1ptr = & C1; 00822 C2ptr = & C2; 00823 00824 gobjMyCircle * cir = new gobjMyCircle(); 00825 gobjpush(cir); 00826 gobjMyCircleDraw * cird; 00827 cird = new gobjMyCircleDraw(C1.radius,C1.pos,C1.nml,*cir); 00828 gobjpush(cird); 00829 D1cd = cird; 00830 cird = new gobjMyCircleDraw(C2.radius,C2.pos,C2.nml,*cir); 00831 gobjpush(cird); 00832 D2cd = cird; 00833 00834 00835 00836 cylinderintersection = new gobjContainer(true); 00837 gobjpush(cylinderintersection); 00838 00839 00840 menusystem * menu = 00841 new menusystem(0,0,true,point2<GLint>(60,30),20); 00842 00843 gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true); 00844 help = & menuswitch->isdrawn; 00845 gobjpush(menuswitch); 00846 00847 menu->addfont12("Cylinder and Cylinder Intersection"); 00848 menu->addnewline(); 00849 menu->addfont12("STATUS: Not complete - in progress."); 00850 menu->addnewline(); 00851 menu->addnewline(); 00852 menu->addfont10("'j' 'J' x position/normal"); 00853 menu->addnewline(); 00854 menu->addfont10("'k' 'K' y position/normal"); 00855 menu->addnewline(); 00856 menu->addfont10("'l' 'L' z position/normal"); 00857 menu->addnewline(); 00858 menu->addfont10("'m' Toggle position/normal mode"); 00859 menu->addnewline(); 00860 menu->addfont10("'p' Print the two cylinders to terminal."); 00861 menu->addnewline(); 00862 menu->addfont10("'t' Adjust the transparency."); 00863 menu->addnewline(); 00864 menu->addfont10("'h' Toggle this help menu."); 00865 menu->addnewline(); 00866 menu->addnewline(); 00867 menu->addfont10("ESC Quit"); 00868 00869 00870 update03(); 00871 00872 zz.update(); 00873 glutMainLoop(); 00874 } 00875 00876 00877
1.5.8