From 1a19b5c98a38a926db23df6ca9c7ab2140149523 Mon Sep 17 00:00:00 2001 From: Milang Date: Fri, 16 Aug 2019 16:22:11 +0200 Subject: [PATCH] add comments and replace int by int32_t --- src/FxEngine/coord.c | 42 ++++++++++++++++++--------------------- src/FxEngine/coord.h | 47 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/src/FxEngine/coord.c b/src/FxEngine/coord.c index db55a3b..aaf4418 100644 --- a/src/FxEngine/coord.c +++ b/src/FxEngine/coord.c @@ -1,31 +1,28 @@ #include "coord.h" -#include "FxEngine.h" + +const double FE_PI = 3.141592653589793238462643383279; +const double FE_2_PI = FE_PI * 2; +const double FE_PI_SUR_2 = FE_PI / 2; -/* Cosinus and sinus implementation */ +static const uint32_t precision=15; // précision (nombre obligatoirement impair) choisie de façon arbitraire -/// Math values -const double pi=3.141592653589793238462643383279; -const double pi2=pi*2; -const double pi_sur2=pi/2; - -/// Internal Use -// cos function with 01 - for(int p=precision;p>=1;p-=2) - u=1-a2/(p*p+p)*u; + double u= 1.0; + const double a2 = a * a; + for(uint32_t p = precision; p>=1; p -= 2) + u = 1 - a2 / (p * p + p) * u; return u; } // return a with -pi<=api) a-=pi2; + while (a<=-pi) + a += pi2; + while (a>pi) + a -= pi2; return a; } @@ -33,22 +30,21 @@ static double cos_recursive(double angle) { if (angle<0) return cos_recursive(-angle); - if (angle>=pi_sur2) - return -reducted_cos(angle-pi); + if (angle>=FE_PI_SUR_2) + return -reducted_cos(angle - pi); return reducted_cos(angle); // OK } -/// External functions -// Official FE_cos function double FE_cos(double angle) { - angle=FE_modulo_2pi(angle); + angle = FE_modulo_2pi(angle); return cos_recursive(angle); } -// Official FE_sin function double FE_sin(double angle) -{return FE_cos(angle-pi_sur2);} +{ + return FE_cos(angle - pi_sur2); +} #define sgn(x) (x>=0?x:-x) diff --git a/src/FxEngine/coord.h b/src/FxEngine/coord.h index 32a0b71..3bb4848 100644 --- a/src/FxEngine/coord.h +++ b/src/FxEngine/coord.h @@ -1,30 +1,61 @@ #ifndef FE_COORD_H #define FE_COORD_H +#include "FxEngine.h" +/* FE_position: + notion de point dans l'espace simple */ typedef struct FE_position FE_position; struct FE_position -{int x,y,z;}; +{uint32_t x,y,z;}; +/* FE_point: + notion de point dans l'espace destiné à etre utilisé dans l'affichage + Dépend de + "coord.h" + FE_position */ typedef struct FE_point FE_point; struct FE_point {FE_position real,translated,rotated}; - +/* FE_calc(): + applique la matrice de rotation sur les coordonnées d'un point + + Dépend de : + "coord.h" + FE_cos() + FE_sin() + FE_point */ void FE_calc(FE_point* point); -// sets rotation matrice +/* FE_set_matrice(): + change la matrice de rotation pour le cycle à venir + + Dépend de : + "coord.h" + FE_cos() + FE_sin() */ void FE_set_matrice(void); -// Maths -extern const double pi; -extern const double pi2; -extern const double pi_sur2; +/* constantes mathématiques */ +extern const double FE_PI, FE_2_PI, FE_PI_SUR_2; + +/* FE_modulo_2pi(): + ramener la mesure d'un angle orienté à la valeur comprise entre 0 et 2 pi */ double FE_modulo_2pi(double a); + +/* FE_cos(): + implémentation du cosinus */ double FE_cos(double angle); -double FE_sin(double angle); +/* FE_sin(): + implémentation du sinus + + Dépend de : + "coord.h" + FE_cos() */ +double FE_sin(const double angle); #endif \ No newline at end of file