2007-02-06 14:41:04 +00:00
|
|
|
#ifndef _TOOLS_H
|
2007-02-16 15:22:03 +00:00
|
|
|
#define _TOOLS_H
|
|
|
|
|
2007-02-18 00:14:00 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
2007-02-19 22:02:01 +00:00
|
|
|
#include "defines.h"
|
2007-02-06 14:41:04 +00:00
|
|
|
|
2007-02-16 15:22:03 +00:00
|
|
|
#ifndef new
|
2007-02-13 14:40:04 +00:00
|
|
|
void* operator new(size_t sz);
|
|
|
|
void operator delete(void* p);
|
2007-02-17 00:35:01 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 17:57:03 +00:00
|
|
|
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
|
|
|
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#define sign(a) (((a) < 0) ? (-1) : (1))
|
|
|
|
|
2007-02-20 21:01:02 +00:00
|
|
|
inline float easyAngle(float angle)
|
|
|
|
{
|
|
|
|
while(angle < 0)
|
|
|
|
{
|
|
|
|
angle += 2.0f * PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(angle >= 2.0f * PI)
|
|
|
|
{
|
|
|
|
angle -= 2.0f * PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2007-02-19 22:02:01 +00:00
|
|
|
inline void sleep(uint16 sec)
|
2007-02-17 00:35:01 +00:00
|
|
|
{
|
2007-02-19 22:02:01 +00:00
|
|
|
for (uint16 s = 0; s < sec; s++) {
|
|
|
|
for (uint32 i = 0; i < 1405678; i++) {
|
2007-02-17 00:35:01 +00:00
|
|
|
asm volatile("nop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-02-19 22:02:01 +00:00
|
|
|
inline void msleep(uint16 msec)
|
2007-02-17 00:35:01 +00:00
|
|
|
{
|
2007-02-19 22:02:01 +00:00
|
|
|
for (uint16 s = 0; s < msec; s++) {
|
|
|
|
for (uint16 i = 0; i < 1405; i++) {
|
2007-02-17 00:35:01 +00:00
|
|
|
asm volatile("nop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-02-19 22:02:01 +00:00
|
|
|
inline void usleep(uint16 usec)
|
2007-02-17 00:35:01 +00:00
|
|
|
{
|
2007-02-19 22:02:01 +00:00
|
|
|
for (uint16 s = 0; s < usec; s++) {
|
|
|
|
for (uint8 i = 0; i < 3; i++) {
|
2007-02-17 00:35:01 +00:00
|
|
|
asm volatile("nop");
|
|
|
|
}
|
|
|
|
}
|
2007-02-18 00:14:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline float distance2d(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
|
|
|
return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
|
2007-02-18 17:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline float direction2d(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
2007-02-20 21:01:02 +00:00
|
|
|
return atan2((y2 - y1), (x2 - x1));
|
2007-02-18 00:14:00 +00:00
|
|
|
}
|
2007-02-06 14:41:04 +00:00
|
|
|
|
|
|
|
#endif
|