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
00024 #define PA_Cos(angle) PA_SIN[((angle) + 128)&511]
00025
00026
00032 #define PA_Sin(angle) PA_SIN[((angle))&511]
00033
00034
00035
00036
00037 extern u16 RandomValue;
00038
00044 u32 PA_Rand(void);
00045
00046
00052
00053 extern inline void PA_InitRand(void) {
00054 RandomValue = PA_RTC.Minutes*60 + PA_RTC.Seconds + PA_RTC.Hour*3600 + PA_RTC.Day*3600*24+PA_RTC.Month*3600*24*30;
00055 PA_Rand(); PA_Rand(); PA_Rand();
00056 }
00057
00067
00068 extern inline void PA_SRand(s32 r) {
00069 RandomValue = r;
00070 }
00071
00072
00073
00074
00075
00084 extern inline u32 PA_RandMax(u32 max)
00085 {
00086 return PA_Rand()%(max + 1);
00087 }
00088
00089
00090
00102 extern inline u32 PA_RandMinMax(u32 min,u32 max)
00103 {
00104 return ((PA_Rand()%((max + 1)-min)) + min);
00105 }
00106
00107
00125 extern inline u64 PA_Distance(s32 x1, s32 y1, s32 x2, s32 y2) {
00126 s64 h = x1 - x2;
00127 s64 v = y1 - y2;
00128 return(h*h + v*v);
00129 }
00130
00148 extern inline u64 PA_TrueDistance(s32 x1, s32 y1, s32 x2, s32 y2) {
00149 s64 h = x1 - x2;
00150 s64 v = y1 - y2;
00151 return(swiSqrt(h*h + v*v));
00152 }
00153
00154
00155
00180 u16 PA_AdjustAngle(u16 angle, s16 anglerot, s32 startx, s32 starty, s32 targetx, s32 targety);
00181
00182
00183
00201 extern inline u16 PA_GetAngle(s32 startx, s32 starty, s32 targetx, s32 targety) {
00202 u16 angle = 0;
00203 u16 anglerot = 180;
00204
00205
00206 while(anglerot > 5) {
00207 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00208 anglerot = (anglerot - ((3 * anglerot) >> 3));
00209 }
00210
00211
00212 anglerot = 4;
00213 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00214 anglerot = 2;
00215 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00216 anglerot = 1;
00217 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00218
00219 return angle;
00220 }
00221
00223
00224
00225 extern inline s32 PA_Modulo(s32 var, s32 modulo){
00226 while(var < 0) var += modulo;
00227 return (var%modulo);
00228 }
00229
00230 #ifdef __cplusplus
00231 }
00232 #endif
00233
00234 #endif
00235
00236