A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19*/
20// mathlib.h
21
22//Dan East:
23#include "FixedPointMath.h"
24
25#ifdef USE_PQ_OPT
26typedef int fpvec3[3];
27#endif
28
29typedef fixedpoint_t vec3_FPM_t[3];
30typedef fixedpoint8_24_t vec3_8_24FPM_t[3];
31typedef fixedpoint_t vec5_FPM_t[5];
32
33//End Dan
34
35typedef float vec_t;
36typedef vec_t vec3_t[3];
37typedef vec_t vec5_t[5];
38
39typedef int fixed4_t;
40typedef int fixed8_t;
41typedef int fixed16_t;
42
43#ifndef M_PI
44#define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
45#endif
46
47struct mplane_s;
48
49extern vec3_t vec3_origin;
50extern int nanmask;
51
52#define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
53
54#define DotProduct(x,y) (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])
55#define VectorSubtract(a,b,c) {c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];}
56#define VectorAdd(a,b,c) {c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];}
57#define VectorCopy(a,b) {b[0]=a[0];b[1]=a[1];b[2]=a[2];}
58
59void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc);
60
61vec_t _DotProduct (vec3_t v1, vec3_t v2);
62void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out);
63void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out);
64void _VectorCopy (vec3_t in, vec3_t out);
65
66int VectorCompare (vec3_t v1, vec3_t v2);
67vec_t Length (vec3_t v);
68void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross);
69//void VectorNormalizeNoRet (vec3_t v); // uses finvsqrt
70//float VectorNormalize (vec3_t v); // returns vector length
71
72#pragma GCC diagnostic push
73#pragma GCC diagnostic ignored "-Wstrict-aliasing"
74static inline float InvSqrt( float number ) {
75 long i;
76 float x2, y;
77 const float threehalfs = 1.5F;
78
79 x2 = number * 0.5F;
80 y = number;
81 i = * ( long * ) &y; // evil floating point bit level hacking
82 i = 0x5f3759df - ( i >> 1 ); // what the fuck?
83 y = * ( float * ) &i;
84 y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
85// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
86
87 return y;
88}
89#pragma GCC diagnostic pop
90
91static inline void VectorNormalizeNoRet (vec3_t v)
92{
93 float length, ilength;
94
95 ilength = InvSqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
96
97 v[0] *= ilength;
98 v[1] *= ilength;
99 v[2] *= ilength;
100}
101
102static inline float VectorNormalize (vec3_t v)
103{
104 float length, ilength;
105
106 length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
107 length = sqrt (length); // FIXME
108
109 if (length)
110 {
111 ilength = 1/length;
112 v[0] *= ilength;
113 v[1] *= ilength;
114 v[2] *= ilength;
115 }
116
117 return length;
118
119}
120
121//void VectorInverse (vec3_t v);
122//void VectorScale (vec3_t in, vec_t scale, vec3_t out);
123
124
125static inline void VectorInverse (vec3_t v)
126{
127 v[0] = -v[0];
128 v[1] = -v[1];
129 v[2] = -v[2];
130}
131
132static inline void VectorScale (vec3_t in, vec_t scale, vec3_t out)
133{
134 out[0] = in[0]*scale;
135 out[1] = in[1]*scale;
136 out[2] = in[2]*scale;
137}
138
139
140int Q_log2(int val);
141
142void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
143void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
144
145void FloorDivMod (double numer, double denom, int *quotient,
146 int *rem);
147fixed16_t Invert24To16(fixed16_t val);
148int GreatestCommonDivisor (int i1, int i2);
149
150void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
151int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane);
152float anglemod(float a);
153
154
155
156#define BOX_ON_PLANE_SIDE(emins, emaxs, p) \
157 (((p)->type < 3)? \
158 ( \
159 ((p)->dist <= (emins)[(p)->type])? \
160 1 \
161 : \
162 ( \
163 ((p)->dist >= (emaxs)[(p)->type])?\
164 2 \
165 : \
166 3 \
167 ) \
168 ) \
169 : \
170 BoxOnPlaneSide( (emins), (emaxs), (p)))