Files Classes Functions Hierarchy
00001 00002 #include <cassert> 00003 #include <iostream> 00004 using namespace std; 00005 00006 #include <GL/glut.h> 00007 #include <GL/glu.h> 00008 #include <GL/gl.h> 00009 00010 #include <boxcollision.h> 00011 #include <cell.h> 00012 #include <commandline.h> 00013 #include <d2toindex.h> 00014 #include <graphmisc.h> 00015 #include <histogram.h> 00016 #include <integration.h> 00017 #include <particle.h> 00018 #include <particledisp.h> 00019 #include <particleranvd.h> 00020 #include <particlesampler.h> 00021 #include <zpr.h> 00022 00023 00024 //#define DEBUG_PART 00025 00026 00027 //integration<particlev0theta0> G; 00028 //integration<particleranvd,d2toindex> G; 00029 //integration<particlev0,d2toindex> G; 00030 integration<particlev0spaced,d2toindex> G; 00031 00032 00033 00034 void animate() 00035 { 00036 if (G.run) 00037 G.step(); 00038 00039 G.fr.update(); 00040 G.stepcountmsg.updatevalue("stepcount: ",G.stepcount); 00041 glutPostRedisplay(); 00042 } 00043 00044 00045 void display() 00046 { 00047 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00048 glPushMatrix(); 00049 00050 glDisable(GL_LIGHTING); 00051 //axes(10.0); 00052 00053 G.draw(); 00054 00055 00056 00057 glPopMatrix(); 00058 glutSwapBuffers(); 00059 } 00060 00061 void reshape(int w, int h) 00062 { 00063 glViewport(0, 0, w, h); 00064 glMatrixMode(GL_PROJECTION); 00065 glLoadIdentity(); 00066 00067 glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0); 00068 glMatrixMode(GL_MODELVIEW); 00069 glLoadIdentity(); 00070 } 00071 00072 void keyboard 00073 ( 00074 unsigned char key, 00075 int x, 00076 int y 00077 ) 00078 { 00079 switch (key) 00080 { 00081 case 27: 00082 exit(0); 00083 break; 00084 case 'h': 00085 G.step(); 00086 break; 00087 case 'H': 00088 G.steplarge(); 00089 break; 00090 case 's': 00091 case 'S': 00092 G.togglestartstop(); 00093 break; 00094 00095 } 00096 } 00097 00098 00099 void test01(int argc, char** argv) 00100 { 00101 glutInit(&argc, argv); 00102 glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00103 glutInitWindowSize(600, 600); 00104 glutCreateWindow("Collision Detection and Dynamics: Particles in an Arena"); 00105 glutDisplayFunc(display); 00106 glutIdleFunc(animate); 00107 glutReshapeFunc(reshape); 00108 glutKeyboardFunc(keyboard); 00109 00110 G.reset(argc,argv); 00111 00112 zpr zz; 00113 00114 zz.update(); 00115 00116 commandline cmd(argc,argv); 00117 00118 double angle=20.0; 00119 double near=1.0; 00120 double far=100.0; 00121 uint choice(2); 00122 cmd.mapvar(choice,"choice"); 00123 cmd.mapvar(angle,"angle"); 00124 cmd.mapvar(near,"near"); 00125 cmd.mapvar(far,"far"); 00126 00127 double left=-1.0; 00128 double right=1.0; 00129 double bottom=-1.0; 00130 double top=1.0; 00131 00132 cmd.mapvar(left,"left"); 00133 cmd.mapvar(right,"right"); 00134 cmd.mapvar(bottom,"bottom"); 00135 cmd.mapvar(top,"top"); 00136 00137 if (choice!=0) 00138 { 00139 glMatrixMode(GL_PROJECTION); 00140 glLoadIdentity(); 00141 } 00142 00143 switch( choice ) 00144 { 00145 case 0: break; 00146 case 1: 00147 glFrustum(left,right,bottom,top,near,far); break; 00148 case 2: camera::lookat(cmd,4.8,4.7,5.6); break; 00149 // Can over-ride with 00150 // $./main choice=2 camerax=2.0 cameray=.4 cameraz=4.0 00151 // whatever numbers you want 00152 case 3: gluPerspective(angle,1.0,near,far); break; 00153 default: break; 00154 } 00155 00156 if (choice!=0) 00157 { 00158 glMatrixMode(GL_MODELVIEW); 00159 } 00160 00161 double eyex(0.0); 00162 double eyey(0.0); 00163 double eyez(0.0); 00164 cmd.mapvar(eyex,"eyex"); 00165 cmd.mapvar(eyey,"eyey"); 00166 cmd.mapvar(eyez,"eyez"); 00167 glTranslated(eyex,eyey,eyez); 00168 00169 glutPostRedisplay(); 00170 00171 glutMainLoop(); 00172 } 00173 00174 00175 // 00176 // Measuring particle update separate to graphics 00177 // 00178 // This is going to be used to compare against other implementations. 00179 void test02(int argc, char** argv) 00180 { 00181 int const milli = 1000; 00182 uint N = 1000; 00183 commandline c(argc,argv); 00184 c.mapvar(N,"N"); 00185 c.mapvar(G.uniform,"uniform"); 00186 c.mapvar(G.numParticles,"numParticles"); 00187 00188 G.reset(argc,argv); 00189 00190 float startTime = glutGet(GLUT_ELAPSED_TIME) / (float)milli; 00191 if (!G.uniform) 00192 { 00193 for (uint i=0; i<N; ++i) 00194 G.bruteforce(); 00195 } 00196 else 00197 { 00198 for (uint i=0; i<N; ++i) 00199 G.uniformgridtest(); 00200 } 00201 00202 float elapsedTime = glutGet(GLUT_ELAPSED_TIME) / (float)milli - startTime; 00203 cout << SHOW(elapsedTime) << endl; 00204 } 00205 00206 void test03(int argc, char** argv) 00207 { 00208 particlev0theta0 D 00209 ( 00210 0.2, //radius 00211 1.0, //vmax 00212 boxcollision(0.0,10.0,0.0,10.0) //box dimensions 00213 ); 00214 00215 uintc N(8); 00216 particle pi[N]; 00217 d2toindex f2(pi,D.box); 00218 f2.reset(); 00219 uint W = (uint)( sqrt((double)N) )+1; 00220 f2.W = W; 00221 00222 for (uint i=0; i<N; ++i) 00223 { 00224 D.randomposition(pi[i]); 00225 cout << pi[i]; 00226 cout << endl; 00227 cout << " indx=" << f2.index(i) << endl; 00228 } 00229 00230 cout << endl << endl; 00231 00232 cell C(N); 00233 C.eval(f2); 00234 00235 uint * nb; 00236 uint sz; 00237 for (uint i=0; i<W*W; ++i) 00238 { 00239 f2.getsurroundingcells(nb,sz,i); 00240 cout << "i=" << i << " "; 00241 for (uint k=0; k<sz; ++k) 00242 cout << nb[k] << " "; 00243 cout << endl; 00244 } 00245 00246 } 00247 00248 00249 00250 int main(int argc, char** argv) 00251 { 00252 commandline c(argc,argv); 00253 bool benchmark(false); 00254 c.mapvar(benchmark,"benchmark"); 00255 00256 if (benchmark) 00257 test02(argc,argv); 00258 else 00259 test01(argc,argv); 00260 00261 00262 00263 return 0; 00264 }
1.5.8