Rename functions and update args

This commit is contained in:
geoffrey 2023-08-05 18:24:54 +02:00
parent c98d6bf396
commit 0c5f29c983
6 changed files with 37 additions and 25 deletions

@ -3,7 +3,7 @@
#include "argparser.h" #include "argparser.h"
void usage() { void usage() {
printf("Cosmology: -c <param file> [--debug]\n"); printf("Astrophysics: <option> <param file> [--debug]\n");
} }
int getArgs(char *arg) { int getArgs(char *arg) {
@ -11,7 +11,7 @@ int getArgs(char *arg) {
int i; int i;
/* List arguments */ /* List arguments */
char listArgs[3][BUF_SIZE]; char listArgs[3][BUF_SIZE];
strcpy(listArgs[0], "-c"); // Gravity strcpy(listArgs[0], "-p"); // Projectile
for(i = 0; i < 3; i++){ for(i = 0; i < 3; i++){
if(strcmp(listArgs[i], arg) == 0) if(strcmp(listArgs[i], arg) == 0)

BIN
main

Binary file not shown.

12
main.c

@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
mainInitProjectile(yamlFile, &s_projectile, s_planet1.grav); mainInitProjectile(yamlFile, &s_projectile, s_planet1.grav);
switch (argv[1][1]){ switch (argv[1][1]){
case 'c': case 'p':
handleProjectile(&s_projectile, &s_planet1, debug); handleProjectile(&s_projectile, &s_planet1, debug);
break; break;
default: default:
@ -113,8 +113,8 @@ static void mainInitProjectile(const struct yamlFile *yamlFile, struct projectil
s_projectile->masse = parseYamlFileInt(yamlFile, "Projectile:masse"); s_projectile->masse = parseYamlFileInt(yamlFile, "Projectile:masse");
s_projectile->alpha = parseYamlFileDouble(yamlFile, "Projectile:angle"); s_projectile->alpha = parseYamlFileDouble(yamlFile, "Projectile:angle");
deg_to_rad = degree_to_radian(s_projectile->alpha); deg_to_rad = degree_to_radian(s_projectile->alpha);
s_projectile->v0x = calcul_initial_speed(deg_to_rad, v0, 'x'); s_projectile->v0x = calculate_initial_speed(deg_to_rad, v0, 'x');
s_projectile->v0y = calcul_initial_speed(deg_to_rad, v0, 'y'); s_projectile->v0y = calculate_initial_speed(deg_to_rad, v0, 'y');
s_projectile->rect.x = s_projectile->x; s_projectile->rect.x = s_projectile->x;
s_projectile->rect.y = s_projectile->y; s_projectile->rect.y = s_projectile->y;
s_projectile->rect.w = s_projectile->height; s_projectile->rect.w = s_projectile->height;
@ -122,11 +122,11 @@ static void mainInitProjectile(const struct yamlFile *yamlFile, struct projectil
/***** Informations about the projectile *****/ /***** Informations about the projectile *****/
// Calcul delta t // Calcul delta t
s_projectile->deltat = calcul_delta_t(s_projectile->v0y, grav); s_projectile->deltat = calculate_delta_t(s_projectile->v0y, grav);
// calcul distance in meter // calcul distance in meter
s_projectile->distance = calcul_distance_total(s_projectile->v0x, s_projectile->deltat); s_projectile->distance = calculate_total_distance(s_projectile->v0x, s_projectile->deltat);
// Calcul height Max // Calcul height Max
s_projectile->hmax = calcul_height_max(0.0, s_projectile->v0y, grav); s_projectile->hmax = calculate_height_max(0.0, s_projectile->v0y, grav);
} }

@ -1,35 +1,47 @@
#include "motion.h" #include "motion.h"
#include <math.h> #include <math.h>
double calcul_initial_speed(double alpha, double speed, const char c) { /*
// We calculated the v0 of y * Here, we calculate the initial speed
* Where alpha is the initial launch angle
* speed is the initial speed
* and c defined if we calculate for x or y
*/
double calculate_initial_speed(double alpha, double speed, const char c) {
// We calculated the v0 of x
if (c == 'x') if (c == 'x')
return speed * cos(alpha); return speed * cos(alpha);
// Otherwise, we calculated the v0 of x // Otherwise, we calculated the v0 of y
else else
return speed * sin(alpha); return speed * sin(alpha);
} }
/* /*
* This function calcul the during of the time before the projectile have touche the ground * This function calcul the during of the time before the projectile have reach the ground
* Where v is the initial speed of xor y
* and grav is the gravitational force
*/ */
double calcul_delta_t(double v, double grav){ double calculate_delta_t(double v, double grav){
return (2 * v) / grav; return (2 * v) / grav;
} }
/* /*
* This function calcul the distance total of the projectile * This function calcul the distance total of the projectile
* Where v is the initial speed of Vx
* and deltat is the result total time of flight
*/ */
double calcul_distance_total(double v, double deltat){ double calculate_total_distance(double v, double deltat){
return v * deltat; return v * deltat;
} }
/* /*
* This function calcul the height max of the Projectile * This function calcul the height max of the Projectile
* Where vx and xy are the initial speeds
* and grav is the gravitational force
*/ */
double calcul_height_max(double vx, double vy, double grav){ double calculate_height_max(double vx, double vy, double grav){
return (pow(vx, 2) - pow(vy, 2)) / (2 * -grav); return (pow(vx, 2) - pow(vy, 2)) / (2 * -grav);
} }
/* /*
* This function convert the degree in radian * This function convert the degree in radian
*/ */
double degree_to_radian(double degree){ double degree_to_radian(double degree){
return degree * M_PI / 180; return degree * M_PI / 180;
} }

@ -1,10 +1,10 @@
#ifndef H_MOTION #ifndef H_MOTION
#define H_MOTION #define H_MOTION
double calcul_initial_speed(double, double, const char); double calculate_initial_speed(double, double, const char);
double calcul_delta_t(double, double); double calculate_delta_t(double, double);
double calcul_distance_total(double, double); double calculate_total_distance(double, double);
double calcul_height_max(double, double, double); double calculate_height_max(double, double, double);
double degree_to_radian(double); double degree_to_radian(double);
#endif #endif

@ -5,7 +5,7 @@
#include "projectile.h" #include "projectile.h"
/* State of projectile */ /* State of projectile */
int isLaunch; static int isLaunch;
/* /*
* This function initialize our Projectile * This function initialize our Projectile
@ -174,7 +174,7 @@ void handleProjectile(struct projectile *s_projectile, const struct object *s_pl
args.window = s_window; args.window = s_window;
/* Init celestial object */ /* Init celestial object */
*sInfos = TTF_RenderText_Blended(s_window.font, "Earth", colorFont); *sInfos = TTF_RenderText_Blended(s_window.font, "Ground", colorFont);
initInfos(s_window.font, &rectInfos[0], sInfos[0], (WIN_PROJECTILE_WIDTH / 2) - sInfos[0]->w, rectObject.y + 15); initInfos(s_window.font, &rectInfos[0], sInfos[0], (WIN_PROJECTILE_WIDTH / 2) - sInfos[0]->w, rectObject.y + 15);
/* Get distance and time */ /* Get distance and time */