00001 #ifndef _PA_Math
00002 #define _PA_Math
00003
00004 #ifdef __cplusplus
00005 extern "C" {
00006 #endif
00007
00008 #include "PA9.h"
00009
00010
00011
00012
00023 #define PA_Cos(angle) PA_SIN[((angle) + 128)&511]
00024
00025
00031 #define PA_Sin(angle) PA_SIN[((angle))&511]
00032
00033
00034
00035
00036 extern u16 RandomValue;
00037
00038
00044
00045 extern inline void PA_InitRand(void) {
00046 PA_vblok = 0; while ((volatile bool)PA_vblok == 0);
00047 PA_vblok = 0; while ((volatile bool)PA_vblok == 0);
00048 RandomValue = PA_RTC.Minutes*7 + PA_RTC.Seconds*23 + PA_RTC.Hour + PA_RTC.Day;
00049 }
00050
00060
00061 extern inline void PA_SRand(s32 r) {
00062 RandomValue = r;
00063 }
00064
00065
00071 u32 PA_Rand(void);
00072
00073
00082 extern inline u32 PA_RandMax(u32 max)
00083 {
00084 return PA_Rand()%(max + 1);
00085 }
00086
00087
00088
00100 extern inline u32 PA_RandMinMax(u32 min,u32 max)
00101 {
00102 return ((PA_Rand()%((max + 1)-min)) + min);
00103 }
00104
00105
00123 extern inline u64 PA_Distance(s32 x1, s32 y1, s32 x2, s32 y2) {
00124 s64 h = x1 - x2;
00125 s64 v = y1 - y2;
00126 return(h*h + v*v);
00127 }
00128
00146 extern inline u64 PA_TrueDistance(s32 x1, s32 y1, s32 x2, s32 y2) {
00147 s64 h = x1 - x2;
00148 s64 v = y1 - y2;
00149 return(swiSqrt(h*h + v*v));
00150 }
00151
00152
00153
00178 u16 PA_AdjustAngle(u16 angle, s16 anglerot, s32 startx, s32 starty, s32 targetx, s32 targety);
00179
00180
00181
00199 extern inline u16 PA_GetAngle(s32 startx, s32 starty, s32 targetx, s32 targety) {
00200 u16 angle = 0;
00201 u16 anglerot = 180;
00202
00203
00204 while(anglerot > 5) {
00205 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00206 anglerot = (anglerot - ((3 * anglerot) >> 3));
00207 }
00208
00209
00210 anglerot = 4;
00211 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00212 anglerot = 2;
00213 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00214 anglerot = 1;
00215 angle = PA_AdjustAngle(angle, anglerot, startx, starty, targetx, targety);
00216
00217 return angle;
00218 }
00219
00221
00222
00223 extern inline s32 PA_Modulo(s32 var, s32 modulo){
00224 while(var < 0) var += modulo;
00225 return (var%modulo);
00226 }
00227
00228 #ifdef __cplusplus
00229 }
00230 #endif
00231
00232 #endif
00233
00234