Skip to content
Snippets Groups Projects
Commit 95920e2e authored by BobLeHibou's avatar BobLeHibou
Browse files

ADD: EPPUR SI MUOVE !

parent 814a2ed6
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,7 @@
#define SUN_RADIUS 50
#define DELTA_T 3600.0
#define DELTA_T 8000.0
int main() {
srand(time(NULL));
......@@ -32,7 +32,6 @@ int main() {
// end : draw state of system
// begin : update your system
update_system(&sys, DELTA_T);
usleep(100000);
// end : update system
if (gfx_keypressed() == SDLK_ESCAPE) { break; }
}
......
......@@ -2,6 +2,10 @@
#define PLANET_CONSTANTS_H
// display
#define DISPLAY_RADIUS_DIV 1.0e23
#define G 6.67e-11
#define M_SOLEIL 1.989e30
......
......@@ -20,22 +20,22 @@ system_t create_system(double delta_t) {
system.star = create_planet(M_SOLEIL, vec2_create_zero());
system.nb_planets = 4;
system.planets = malloc(system.nb_planets * sizeof(planet_t));
double masses[NB_PLANETS] = {
double masses[] = {
M_MERCURE,
M_VENUS,
M_TERRE,
M_MARS};
vec2 positions[NB_PLANETS] = {
vec2 positions[] = {
vec2_create(PER_MERCURE, 0.0),
vec2_create(PER_VENUS, 0.0),
vec2_create(PER_TERRE, 0.0),
vec2_create(PER_MARS, 0.0)};
double eccentricities[NB_PLANETS] = {
double eccentricities[] = {
E_MERCURE,
E_VENUS,
E_TERRE,
E_MARS};
double axis_major[NB_PLANETS] = {
double axis_major[] = {
A_MERCURE,
A_VENUS,
A_TERRE,
......@@ -55,9 +55,12 @@ system_t create_system(double delta_t) {
}
void show_system(struct gfx_context_t* ctxt, system_t* system, const uint32_t width, const uint32_t height) {
void show_system(struct gfx_context_t* ctxt, system_t* system) {
// draw sun
const coordinates xy_sun = vec2_to_coordinates_centered(vec2_normalize(system->star.pos), width, height);
const coordinates xy_sun = vec2_to_coordinates_centered(
vec2_normalize(system->star.pos),
ctxt->width,
ctxt->height);
draw_full_circle(ctxt, xy_sun.column, xy_sun.row, 50, COLOR_YELLOW);
// draw planets
for (uint32_t i = 0; i < system->nb_planets; ++i) {
......@@ -85,12 +88,14 @@ void update_system(system_t* system, double delta_t) {
const vec2 a_k = vec2_mul(a_norm, u);
a = vec2_add(a, a_k);
}
a = vec2_mul(-1.0, a); // correct sign: towards center
// update position
vec2 next_pos = vec2_mul(2.0, system->planets[i].pos);
next_pos = vec2_sub(next_pos, system->planets[i].prec_pos);
next_pos = vec2_add(next_pos, vec2_mul(delta_t * delta_t, a));
system->planets[i].prec_pos = system->planets[i].pos;
system->planets[i].pos = next_pos;
printf("%lf %lf %lf\n", system->planets[i].pos.x, system->planets[i].pos.y, vec2_norm(a));
}
}
......
......@@ -22,8 +22,7 @@ planet_t create_planet(double mass, vec2 pos);
system_t create_system(double delta_t);
//void show_system(struct gfx_context_t *ctxt, system_t *system);
void show_system(struct gfx_context_t* ctxt, system_t* system, const uint32_t width, const uint32_t height);
void show_system(struct gfx_context_t* ctxt, system_t* system);
void update_system(system_t* system, double delta_t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment