Skip to content
Snippets Groups Projects
Commit 53d77f07 authored by arnaud.devevey's avatar arnaud.devevey
Browse files

star avance

parent 302e5235
No related branches found
No related tags found
No related merge requests found
Pipeline #5985 failed
CC = gcc 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 LARGS = -lm -lSDL2
all = box galaxy quadtree star vector all = box galaxy quadtree star vector
......
...@@ -72,15 +72,15 @@ double compute_length(Box box) { ...@@ -72,15 +72,15 @@ double compute_length(Box box) {
double height = box.x1 - box.x0; double height = box.x1 - box.x0;
double width = box.y1 - box.y0; double width = box.y1 - box.y0;
printf("\tprint_box() : la hauteur de la box est : %d", height); printf("\tcompute_length() : la hauteur de la box est : %f", height);
printf("\tprint_box() : la largeur de la box est : %d", width); printf("\tcompute_length() : la largeur de la box est : %f", width);
return 2.0; return 2.0;
} }
void print_box(Box box) { 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) { ...@@ -115,14 +115,7 @@ void tests_box_new(Box* b1) {
} }
void tests_box_divide(Box* b2) { void tests_box_divide(Box* b2) {
Box* b_divide = new_box(0.0, 1.5, 0.0, 1.5); // COMPLETER APRES AVOIR FINI DIVIDE()
TEST(b2 -> x0 == b_divide -> x0 &&
b2 -> x1 == b_divide -> x1 &&
b2 -> y0 == b_divide -> y0 &&
b2 -> y1 == b_divide -> y1)
free(b_divide);
} }
void tests_box_include(Box* b1) { void tests_box_include(Box* b1) {
......
...@@ -39,5 +39,8 @@ void print_box(Box box); ...@@ -39,5 +39,8 @@ void print_box(Box box);
void tests_box(); void tests_box();
void tests_box_new(Box* b1);
void tests_box_divide(Box* b2);
void tests_box_include(Box* b1);
#endif #endif
\ No newline at end of file
...@@ -65,12 +65,12 @@ int main(int argc, char **argv) { ...@@ -65,12 +65,12 @@ int main(int argc, char **argv) {
* --- FONCTIONS --- * * --- FONCTIONS --- *
* * * *
* * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * */
/*
Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) { Galaxy* create_and_init_galaxy(int nb_bodies, Box box, double delta_t) {
} }
/*
void reset_acc_galaxy(Galaxy* galaxy) { void reset_acc_galaxy(Galaxy* galaxy) {
} }
......
#include <math.h>
#include "star.h" #include "star.h"
#define MASSE_MIN math.pow(10, 20) #define MASSE_MIN 1e20
#define MASSE_SOLAIRE (1.98892 * math.pow(10, 30)) #define MASSE_SOLAIRE 1.98892e30
#define DELTA_T (math.pow(10, 10)) // discrétisation temporelle #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_ ...@@ -18,9 +19,16 @@ Star* new_star_vel(Vector new_pos, Vector new_speed, Vector new_acc, double new_
new_star -> pos = new_pos; 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) // 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) // 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 -> acc = new_acc;
new_star -> mass = new_mass; new_star -> mass = new_mass;
...@@ -58,6 +66,21 @@ void print_star(const Star* const star) { ...@@ -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); 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) { ...@@ -70,9 +93,20 @@ void print_star(const Star* const star) {
void tests_star() { void tests_star() {
printf("TESTS STAR : \n"); 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(s1);
free(position);
free(speed);
free(acceleration);
printf("\n"); printf("\n");
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment