Mercurial > hg > Members > kent > N-BodyProblem
comparison main_GL.cbc @ 1:09e774f4433f
main_GL is runnable.
author | kent |
---|---|
date | Fri, 30 May 2008 00:00:49 +0900 |
parents | 249965d0a68f |
children | 3e543e31b6eb |
comparison
equal
deleted
inserted
replaced
0:249965d0a68f | 1:09e774f4433f |
---|---|
20 /* parameters */ | 20 /* parameters */ |
21 static int NUM_BODY = 3; | 21 static int NUM_BODY = 3; |
22 //static float Gravitation = 6.67e-11 ; | 22 //static float Gravitation = 6.67e-11 ; |
23 //static float delta = 100; | 23 //static float delta = 100; |
24 //static float FIELD = 2e11; | 24 //static float FIELD = 2e11; |
25 static float Gravitation = 0.2f; // ? | 25 static float Gravitation = 100.0f; // ? |
26 static float delta = 100.0f; // 0.01 ~ 100 ? | 26 static float delta = 0.05f; // 0.01 ~ 100 ? |
27 static float FIELD = 400.0f; // -100 ~ 100 | 27 static float FIELD = 400.0f; // -100 ~ 100 |
28 static const float eps = 0.0f; | 28 static const float eps = 15.0f; |
29 | 29 |
30 /* for OpenGL Utility. */ | 30 /* for OpenGL Utility. */ |
31 GLUquadricObj **sphere; | 31 GLUquadricObj **sphere; |
32 | 32 |
33 typedef struct | 33 typedef struct |
128 /* initialize OpenGL. */ | 128 /* initialize OpenGL. */ |
129 glViewport(0,0,screen->w,screen->h); | 129 glViewport(0,0,screen->w,screen->h); |
130 glMatrixMode(GL_PROJECTION); | 130 glMatrixMode(GL_PROJECTION); |
131 glLoadIdentity(); | 131 glLoadIdentity(); |
132 gluPerspective( 60.0, (float)screen->w/(float)screen->h, 1.0, 1000.0); | 132 gluPerspective( 60.0, (float)screen->w/(float)screen->h, 1.0, 1000.0); |
133 gluLookAt( 500.0,500.0,500.0, 0.0,0.0,0.0, 1.0,0.0,0.0); | 133 gluLookAt( 300.0,300.0,300.0, 0.0,0.0,0.0, 1.0,0.0,0.0); |
134 glClearColor(0.0, 0.0, 0.0, 0.0); | 134 glClearColor(0.0, 0.0, 0.0, 0.0); |
135 glMatrixMode(GL_MODELVIEW); | 135 glMatrixMode(GL_MODELVIEW); |
136 | 136 |
137 //DEBUGlog("scr->w=%d\n", screen->w); | 137 //DEBUGlog("scr->w=%d\n", screen->w); |
138 //DEBUGlog("scr->h=%d\n", screen->h); | 138 //DEBUGlog("scr->h=%d\n", screen->h); |
142 } | 142 } |
143 | 143 |
144 goto starsInit(screen, num); | 144 goto starsInit(screen, num); |
145 } | 145 } |
146 | 146 |
147 __code starsInit0(SDL_Surface *screen, int num) | 147 __code starsInitRandom(SDL_Surface *screen, int num) |
148 { | 148 { |
149 int i; | 149 int i; |
150 srandom(time(NULL)); | 150 srandom(time(NULL)); |
151 for (i=0; i<num; i++){ // this loop should be split into few code segment.. | 151 for (i=0; i<num; i++){ // this loop should be split into few code segment.. |
152 stars_old[i].weight = random()/(RAND_MAX+1.0)*5+5; | 152 stars_old[i].weight = random()/(RAND_MAX+1.0)*5+5; |
163 } | 163 } |
164 __code starsInit(SDL_Surface *screen, int num) | 164 __code starsInit(SDL_Surface *screen, int num) |
165 { | 165 { |
166 int i; | 166 int i; |
167 /* */ | 167 /* */ |
168 stars_old[0].weight = 110; | 168 stars_old[0].weight = 1000; |
169 stars_old[0].v[0] = 0.0; | |
170 stars_old[0].v[1] = -1.0; | |
171 stars_old[0].v[2] = 0.0; | |
172 stars_old[0].r[0] = 100.0; | |
173 stars_old[0].r[1] = 0.0; | |
174 stars_old[0].r[2] = 0.0; | |
175 /* */ | |
176 stars_old[1].weight = 110; | |
177 stars_old[1].v[0] = 0.0; | |
178 stars_old[1].v[1] = -1.0; | |
179 stars_old[1].v[2] = 0.0; | |
180 stars_old[1].r[0] = -100.0; | |
181 stars_old[1].r[1] = 0.0; | |
182 stars_old[1].r[2] = 0.0; | |
183 /* */ | |
184 stars_old[2].weight = 110; | |
185 stars_old[2].v[0] = -1.0; | |
186 stars_old[2].v[1] = 0.0; | |
187 stars_old[2].v[2] = 0.0; | |
188 stars_old[2].r[0] = 0.0; | |
189 stars_old[2].r[1] = 0.0; | |
190 stars_old[2].r[2] = -70.0; | |
191 | |
192 for( i=0; i<num; i++){ | |
193 stars_new[i].weight = stars_old[i].weight; | |
194 //stars_new[i].rect.h = 5, stars_new[i].rect.w = 5; | |
195 //stars_old[i].rect.h = 5, stars_old[i].rect.w = 5; | |
196 } | |
197 | |
198 goto loop(0, screen, num); | |
199 } | |
200 | |
201 __code starsInit1(SDL_Surface *screen, int num) | |
202 { | |
203 int i; | |
204 /* Sun */ | |
205 stars_old[0].weight = 1.9891e30; // 1.9891*10^30 | |
206 stars_old[0].v[0] = 0.0; | 169 stars_old[0].v[0] = 0.0; |
207 stars_old[0].v[1] = 0.0; | 170 stars_old[0].v[1] = 0.0; |
208 stars_old[0].v[2] = 0.0; | 171 stars_old[0].v[2] = 0.0; |
209 stars_old[0].r[0] = 0.0; | 172 stars_old[0].r[0] = 0.0; |
210 stars_old[0].r[1] = 0.0; | 173 stars_old[0].r[1] = 0.0; |
211 stars_old[0].r[2] = 0.0; | 174 stars_old[0].r[2] = 0.0; |
212 /* Venus */ | 175 /* */ |
213 stars_old[1].weight = 4.869e24; // 4.869*10^24 | 176 stars_old[1].weight = 5; |
214 stars_old[1].v[0] = 0.0; | 177 stars_old[1].v[0] = 0.1; |
215 stars_old[1].v[1] = 3.50214e4; // 35.0214 km/s | 178 stars_old[1].v[1] = 5.0; |
216 stars_old[1].v[2] = 0.0; | 179 stars_old[1].v[2] = 0.0; |
217 stars_old[1].r[0] = 1.08e11; // 108,208,930 km | 180 stars_old[1].r[0] = 100.0; |
218 stars_old[1].r[1] = 0.0; | 181 stars_old[1].r[1] = 0.0; |
219 stars_old[1].r[2] = 0.0; | 182 stars_old[1].r[2] = 0.0; |
220 /* Earth */ | 183 /* */ |
221 stars_old[2].weight = 5.9742e24; // 5.9742*10^24 | 184 stars_old[2].weight = 5; |
222 stars_old[2].v[0] = 0.0; | 185 stars_old[2].v[0] = 0.0; |
223 stars_old[2].v[1] = 2.97859e4; // 29.7859 km/s | 186 stars_old[2].v[1] = -5.0; |
224 stars_old[2].v[2] = 0.0; | 187 stars_old[2].v[2] = 0.1; |
225 stars_old[2].r[0] = 1.49e11; // 149,597,870km | 188 stars_old[2].r[0] = -100.0; |
226 stars_old[2].r[1] = 0.0; | 189 stars_old[2].r[1] = 0.0; |
227 stars_old[2].r[2] = 0.0; | 190 stars_old[2].r[2] = 0.0; |
228 | 191 |
229 for( i=0; i<num; i++){ | 192 for( i=0; i<num; i++){ |
230 stars_new[i].weight = stars_old[i].weight; | 193 stars_new[i].weight = stars_old[i].weight; |
373 if ( i==count ) continue; | 336 if ( i==count ) continue; |
374 /* compute distance between two i-th planet and itself. */ | 337 /* compute distance between two i-th planet and itself. */ |
375 d0 = stars_old[i].r[0] - stars_old[count].r[0]; | 338 d0 = stars_old[i].r[0] - stars_old[count].r[0]; |
376 d1 = stars_old[i].r[1] - stars_old[count].r[1]; | 339 d1 = stars_old[i].r[1] - stars_old[count].r[1]; |
377 d2 = stars_old[i].r[2] - stars_old[count].r[2]; | 340 d2 = stars_old[i].r[2] - stars_old[count].r[2]; |
378 d = ( d0*d0+d1*d1+d2*d2 ); | 341 d = ( d0*d0+d1*d1+d2*d2+eps*eps ); |
379 /* compute force it receive from i-th planet. */ | 342 /* compute force it receive from i-th planet. */ |
380 //F = Gravitation * stars_old[i].weight * stars_old[count].weight / d; | 343 //F = Gravitation * stars_old[i].weight * stars_old[count].weight / d; |
381 /* and accel. */ | 344 /* and accel. */ |
382 //a = F/stars_old[count].weight; | 345 //a = F/stars_old[count].weight; |
383 a = Gravitation/d * stars_old[i].weight ; | 346 a = Gravitation/d * stars_old[i].weight ; |
424 DEBUGlog("draw\n"); | 387 DEBUGlog("draw\n"); |
425 glClear( GL_COLOR_BUFFER_BIT ); | 388 glClear( GL_COLOR_BUFFER_BIT ); |
426 for (i=0; i<num; i++){ | 389 for (i=0; i<num; i++){ |
427 glPushMatrix(); | 390 glPushMatrix(); |
428 glTranslatef( stars_new[i].r[0], stars_new[i].r[1], stars_new[i].r[2]); | 391 glTranslatef( stars_new[i].r[0], stars_new[i].r[1], stars_new[i].r[2]); |
429 gluSphere( sphere[i], 200.0, 8.0, 8.0 ); | 392 gluSphere( sphere[i], 2.0, 8.0, 8.0 ); |
430 glPopMatrix(); | 393 glPopMatrix(); |
431 } | 394 } |
432 | 395 |
433 glColor3d( 1.0, 1.0, 1.0); | 396 glColor3d( 1.0, 1.0, 1.0); |
434 glBegin(GL_LINES); | 397 glBegin(GL_LINES); |