18,11 → 18,11 |
|
/* |
------------ |
CVS : $Id: orbit.c,v 1.4 2003-05-01 19:44:07 pj Exp $ |
CVS : $Id: orbit.c,v 1.5 2004-05-23 11:27:29 giacomo Exp $ |
|
File: $File$ |
Revision: $Revision: 1.4 $ |
Last update: $Date: 2003-05-01 19:44:07 $ |
Revision: $Revision: 1.5 $ |
Last update: $Date: 2004-05-23 11:27:29 $ |
------------ |
*/ |
|
50,26 → 50,28 |
/****************************************************************/ |
|
#include <kernel/kern.h> |
#include <drivers/glib.h> |
#include <drivers/keyb.h> |
#include <semaphore.h> |
#include <stdlib.h> |
#include <math.h> |
#include <string.h> |
|
#include <drivers/shark_fb26.h> |
#include <drivers/shark_keyb26.h> |
|
#define MAX 11 /* numero massimo pianeti */ |
#define ESC 27 /* codice ASCII tasto ESCAPE */ |
#define XMAX 639 /* valore massimo coordinata X */ |
#define YMAX 479 /* valore massimo coordinata Y */ |
|
extern int vga16color[16]; |
|
struct coord { |
double x; |
double y; |
}; |
|
char fbuf[1000]; // buffer for reading a file |
int flen; // file length |
|
double mass[MAX]; /* vettore masse pianeti */ |
float mass[MAX]; /* vettore masse pianeti */ |
struct coord pos[MAX]; /* vettore posizioni attuali */ |
struct coord vel[MAX]; /* vettore velocita' iniziali */ |
|
76,11 → 78,33 |
int XGS, YGS; /* Coordinate centro spazio */ |
int RP, RT; /* raggio pianeta, raggio Terra */ |
int np; /* numero attuale di pianeti */ |
double G; /* Gravitazione Universale */ |
double tick; /* tick di sistema */ |
double delta; /* incremento temporale */ |
double scala; /* fattore grafico di scala */ |
float G; /* Gravitazione Universale */ |
float tick; /* tick di sistema */ |
float delta; /* incremento temporale */ |
float scala; /* fattore grafico di scala */ |
|
char fbuf[1000] ="\ |
----------------------------------------------------\n\ |
period: 10000 wcet: 100\n\ |
delta: 1. scala: 150.\n\ |
G: 6.6e-15\n\ |
r_pianeta: 4 r_Terra: 8\n\ |
X_centro: 320 Y_centro: 240\n\ |
------------------- pianeti ------------------------\n\ |
massa pos.x pos.y vel.x vel.y\n\ |
0: 6.0e21 0. 0. 0. 0.\n\ |
1: 1.0e21 10000. 8000. -60. 0.\n\ |
2: 1.0e8 5000. 0. 0. 80.\n\ |
3: 5.0e18 10000. 8000. -50. 0.\n\ |
4: 1.0e9 10000. 8000. -40. 20.\n\ |
5: 1.0e15 1000. 5000. -80. 0.\n\ |
6: 1.0e5 1000. 5000. -80. 0.\n\ |
7: 1.0e17 1000. 5000. -80. 0.\n\ |
8: 1.0e5 1000. 5000. -80. 0.\n\ |
9: 1.0e5 1000. 5000. -80. 0.\n\ |
10: 1.0e5 1000. 5000. -80. 0.\n\ |
----------------------------------------------------\n"; |
|
// ------------------------------------------------------- |
// NOTA: %f o %lf significa double e %nf significa float |
// ------------------------------------------------------- |
95,13 → 119,6 |
|
/*--------------------------------------------------------------*/ |
|
void my_fine(void *arg) |
{ |
grx_close(); |
} |
|
/*--------------------------------------------------------------*/ |
|
int inside(int x, int y) |
{ |
return ((x > RP) && (x < XMAX-RP) && |
161,8 → 178,8 |
col = i + 1; |
|
sem_wait(&mutex); |
grx_disc(ox,oy,r,0); |
grx_disc(gx,gy,r,col); |
grx_disc(ox,oy,r,vga16color[0]); |
grx_disc(gx,gy,r,vga16color[col]); |
sem_post(&mutex); |
|
pos[i].x = x; pos[i].y = y; |
173,9 → 190,9 |
} while ((dist0 > 0) && inside(gx,gy)); |
|
sem_wait(&mutex); |
grx_disc(ox,oy,r,0); |
grx_disc(XGS,YGS,RT,12); |
grx_circle(XGS,YGS,RT,14); |
grx_disc(ox,oy,r,vga16color[0]); |
grx_disc(XGS,YGS,RT,vga16color[12]); |
grx_circle(XGS,YGS,RT,vga16color[14]); |
sem_post(&mutex); |
|
return NULL; |
190,19 → 207,13 |
HARD_TASK_MODEL m; |
char c; /* carattere letto da tastiera */ |
|
sys_atrunlevel(my_fine, NULL, RUNLEVEL_BEFORE_EXIT); |
|
sem_init(&mutex,0,1); |
|
get_par(); |
keyb_getch(BLOCK); |
|
grx_init(); |
grx_open(640, 480, 8); |
grx_disc(XGS,YGS,RT,vga16color[12]); |
grx_circle(XGS,YGS,RT,vga16color[14]); |
|
grx_disc(XGS,YGS,RT,12); |
grx_circle(XGS,YGS,RT,14); |
|
np = 0; |
|
do { |
261,52 → 272,45 |
{ |
int x = 0; |
int i; |
double vx, vy; |
float vx, vy; |
|
flen = strlen(fbuf); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%d", &period); |
cprintf("period = %d\n", period); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%d", &wcet); |
cprintf("wcet = %d\n", wcet); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%f", &delta); |
cprintf("delta = %f\n", delta); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%f", &scala); |
cprintf("scala = %f\n", scala); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%f", &G); |
cprintf("G = %20.15f\n", G); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%d", &RP); |
cprintf("RP = %d\n", RP); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%d", &RT); |
cprintf("RT = %d\n", RT); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%d", &XGS); |
cprintf("XGS = %d\n", XGS); |
|
while ((fbuf[x] != ':') && (x < flen)) x++; |
x++; |
sscanf(&fbuf[x], "%d", &YGS); |
cprintf("YGS = %d\n", YGS); |
|
for (i=0; i<MAX; i++) { |
while ((fbuf[x] != ':') && (x < flen)) x++; |
330,10 → 334,6 |
x++; |
sscanf(&fbuf[x], "%f", &vy); |
vel[i].x = vx; vel[i].y = vy; |
|
cprintf("mass[%d] = %f\t", i, mass[i]); |
cprintf("pos: %f, %f\t", pos[i].x, pos[i].y); |
cprintf("vel: %f, %f\n", vel[i].x, vel[i].y); |
} |
} |
|