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
main
tests
......@@ -8,35 +8,34 @@
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 1000
int main()
{
srand(time(NULL));
struct gfx_context_t *ctxt =
gfx_create("Planetary system", SCREEN_WIDTH, SCREEN_HEIGHT);
if (!ctxt)
{
fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE;
}
// arbitraire, en secondes ?
#define DELTA_T 0.125
// TODO : create your system
int main() {
srand(time(NULL));
struct gfx_context_t *ctxt =
gfx_create("Planetary system", SCREEN_WIDTH, SCREEN_HEIGHT);
if (!ctxt) {
fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE;
}
// TODO : create your system
system_t sys = create_system(DELTA_T);
// end : create system
while (true)
{
gfx_present(ctxt);
// TODO : draw the current state of your system
// end : draw state of system
// TODO : update your system
// end : update system
gfx_clear(ctxt, COLOR_BLACK);
if (gfx_keypressed() == SDLK_ESCAPE)
{
break;
}
}
while (true) {
gfx_present(ctxt);
gfx_clear(ctxt, COLOR_BLACK);
// TODO : draw the current state of your system
// end : draw state of system
// TODO : update your system
// end : update system
if (gfx_keypressed() == SDLK_ESCAPE) { break; }
}
// TODO : Free your system
// end : free system
gfx_destroy(ctxt);
return EXIT_SUCCESS;
// TODO : Free your system
free_system(sys);
// end : free system
gfx_destroy(ctxt);
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 <stdlib.h>
#define G 6.67e-11
#define M_SOLEIL 1.989e30
#include "constants.h"
/*
......@@ -24,10 +23,25 @@ typedef struct _system
// TODO : complete all implementations
planet_t create_planet(double mass, vec2 pos);
system_t create_system(double delta_t);
planet_t create_planet(double mass, vec2 pos) {
planet_t p;
p.mass = mass;
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);
......
......@@ -6,19 +6,19 @@
typedef struct _planet
{
double mass;
vec2 pos; // x(t)
vec2 prec_pos; // x(t - dt)
double mass;
vec2 pos; // x(t)
vec2 prec_pos; // x(t - dt)
} planet_t;
typedef struct _system
{
planet_t star; // ex. The sun
uint32_t nb_planets; // The number of orbiting planets
planet_t *planets; // An array of orbiting planets
planet_t star; // ex. The sun
uint32_t nb_planets; // The number of orbiting planets
planet_t *planets; // An array of orbiting planets
} 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.
planet_t create_planet(double mass, vec2 pos);
system_t create_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