This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
rc2007-soccer/source/Concept/Framework/tools.h

70 lines
1.2 KiB
C
Raw Normal View History

2007-02-06 14:41:04 +00:00
#ifndef _TOOLS_H
#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
#ifndef new
void* operator new(size_t sz);
void operator delete(void* p);
#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))
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-19 22:02:01 +00:00
for (uint16 s = 0; s < sec; s++) {
for (uint32 i = 0; i < 1405678; i++) {
asm volatile("nop");
}
}
};
2007-02-19 22:02:01 +00:00
inline void msleep(uint16 msec)
{
2007-02-19 22:02:01 +00:00
for (uint16 s = 0; s < msec; s++) {
for (uint16 i = 0; i < 1405; i++) {
asm volatile("nop");
}
}
};
2007-02-19 22:02:01 +00:00
inline void usleep(uint16 usec)
{
2007-02-19 22:02:01 +00:00
for (uint16 s = 0; s < usec; s++) {
for (uint8 i = 0; i < 3; i++) {
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)
{
return atan2((y2 - y1), (x2 - x1));
2007-02-18 00:14:00 +00:00
}
2007-02-06 14:41:04 +00:00
#endif