generated from pimoroni/picosystem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFixedMath.h
39 lines (30 loc) · 969 Bytes
/
FixedMath.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include <stdint.h>
#if _WIN32
#include <math.h>
#endif
#include "Defines.h"
#define FIXED_SHIFT 8
#define FIXED_ONE (1 << FIXED_SHIFT)
#define INT_TO_FIXED(x) ((x) * FIXED_ONE)
#define FIXED_TO_INT(x) ((x) >> 8)
#define FLOAT_TO_FIXED(x) ((int16_t)((x) * FIXED_ONE))
#define ABS(x) (((x) < 0) ? -(x) : (x))
#define FIXED_ANGLE_MAX 256
#define FIXED_ANGLE_WRAP(x) ((x) & 255)
#define FIXED_ANGLE_45 (FIXED_ANGLE_90 / 2)
#define FIXED_ANGLE_90 (FIXED_ANGLE_MAX / 4)
#define FIXED_ANGLE_180 (FIXED_ANGLE_90 * 2)
#define FIXED_ANGLE_270 (FIXED_ANGLE_90 * 3)
#define FIXED_ANGLE_TO_RADIANS(x) ((x) * (2.0f * 3.141592654f / FIXED_ANGLE_MAX))
extern const int16_t sinTable[FIXED_ANGLE_MAX] PROGMEM;
inline int16_t FixedSin(uint8_t angle)
{
return pgm_read_word(&sinTable[angle]);
}
inline int16_t FixedCos(uint8_t angle)
{
return pgm_read_word(&sinTable[FIXED_ANGLE_WRAP(FIXED_ANGLE_90 - angle)]);
}
uint16_t Random();
void SeedRandom(uint16_t seed);