From 53d77f0736705dcbb54bb57be084b9900a0e2eb5 Mon Sep 17 00:00:00 2001 From: "arnaud.devevey" <arnaud.de-vevey@etu.hesge.ch> Date: Fri, 7 Jun 2019 11:40:05 +0200 Subject: [PATCH] star avance --- perso/Makefile | 2 +- perso/box.c | 15 ++++----------- perso/box.h | 3 +++ perso/galaxy.c | 4 ++-- perso/star.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/perso/Makefile b/perso/Makefile index 4f2d1dc..8639da9 100644 --- a/perso/Makefile +++ b/perso/Makefile @@ -1,5 +1,5 @@ CC = gcc -CARGS = -std=c11 -Wall -Wextra -fsanitize=address -fsanitize=leak -fsanitize=undefined +CARGS = -g -std=c11 -Wall -Wextra -fsanitize=address -fsanitize=leak -fsanitize=undefined LARGS = -lm -lSDL2 all = box galaxy quadtree star vector diff --git a/perso/box.c b/perso/box.c index 9a4b93c..43ef236 100644 --- a/perso/box.c +++ b/perso/box.c @@ -72,15 +72,15 @@ double compute_length(Box box) { double height = box.x1 - box.x0; double width = box.y1 - box.y0; - printf("\tprint_box() : la hauteur de la box est : %d", height); - printf("\tprint_box() : la largeur de la box est : %d", width); + printf("\tcompute_length() : la hauteur de la box est : %f", height); + printf("\tcompute_length() : la largeur de la box est : %f", width); return 2.0; } void print_box(Box box) { - printf("\tprint_box() : x0 = %f \tx1 = %f \ty0 = %f \ty1 = %f \n", box.x0, box.x1, box.y0, box.y1); + printf("\tprint_box() : coin haut-gauche : (%f;%f) / coin bas-droite : (%f;%f) \n", box.x0, box.y0, box.x1, box.y1); } @@ -115,14 +115,7 @@ void tests_box_new(Box* b1) { } void tests_box_divide(Box* b2) { - Box* b_divide = new_box(0.0, 1.5, 0.0, 1.5); - - TEST(b2 -> x0 == b_divide -> x0 && - b2 -> x1 == b_divide -> x1 && - b2 -> y0 == b_divide -> y0 && - b2 -> y1 == b_divide -> y1) - - free(b_divide); + // COMPLETER APRES AVOIR FINI DIVIDE() } void tests_box_include(Box* b1) { diff --git a/perso/box.h b/perso/box.h index ba925c2..84d86b3 100644 --- a/perso/box.h +++ b/perso/box.h @@ -39,5 +39,8 @@ void print_box(Box box); void tests_box(); +void tests_box_new(Box* b1); +void tests_box_divide(Box* b2); +void tests_box_include(Box* b1); #endif \ No newline at end of file diff --git a/perso/galaxy.c b/perso/galaxy.c index 0dc9c3f..b702960 100644 --- a/perso/galaxy.c +++ b/perso/galaxy.c @@ -65,12 +65,12 @@ int main(int argc, char **argv) { * --- FONCTIONS --- * * * * * * * * * * * * * * * * * * * */ - +/* Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) { } -/* + void reset_acc_galaxy(Galaxy* galaxy) { } diff --git a/perso/star.c b/perso/star.c index 5dd256b..95eac0d 100644 --- a/perso/star.c +++ b/perso/star.c @@ -1,9 +1,10 @@ +#include <math.h> #include "star.h" -#define MASSE_MIN math.pow(10, 20) -#define MASSE_SOLAIRE (1.98892 * math.pow(10, 30)) -#define DELTA_T (math.pow(10, 10)) // discrétisation temporelle +#define MASSE_MIN 1e20 +#define MASSE_SOLAIRE 1.98892e30 +#define DELTA_T 1e10 // discrétisation temporelle /* * * * * * * * * * * * * * * * * * * @@ -18,9 +19,16 @@ Star* new_star_vel(Vector new_pos, Vector new_speed, Vector new_acc, double new_ new_star -> pos = new_pos; // on multiplie le vecteur speed par delta_t (qui retourne un pointeur sur vecteur, que l'on déréférence) - new_star -> previous_pos = *(mul_vec(&new_speed, new_dt)); + Vector *pos_tmp = mul_vec(&new_speed, new_dt); + new_star -> previous_pos = *pos_tmp; + free(pos_tmp); + // et on soustrait ce résultat au vecteur position (qui retourne un pointeur sur vecteur, que l'on déréférence) - new_star -> previous_pos = *(sub_vec(&(new_star -> previous_pos), &new_pos)); + pos_tmp = sub_vec(&(new_star -> previous_pos), &new_pos); + new_star -> previous_pos = *pos_tmp; + free(pos_tmp); + + pos_tmp = NULL; new_star -> acc = new_acc; new_star -> mass = new_mass; @@ -58,6 +66,21 @@ void print_star(const Star* const star) { masse = %f \n", star -> pos.x, star -> pos.y, star -> previous_pos.x, star -> previous_pos.y, star -> acc.x, star -> acc.y, star -> mass); } +/* +il faut deja faire une liste de stars qui se trouvent dans une box +Star* super_star(Star* list_stars) { + Star* super_star = malloc(sizeof(Star)) + + for (int i = 0; i < list_stars.len() MARCHE PAS COMME CA; i++) { + super_star -> pos += list_stars[i] -> pos; + } + + super_star -> # /= list_stars.len() + + return super_star; +} +*/ + @@ -70,9 +93,20 @@ void print_star(const Star* const star) { void tests_star() { printf("TESTS STAR : \n"); - Star* s1 = malloc(sizeof(Star)); + + Vector* position = new_vec(4.0, 5.0); + Vector* speed = new_vec(4.0, 5.0); + Vector* acceleration = new_vec(4.0, 5.0); + + Star* s1 = new_star_vel(*position, *speed, *acceleration, MASSE_MIN, DELTA_T); + print_star(s1); + free(s1); + free(position); + free(speed); + free(acceleration); + printf("\n"); } \ No newline at end of file -- GitLab