Skip to content
Snippets Groups Projects
Commit d840a2e7 authored by Boris Stefanovic's avatar Boris Stefanovic
Browse files

ADD: some constants

parent b2c8808c
No related branches found
No related tags found
No related merge requests found
.idea
*.o *.o
main main
tests tests
...@@ -8,34 +8,33 @@ ...@@ -8,34 +8,33 @@
#define SCREEN_WIDTH 1000 #define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 1000 #define SCREEN_HEIGHT 1000
int main() // arbitraire, en secondes ?
{ #define DELTA_T 0.125
int main() {
srand(time(NULL)); srand(time(NULL));
struct gfx_context_t *ctxt = struct gfx_context_t *ctxt =
gfx_create("Planetary system", SCREEN_WIDTH, SCREEN_HEIGHT); gfx_create("Planetary system", SCREEN_WIDTH, SCREEN_HEIGHT);
if (!ctxt) if (!ctxt) {
{
fprintf(stderr, "Graphics initialization failed!\n"); fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// TODO : create your system // TODO : create your system
system_t sys = create_system(DELTA_T);
// end : create system // end : create system
while (true) while (true) {
{
gfx_present(ctxt); gfx_present(ctxt);
gfx_clear(ctxt, COLOR_BLACK);
// TODO : draw the current state of your system // TODO : draw the current state of your system
// end : draw state of system // end : draw state of system
// TODO : update your system // TODO : update your system
// end : update system // end : update system
gfx_clear(ctxt, COLOR_BLACK); if (gfx_keypressed() == SDLK_ESCAPE) { break; }
if (gfx_keypressed() == SDLK_ESCAPE)
{
break;
}
} }
// TODO : Free your system // TODO : Free your system
free_system(sys);
// end : free system // end : free system
gfx_destroy(ctxt); gfx_destroy(ctxt);
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
#ifndef PLANET_CONSTANTS_H
#define PLANET_CONSTANTS_H
#define G 6.67e-11
#define M_SOLEIL 1.989e30
// source: CRM
#define M_TERRE 5.9742e24
// source: wiki
#define M_MERCURE 3.3011e23
#define M_VENUS 4.8675e24
#define M_MARS 6.4171e23
#define A_MERCURE 5.7909e10
#define A_VENUS 1.0821e11
#define A_TERRE 1.4960e11
#define A_MARS 2.2794e11
#define E_MERCURE 0.205630
#define E_VENUS 0.006772
#define E_TERRE 0.0167086
#define E_MARS 0.0934
//TODO: perihelion
#define PER_MERCURE
#define PER_VENUS
#define PER_TERRE
#define PER_MARS
#endif //PLANET_CONSTANTS_H
#include "planet.h" #include "planet.h"
#include <stdlib.h> #include <stdlib.h>
#define G 6.67e-11 #include "constants.h"
#define M_SOLEIL 1.989e30
/* /*
...@@ -24,10 +23,25 @@ typedef struct _system ...@@ -24,10 +23,25 @@ typedef struct _system
// TODO : complete all implementations // TODO : complete all implementations
planet_t create_planet(double mass, vec2 pos); planet_t create_planet(double mass, vec2 pos) {
planet_t p;
p.mass = mass;
system_t create_system(double delta_t); p.prec_pos = pos;
p.pos = pos;
return p;
}
system_t create_system(double delta_t) {
system_t system;
system.star = create_planet(M_SOLEIL, vec2_create_zero());
system.nb_planets = 4;
system.planets = malloc(system.nb_planets * sizeof(planet_t));
double masses[system.nb_planets] = {M_MERCURE, M_VENUS, M_TERRE, M_MARS};
//TODO
vec2 positions[system.nb_planets] = {vec2_create(), vec2_create(), vec2_create(), vec2_create()};
return system;
}
void show_system(struct gfx_context_t *ctxt, system_t *system); void show_system(struct gfx_context_t *ctxt, system_t *system);
......
...@@ -18,7 +18,7 @@ typedef struct _system ...@@ -18,7 +18,7 @@ typedef struct _system
planet_t *planets; // An array of orbiting planets planet_t *planets; // An array of orbiting planets
} system_t; } system_t;
// Those function are not mandatory to implement, // These functions are not mandatory to implement,
// it's rather a hint of what you should have. // it's rather a hint of what you should have.
planet_t create_planet(double mass, vec2 pos); planet_t create_planet(double mass, vec2 pos);
system_t create_system(double delta_t); system_t create_system(double delta_t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment