PA_Math.h

00001 #ifndef _PA_Math
00002 #define _PA_Math
00003 
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007 
00008 #include "PA9.h"
00009 
00010 #include "PA_Interrupt.h"
00011 
00012 
00013 
00014 typedef struct{
00015        u8 Screen;
00016        float Time;
00017        s8 Functions;
00018        s32 Runs[16];
00019 }PA_TestInfos;
00020 extern PA_TestInfos PA_TestInfo;
00021 
00022 extern inline void PA_TestInit(u8 screen, float time){
00023        PA_TestInfo.Screen = screen;
00024        PA_TestInfo.Time = time*60; // Convert seconds to VBLs
00025        PA_TestInfo.Functions = 0; // Functions tested
00026 }
00027 
00028 #define PA_TESTSTART  { PA_OutputText(PA_TestInfo.Screen, 0, 4+PA_TestInfo.Functions, "Testing function %02d", PA_TestInfo.Functions+1);\
00029                             PA_WaitForVBL();\
00030                             PA_TestVBLs = 0;\
00031                             while( PA_TestVBLs < PA_TestInfo.Time){
00032 
00033 
00034 #define PA_TESTEND  PA_TestInfo.Runs[PA_TestInfo.Functions] ++; }\
00035                                    PA_TestInfo.Functions++;} // 1 more function tested
00036                                                         
00037 
00038 void PA_TestResults(void);
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00062 #define PA_Cos(angle) PA_SIN[((angle) + 128)&511]
00063 
00064 
00070 #define PA_Sin(angle) PA_SIN[((angle))&511]
00071 
00072 
00073 
00074 
00075 extern u16 RandomValue;  // Seed pour la fonction random
00076 
00082 extern inline u32 PA_Rand(void) {
00083 int i;
00084    RandomValue+=0x9248;
00085 
00086    for(i=0;i<3;i++)   {
00087        if(RandomValue&0x1) {
00088            RandomValue>>=1;
00089            RandomValue|=0x8000;
00090        }
00091        else  RandomValue>>=1;
00092    }
00093    return(RandomValue);
00094 }
00095 
00096 
00102 // Les fonctions randoms sont prises de Ham, je n'ai strictement AUCUN mérite ! Désolé ! Je l'ai un peu modifiée, elle doit etre plus rapide
00103 extern inline void PA_InitRand(void) {
00104    RandomValue = PA_RTC.Minutes*60 + PA_RTC.Seconds + PA_RTC.Hour*3600 + PA_RTC.Day*3600*24+PA_RTC.Month*3600*24*30;
00105    PA_Rand(); PA_Rand(); PA_Rand(); // On fait plusieurs fois de base
00106 }
00107 
00117 // Les fonctions randoms sont prises de Ham, je n'ai strictement AUCUN mérite ! Désolé ! Je l'ai un peu modifiée, elle doit etre plus rapide
00118 extern inline void PA_SRand(s32 r) {
00119    RandomValue = r;
00120 }
00121 
00122 
00123 
00124 
00125 
00134 extern inline u32 PA_RandMax(u32 max)
00135 {
00136     return PA_Rand()%(max + 1);
00137 }
00138 
00139 
00140 
00152 extern inline u32 PA_RandMinMax(u32 min,u32 max)
00153 {
00154     return ((PA_Rand()%((max + 1)-min)) + min);
00155 } 
00156 
00157 
00175 extern inline u64 PA_Distance(s32 x1, s32 y1, s32 x2, s32 y2) {
00176    s64 h = x1 - x2;
00177    s64 v = y1 - y2;
00178    return(h*h + v*v);
00179 }
00180 
00198 extern inline u64 PA_TrueDistance(s32 x1, s32 y1, s32 x2, s32 y2) {
00199    s64 h = x1 - x2;
00200    s64 v = y1 - y2;
00201    return(swiSqrt(h*h + v*v));
00202 }
00203 
00204 
00205 
00230 u16 PA_AdjustAngle(u16 angle, s16 anglerot, s32 startx, s32 starty, s32 targetx, s32 targety);
00231 
00232 
00233 
00251 extern inline u16 PA_GetAngle(s32 startx, s32 starty, s32 targetx, s32 targety) {
00252 u16 angle = 0;
00253 u16 anglerot = 180;
00254 
00255 
00256 while(anglerot > 5) {
00257        angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00258        anglerot = (anglerot - ((3 * anglerot) >> 3)); // On diminue petit à petit la rotation...
00259 }
00260 
00261 // Ajustement encore plus précis...
00262 anglerot = 4;
00263 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00264 anglerot = 2;
00265 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00266 anglerot = 1;
00267 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00268 
00269 return angle;
00270 }
00271  // end of Math
00273 
00274 
00275 extern inline s32 PA_Modulo(s32 var, s32 modulo){
00276 while(var < 0) var += modulo;
00277 return (var%modulo);
00278 }
00279 
00280 #ifdef __cplusplus
00281 }
00282 #endif
00283 
00284 #endif
00285 
00286 

Généré le Tue Jan 30 23:10:49 2007 pour PAlib par  doxygen 1.3.9.1