PA_Math.h

00001 
00002 #ifndef _PA_Math
00003 #define _PA_Math
00004 
00005 #include "PA9.h"
00006 
00007 
00008 
00009 
00020 #define PA_Cos(angle) PA_SIN[((angle) + 128)&511]
00021 
00022 
00028 #define PA_Sin(angle) PA_SIN[((angle))&511]
00029 
00030 
00031 
00032 
00033 extern u16 RandomValue;  // Seed pour la fonction random
00034 
00035 
00041 // 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
00042 extern inline void PA_InitRand(void) {
00043        PA_vblok = 0;  while ((volatile bool)PA_vblok == 0);
00044        PA_vblok = 0;  while ((volatile bool)PA_vblok == 0); // Pour laisser le temps de mettre à jour...
00045    RandomValue = PA_RTC.Minutes*7 + PA_RTC.Seconds*23 + PA_RTC.Hour + PA_RTC.Day;
00046 }
00047 
00057 // 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
00058 extern inline void PA_SRand(s32 r) {
00059    RandomValue = r;
00060 }
00061 
00062 
00068 u32 PA_Rand(void);
00069 
00070 
00079 extern inline u32 PA_RandMax(u32 max)
00080 {
00081     return PA_Rand()%(max + 1);
00082 }
00083 
00084 
00085 
00097 extern inline u32 PA_RandMinMax(u32 min,u32 max)
00098 {
00099     return ((PA_Rand()%((max + 1)-min)) + min);
00100 } 
00101 
00102 
00120 extern inline u64 PA_Distance(s32 x1, s32 y1, s32 x2, s32 y2) {
00121    s64 h = x1 - x2;
00122    s64 v = y1 - y2;
00123    return(h*h + v*v);
00124 }
00125 
00126 
00127 
00152 u16 PA_AdjustAngle(u16 angle, s16 anglerot, s32 startx, s32 starty, s32 targetx, s32 targety);
00153 
00154 
00155 
00173 extern inline u16 PA_GetAngle(s32 startx, s32 starty, s32 targetx, s32 targety) {
00174 u16 angle = 0;
00175 u16 anglerot = 180;
00176 
00177 
00178 while(anglerot > 5) {
00179        angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00180        anglerot = (anglerot - ((3 * anglerot) >> 3)); // On diminue petit à petit la rotation...
00181 }
00182 
00183 // Ajustement encore plus précis...
00184 anglerot = 4;
00185 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00186 anglerot = 2;
00187 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00188 anglerot = 1;
00189 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00190 
00191 return angle;
00192 }
00193  // end of Math
00195 
00196 
00197 extern inline s32 PA_Modulo(s32 var, s32 modulo){
00198 while(var < 0) var += modulo;
00199 return (var%modulo);
00200 }
00201 
00202 
00203 
00204 #endif
00205 
00206 

Généré le Tue Dec 13 11:53:02 2005 pour PAlib par  doxygen 1.3.9.1