head 1.1; branch 1.1.1; access ; symbols start:1.1.1.1 PAlibDoc:1.1.1; locks ; strict; comment @# @; 1.1 date 2005.11.02.08.30.32; author jandujar; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2005.11.02.08.30.32; author jandujar; state Exp; branches ; next ; desc @@ 1.1 log @Initial revision @ text @ PA_lib: Fichier source de PA_Math.h

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 
00067 u32 PA_Rand(void);
00068 
00069 
00087 extern inline u64 PA_Distance(s32 x1, s32 y1, s32 x2, s32 y2) {
00088    s64 h = x1 - x2;
00089    s64 v = y1 - y2;
00090    return(h*h + v*v);
00091 }
00092 
00093 
00094 
00119 u16 PA_AdjustAngle(u16 angle, s16 anglerot, s32 startx, s32 starty, s32 targetx, s32 targety);
00120 
00121 
00122 
00140 extern inline u16 PA_GetAngle(s32 startx, s32 starty, s32 targetx, s32 targety) {
00141 u16 angle = 0;
00142 u16 anglerot = 180;
00143 
00144 
00145 while(anglerot > 5) {
00146        angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00147        anglerot = (anglerot - ((3 * anglerot) >> 3)); // On diminue petit à petit la rotation...
00148 }
00149 
00150 // Ajustement encore plus précis...
00151 anglerot = 4;
00152 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00153 anglerot = 2;
00154 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00155 anglerot = 1;
00156 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00157 
00158 return angle;
00159 }
00160  // end of Math
00162 
00163 
00164 extern inline s32 PA_Modulo(s32 var, s32 modulo){
00165 while(var < 0) var += modulo;
00166 return (var%modulo);
00167 }
00168 
00169 
00170 
00171 #endif
00172 
00173 

Généré le Fri Oct 28 23:18:12 2005 pour PA_lib par  doxygen 1.3.9.1
@ 1.1.1.1 log @Initial import of PalibDoc, begin on PAlib0.64b @ text @@