Add MUL_Q20

This commit is contained in:
Aetias
2024-05-25 23:15:11 +02:00
parent 908dba5200
commit 67aba5b356
2 changed files with 18 additions and 13 deletions
+16 -13
View File
@@ -11,13 +11,13 @@ typedef s16 q4;
#define INT_TO_Q20(n) ((s32)((n) << 12))
#define FLOAT_TO_Q20(n) ((s32)(((n) * 8192 + 1) / 2))
#define ROUND_Q20(n) (((s32)(n) + 0x800) >> 12)
#define MUL_Q20(a,b) ROUND_Q20((a) * (b))
#define MUL_Q20(a,b) (q20)((((s64)(a)) * ((s64)(b)) + 0x800) >> 12)
#define DEG_TO_ANG(n) ((n) * 0x10000 / 360)
#define SIN(n) (gSinCosTable[2 * ((n) >> 4)])
#define COS(n) (gSinCosTable[2 * ((n) >> 4) + 1])
extern "C" s16 Atan2(s32 x, s32 y);
extern "C" s32 Atan2(s32 x, s32 y);
extern q4 gSinCosTable[];
typedef struct {
@@ -49,17 +49,20 @@ extern "C" q20 Vec3p_Length(Vec3p *a);
extern "C" void Vec3p_Normalize(Vec3p *vec, Vec3p *out);
extern "C" void Vec3p_Axpy(q20 a, Vec3p *x, Vec3p *y, Vec3p *out);
extern "C" q20 Vec3p_Distance(Vec3p *a, Vec3p *b);
inline void Vec3p_Rotate(Vec3p *vec, s16 angle, Vec3p *out) {
q20 sin = SIN(angle);
q20 zSin = MUL_Q20(vec->z, sin);
out->x += zSin;
q20 cos = COS(angle);
q20 zCos = MUL_Q20(vec->z, cos);
out->z += zCos;
q20 xCos = MUL_Q20(vec->x, cos);
out->x += xCos;
q20 xSin = MUL_Q20(vec->x, -sin);
out->z += xSin;
inline void Vec3p_Rotate(Vec3p *vec, q20 sin, q20 cos, Vec3p *out) {
out->x += MUL_Q20(vec->z, sin);
out->z += MUL_Q20(vec->z, cos);
out->x += MUL_Q20(vec->x, cos);
out->z += MUL_Q20(vec->x, -sin);
}
inline void Vec3p_CopyXZ(Vec3p *vec, Vec3p *out) {
q20 z = vec->z;
q20 x = vec->x;
out->x = x;
out->y = 0;
out->z = z;
}
typedef struct {
+2
View File
@@ -1,10 +1,12 @@
#ifndef PH_TYPES_H
#define PH_TYPES_H
typedef unsigned long long u64;
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef long long s64;
typedef int s32;
typedef short s16;
typedef char s8;