Files Classes Functions Hierarchy
00001 #include <bsptree001.h> 00002 #include <bsptreeD2disp03.h> 00003 #include <bsptreeD2dispregions01.h> 00004 #include <zpr.h> 00005 00006 00007 bsptree001* bsptree001::scene = 0; 00008 00009 string bsptree001::doc[] = 00010 { 00011 "", 00012 "" 00013 }; 00014 00015 bsptree001::bsptree001(int argc, char** argv) 00016 { 00017 glutInit(&argc,argv); 00018 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00019 glutInitWindowSize(800,600); 00020 glutCreateWindow(""); 00021 glutDisplayFunc(display); 00022 glutKeyboardFunc(keyboard); 00023 00024 OpenGLinitialisation(); 00025 glEnable(GL_CULL_FACE); 00026 glEnable(GL_NORMALIZE); 00027 00028 xGraphics.set(); 00029 00030 scene = this; 00031 00032 keyboarddelta = 0.1; 00033 00034 spherequadric.radius = 0.2; 00035 spherequadric.slices = 30; 00036 spherequadric.loops = 7; 00037 00038 commandline cmd(argc,argv); 00039 00040 bspbuild(); 00041 00042 bsptreeD2disp03<pt2,double,uint> * disp 00043 = new bsptreeD2disp03<pt2,double,uint>(bsp,0.02); 00044 disp->update(); 00045 gobjpush(disp); 00046 00047 bsptreeD2dispregions01<pt2,double,uint> *dispregions 00048 = new bsptreeD2dispregions01<pt2,double,uint>(bsp); 00049 dispregions->delta=0.4; 00050 dispregions->update(); 00051 gobjpush(dispregions); 00052 00053 update(); 00054 00055 00056 zpr zz; 00057 zz.update(); 00058 00059 glutMainLoop(); 00060 00061 00062 } 00063 00064 // http://www.codeproject.com/KB/openGL/GLUT_WINDOW_TEMPLATE.aspx 00065 void bsptree001::special(int key, int x, int y) 00066 { 00067 assertreturn(scene!=0); 00068 00069 switch (key) 00070 { 00071 case GLUT_KEY_RIGHT : scene->spherepos.x += scene->keyboarddelta; break; 00072 case GLUT_KEY_LEFT : scene->spherepos.x -= scene->keyboarddelta; break; 00073 case GLUT_KEY_UP : scene->spherepos.y += scene->keyboarddelta; break; 00074 case GLUT_KEY_DOWN : scene->spherepos.y -= scene->keyboarddelta; break; 00075 } 00076 00077 scene->update(); 00078 } 00079 00080 void bsptree001::keyboard 00081 ( 00082 unsigned char key, 00083 int x, 00084 int y 00085 ) 00086 { 00087 switch (key) 00088 { 00089 case 27: exit(0); break; 00090 00091 /* 00092 case '+': scene->keyboarddelta *= 10.0; 00093 if (scene->keyboarddelta==0.0) 00094 scene->keyboarddelta=0.1; 00095 break; 00096 case '-': scene->keyboarddelta /= 10.0; break; 00097 00098 case 'h': if (help!=0) *help = !*help; break; 00099 */ 00100 } 00101 00102 update(); 00103 } 00104 00105 void bsptree001::bspbuild() 00106 { 00107 cout << "Building a simple 2D partition." << endl; 00108 cout << " Using manual insertion commands : move to the node before" << endl; 00109 cout << " inserting new node, then adding associated half-space to vi." << endl << endl; 00110 00111 bsp.addroot( halfspaceD2<pt2,double>(pt2(0.0,0.0),pt2(0.0,1.0)) ); 00112 bsp.addleft( 0,0,halfspaceD2<pt2,double>(pt2(-1.0,1.0),pt2(0.0,1.0)) ); 00113 bsp.addright( 0,0,halfspaceD2<pt2,double>(pt2(0.0,-0.5),pt2(1.0,-0.5)) ); 00114 bsp.addleft( 1*1,1,halfspaceD2<pt2,double>(pt2(4.0,0.0),pt2(4.0,1.0)) ); 00115 } 00116 00117 00118 void bsptree001::update() 00119 { 00120 assertreturn(scene!=0); 00121 00122 00123 00124 /* 00125 targetg->push(targetsphere); 00126 00127 targetsphere->x = target.x; 00128 targetsphere->y = target.y; 00129 00130 glutPostRedisplay(); 00131 */ 00132 } 00133 00134 void bsptree001::currentsphere() 00135 { 00136 assertreturn(scene!=0); 00137 00138 uint i; 00139 scene->bsp.find(i,scene->spherepos); 00140 switch (i) 00141 { 00142 case 1: gobjpush(new gobjglColor3ub(220,20,60)); break; 00143 case 2: gobjpush(new gobjglColor3ub(0,206,209)); break; 00144 case 3: gobjpush(new gobjglColor3ub(255,140,0)); break; 00145 case 4: gobjpush(new gobjglColor3ub(143,188,139)); break; 00146 case 5: gobjpush(new gobjglColor3ub(184,134,11)); break; 00147 00148 default: 00149 gobjpush(new gobjglColor3ub(255,0,0)); 00150 } 00151 00152 gobjpush 00153 ( 00154 new gobjMySphereDraw 00155 ( 00156 scene->spherepos, 00157 scene->spherequadric 00158 ) 00159 ); 00160 00161 } 00162 00163 void bsptree001::display() 00164 { 00165 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00166 00167 gobj::global->draw(); 00168 glerrordisplay(); 00169 00170 glutSwapBuffers(); 00171 } 00172 00173 00174 /* 00175 void treeindexedD2test::update03() 00176 { 00177 assert(targetg!=0); 00178 assert(targetsphere!=0); 00179 00180 targetg->kill(1); 00181 targetg->nuke(); 00182 00183 uint i; 00184 bsp.find(i,target); 00185 switch (i) 00186 { 00187 case 1: targetg->push(new gobjglColor3ub(220,20,60)); break; 00188 case 2: targetg->push(new gobjglColor3ub(0,206,209)); break; 00189 case 3: targetg->push(new gobjglColor3ub(255,140,0)); break; 00190 case 4: targetg->push(new gobjglColor3ub(143,188,139)); break; 00191 case 5: targetg->push(new gobjglColor3ub(184,134,11)); break; 00192 00193 default: 00194 targetg->push(new gobjglColor3ub(255,0,0)); 00195 } 00196 00197 targetg->push(targetsphere); 00198 00199 targetsphere->x = target.x; 00200 targetsphere->y = target.y; 00201 00202 glutPostRedisplay(); 00203 } 00204 */ 00205 00206 00207
1.5.8