PAlib
Data Structures | Macros | Functions
Math functions

Data Structures

struct  PA_Point
 Simple point structure. More...
 

Macros

#define PA_Cos(angle)   PA_SIN[((angle) + 128)&511]
 Returns the Cos value for an angle. The value goes from -256 to 256... Watch out though : the angle is not in 360 degrees, but in 512 !
 
#define PA_Sin(angle)   PA_SIN[((angle))&511]
 Returns the Sin value for an angle. The value goes from -256 to 256... Watch out though : the angle is not in 360 degrees, but in 256 !
 

Functions

static u32 PA_Rand ()
 Gives a random number, taken from Ham... This is taken from Ham, I have no credit.
 
static void PA_InitRand ()
 Auto-seeds the Rand function based on the clock !
 
static void PA_SRand (s32 r)
 Set the random's seed. This is taken from Ham, I have no credit. I just made it a little shorter/faster (maybe)
 
static u32 PA_RandMax (u32 max)
 Gives a random number, between 0 and the given number (included)
 
static u32 PA_RandMinMax (u32 min, u32 max)
 Gives a random number, between the 2 given numbers (included)
 
static u64 PA_Distance (s32 x1, s32 y1, s32 x2, s32 y2)
 Calculate the distance (squared) between 2 points.
 
static u64 PA_TrueDistance (s32 x1, s32 y1, s32 x2, s32 y2)
 Calculate the real distance between 2 points. A lot slower than PA_Distance.
 
u16 PA_AdjustAngle (u16 angle, s16 anglerot, s32 startx, s32 starty, s32 targetx, s32 targety)
 Adjust an angle, for example to calculate in which direction an object shoudl turn.
 
static u16 PA_GetAngle (s32 startx, s32 starty, s32 targetx, s32 targety)
 Get the angle, from 0 to 511, formed between the horizontal and the line.
 
int PA_mulf32 (int a, int b)
 Multiplies two .12 fixed point integers.
 
int PA_divf32 (int a, int b)
 Divides two .12 fixed point integers.
 
int PA_modf32 (int a, int b)
 Gets the remainder of the division between two .12 fixed point integers (modulo)
 
int PA_sqrtf32 (int a)
 Gets the square root of a .12 fixed point integer.
 

Detailed Description

Adjust angles, get random values...

Function Documentation

◆ PA_SRand()

void PA_SRand ( s32  r)
inlinestatic

Set the random's seed. This is taken from Ham, I have no credit. I just made it a little shorter/faster (maybe)

Parameters
rSeed value

◆ PA_RandMax()

static inline u32 PA_RandMax ( u32  max)
inlinestatic

Gives a random number, between 0 and the given number (included)

Parameters
maxMaximum included value

◆ PA_RandMinMax()

static inline u32 PA_RandMinMax ( u32  min,
u32  max 
)
inlinestatic

Gives a random number, between the 2 given numbers (included)

Parameters
minMinimum included value
maxMaximum included value

◆ PA_Distance()

static inline u32 PA_Distance ( s32  x1,
s32  y1,
s32  x2,
s32  y2 
)
inlinestatic

Calculate the distance (squared) between 2 points.

Parameters
x1X coordinate of the fist point
y1Y coordinate of the first point
x2X coordinate of the second point
y2Y coordinate of the second point

◆ PA_TrueDistance()

static inline u32 PA_TrueDistance ( s32  x1,
s32  y1,
s32  x2,
s32  y2 
)
inlinestatic

Calculate the real distance between 2 points. A lot slower than PA_Distance.

Parameters
x1X coordinate of the fist point
y1Y coordinate of the first point
x2X coordinate of the second point
y2Y coordinate of the second point

◆ PA_AdjustAngle()

u16 PA_AdjustAngle ( u16  angle,
s16  anglerot,
s32  startx,
s32  starty,
s32  targetx,
s32  targety 
)

Adjust an angle, for example to calculate in which direction an object shoudl turn.

Parameters
angleBase angle, from 0 to 511
anglerotFor how much to turn...
startxInitial X position
startyInitial Y position
targetxTarget X position
targetyTarget Y position

◆ PA_GetAngle()

static inline u16 PA_GetAngle ( s32  startx,
s32  starty,
s32  targetx,
s32  targety 
)
inlinestatic

Get the angle, from 0 to 511, formed between the horizontal and the line.

Parameters
startxInitial X position
startyInitial Y position
targetxTarget X position
targetyTarget Y position

◆ PA_mulf32()

int PA_mulf32 ( int  a,
int  b 
)

Multiplies two .12 fixed point integers.

Parameters
aFirst number
bSecond number

◆ PA_divf32()

int PA_divf32 ( int  a,
int  b 
)

Divides two .12 fixed point integers.

Parameters
aFirst number
bSecond number

◆ PA_modf32()

int PA_modf32 ( int  a,
int  b 
)

Gets the remainder of the division between two .12 fixed point integers (modulo)

Parameters
aFirst number
bSecond number

◆ PA_sqrtf32()

int PA_sqrtf32 ( int  a)

Gets the square root of a .12 fixed point integer.

Parameters
aNumber