Mercurial > hg > Members > kent > N-BodyProblem
changeset 1:09e774f4433f
main_GL is runnable.
author | kent |
---|---|
date | Fri, 30 May 2008 00:00:49 +0900 |
parents | 249965d0a68f |
children | 3e543e31b6eb |
files | main.cbc main_GL.cbc |
diffstat | 2 files changed, 61 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/main.cbc Thu May 29 19:35:24 2008 +0900 +++ b/main.cbc Fri May 30 00:00:49 2008 +0900 @@ -6,8 +6,7 @@ #include<float.h> #define DEBUGlog(f, args...) \ - ; - //fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) + fprintf(stderr, "in %s: "f, __FUNCTION__, ## args) #define W_HEIGHT 480 #define W_WIDTH 640 @@ -23,7 +22,7 @@ static float Gravitation = 1.0f; // ? static float delta = 0.05f; // static float FIELD = 400.0f; // -100 ~ 100 -static const float eps = 1.5f; +static const float eps = 15.0f; typedef struct { @@ -153,31 +152,56 @@ stars_old[2].r[0] = 0.0; stars_old[2].r[1] = 0.0; stars_old[2].r[2] = -70.0; -#else +#elif 0 /* */ - stars_old[0].weight = 100; - stars_old[0].v[0] = -1.0; + stars_old[0].weight = 1000; + stars_old[0].v[0] = 0.0; stars_old[0].v[1] = 0.0; - stars_old[0].v[2] = 0.5; - stars_old[0].r[0] = 50.0; + stars_old[0].v[2] = 0.0; + stars_old[0].r[0] = 0.0; stars_old[0].r[1] = 0.0; stars_old[0].r[2] = 0.0; /* */ - stars_old[1].weight = 100; - stars_old[1].v[0] = -0.5; - stars_old[1].v[1] = 0.1; - stars_old[1].v[2] = 1.732; - stars_old[1].r[0] = -50.0; + stars_old[1].weight = 5; + stars_old[1].v[0] = 0.1; + stars_old[1].v[1] = 5.0; + stars_old[1].v[2] = 0.0; + stars_old[1].r[0] = 10.0; stars_old[1].r[1] = 0.0; stars_old[1].r[2] = 0.0; /* */ - stars_old[2].weight = 100; - stars_old[2].v[0] = 0.5; - stars_old[2].v[1] = -0.1; - stars_old[2].v[2] = -1.732; - stars_old[2].r[0] = 0.0; + stars_old[2].weight = 5; + stars_old[2].v[0] = 0.0; + stars_old[2].v[1] = -5.0; + stars_old[2].v[2] = 0.1; + stars_old[2].r[0] = -10.0; stars_old[2].r[1] = 0.0; - stars_old[2].r[2] = 86.60; + stars_old[2].r[2] = 0.0; +#elif 1 + /* */ + stars_old[0].weight = 1000; + stars_old[0].v[0] = 0.0; + stars_old[0].v[1] = 0.0; + stars_old[0].v[2] = 0.0; + stars_old[0].r[0] = 0.0; + stars_old[0].r[1] = 0.0; + stars_old[0].r[2] = 0.0; + /* */ + stars_old[1].weight = 5; + stars_old[1].v[0] = 0.1; + stars_old[1].v[1] = 5.0; + stars_old[1].v[2] = 0.0; + stars_old[1].r[0] = 100.0; + stars_old[1].r[1] = 0.0; + stars_old[1].r[2] = 0.0; + /* */ + stars_old[2].weight = 5; + stars_old[2].v[0] = 0.0; + stars_old[2].v[1] = -5.0; + stars_old[2].v[2] = 0.1; + stars_old[2].r[0] = -100.0; + stars_old[2].r[1] = 0.0; + stars_old[2].r[2] = 0.0; #endif for( i=0; i<num; i++){
--- a/main_GL.cbc Thu May 29 19:35:24 2008 +0900 +++ b/main_GL.cbc Fri May 30 00:00:49 2008 +0900 @@ -22,10 +22,10 @@ //static float Gravitation = 6.67e-11 ; //static float delta = 100; //static float FIELD = 2e11; -static float Gravitation = 0.2f; // ? -static float delta = 100.0f; // 0.01 ~ 100 ? +static float Gravitation = 100.0f; // ? +static float delta = 0.05f; // 0.01 ~ 100 ? static float FIELD = 400.0f; // -100 ~ 100 -static const float eps = 0.0f; +static const float eps = 15.0f; /* for OpenGL Utility. */ GLUquadricObj **sphere; @@ -130,7 +130,7 @@ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective( 60.0, (float)screen->w/(float)screen->h, 1.0, 1000.0); - gluLookAt( 500.0,500.0,500.0, 0.0,0.0,0.0, 1.0,0.0,0.0); + gluLookAt( 300.0,300.0,300.0, 0.0,0.0,0.0, 1.0,0.0,0.0); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_MODELVIEW); @@ -144,7 +144,7 @@ goto starsInit(screen, num); } -__code starsInit0(SDL_Surface *screen, int num) +__code starsInitRandom(SDL_Surface *screen, int num) { int i; srandom(time(NULL)); @@ -165,64 +165,27 @@ { int i; /* */ - stars_old[0].weight = 110; - stars_old[0].v[0] = 0.0; - stars_old[0].v[1] = -1.0; - stars_old[0].v[2] = 0.0; - stars_old[0].r[0] = 100.0; - stars_old[0].r[1] = 0.0; - stars_old[0].r[2] = 0.0; - /* */ - stars_old[1].weight = 110; - stars_old[1].v[0] = 0.0; - stars_old[1].v[1] = -1.0; - stars_old[1].v[2] = 0.0; - stars_old[1].r[0] = -100.0; - stars_old[1].r[1] = 0.0; - stars_old[1].r[2] = 0.0; - /* */ - stars_old[2].weight = 110; - stars_old[2].v[0] = -1.0; - stars_old[2].v[1] = 0.0; - stars_old[2].v[2] = 0.0; - stars_old[2].r[0] = 0.0; - stars_old[2].r[1] = 0.0; - stars_old[2].r[2] = -70.0; - - for( i=0; i<num; i++){ - stars_new[i].weight = stars_old[i].weight; - //stars_new[i].rect.h = 5, stars_new[i].rect.w = 5; - //stars_old[i].rect.h = 5, stars_old[i].rect.w = 5; - } - - goto loop(0, screen, num); -} - -__code starsInit1(SDL_Surface *screen, int num) -{ - int i; - /* Sun */ - stars_old[0].weight = 1.9891e30; // 1.9891*10^30 + stars_old[0].weight = 1000; stars_old[0].v[0] = 0.0; stars_old[0].v[1] = 0.0; stars_old[0].v[2] = 0.0; stars_old[0].r[0] = 0.0; stars_old[0].r[1] = 0.0; stars_old[0].r[2] = 0.0; - /* Venus */ - stars_old[1].weight = 4.869e24; // 4.869*10^24 - stars_old[1].v[0] = 0.0; - stars_old[1].v[1] = 3.50214e4; // 35.0214 km/s + /* */ + stars_old[1].weight = 5; + stars_old[1].v[0] = 0.1; + stars_old[1].v[1] = 5.0; stars_old[1].v[2] = 0.0; - stars_old[1].r[0] = 1.08e11; // 108,208,930 km + stars_old[1].r[0] = 100.0; stars_old[1].r[1] = 0.0; stars_old[1].r[2] = 0.0; - /* Earth */ - stars_old[2].weight = 5.9742e24; // 5.9742*10^24 + /* */ + stars_old[2].weight = 5; stars_old[2].v[0] = 0.0; - stars_old[2].v[1] = 2.97859e4; // 29.7859 km/s - stars_old[2].v[2] = 0.0; - stars_old[2].r[0] = 1.49e11; // 149,597,870km + stars_old[2].v[1] = -5.0; + stars_old[2].v[2] = 0.1; + stars_old[2].r[0] = -100.0; stars_old[2].r[1] = 0.0; stars_old[2].r[2] = 0.0; @@ -375,7 +338,7 @@ d0 = stars_old[i].r[0] - stars_old[count].r[0]; d1 = stars_old[i].r[1] - stars_old[count].r[1]; d2 = stars_old[i].r[2] - stars_old[count].r[2]; - d = ( d0*d0+d1*d1+d2*d2 ); + d = ( d0*d0+d1*d1+d2*d2+eps*eps ); /* compute force it receive from i-th planet. */ //F = Gravitation * stars_old[i].weight * stars_old[count].weight / d; /* and accel. */ @@ -426,7 +389,7 @@ for (i=0; i<num; i++){ glPushMatrix(); glTranslatef( stars_new[i].r[0], stars_new[i].r[1], stars_new[i].r[2]); - gluSphere( sphere[i], 200.0, 8.0, 8.0 ); + gluSphere( sphere[i], 2.0, 8.0, 8.0 ); glPopMatrix(); }