-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathutil.c
170 lines (139 loc) · 3.49 KB
/
util.c
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <gcc/math.h>
#include <sce/rand.h>
#include <util.h>
#include <vec.h>
static const float PI = 3.14159265359f;
const int PRIME_MOD = 0x95675;
float RadNormalize(float rad)
{
if ((rad < -PI) || (PI < rad))
{
float modpos = GModPositive(rad + PI, 2 * PI);
rad = modpos - PI;
}
return rad;
}
INCLUDE_ASM(const s32, "P2/util", GLimitAbs);
INCLUDE_ASM(const s32, "P2/util", GSmooth__FfffP3SMPPf);
INCLUDE_ASM(const s32, "P2/util", GSmoothA__FffffP4SMPAPf);
INCLUDE_ASM(const s32, "P2/util", func_001EA720);
float RadSmooth(float radCur, float radTarget, float dt, SMP *psmp, float *pdradNext)
{
float rad;
rad = RadNormalize(radTarget - radCur);
rad = GSmooth(0.0, rad, dt, psmp, pdradNext);
rad = RadNormalize(radCur + rad);
return rad;
}
float RadSmoothA(float radCur, float dradCur, float radTarget, float dt, SMPA *psmpa, float *pdradNext)
{
float rad;
rad = RadNormalize(radTarget - radCur);
rad = GSmoothA(0.0, dradCur, rad, dt, psmpa, pdradNext);
rad = RadNormalize(radCur + rad);
return rad;
}
INCLUDE_ASM(const s32, "P2/util", PosSmooth);
INCLUDE_ASM(const s32, "P2/util", SmoothMatrix);
// Generates a random integer in the range [nLow, nHi]
int NRandInRange(int nLow, int nHi)
{
if (nLow == nHi)
{
return nLow;
}
int randVal = rand();
randVal = randVal % PRIME_MOD;
int range = (nHi - nLow) + 1;
// Return a value within the range [nLow, nHi]
return nLow + (randVal % range);
}
float GRandInRange(float gHi, float gLow)
{
int rand_result;
float delta;
float result;
if (gHi != gLow)
{
rand_result = rand();
delta = gLow - gHi;
result = gHi + delta * (float)rand_result * 4.656613e-10f;
}
else
{
result = gHi;
}
return result;
}
INCLUDE_ASM(const s32, "P2/util", GRandGaussian);
int FFloatsNear(float g1, float g2, float gEpsilon)
{
g2 = g1 - g2;
g1 = g1 > 0.0f ? g1 : -g1;
g2 = g2 > 0.0f ? g2 : -g2;
float x = 1.0f;
x = g1 > x ? g1 : x;
return (g2 / x) < gEpsilon;
}
INCLUDE_ASM(const s32, "P2/util", CSolveQuadratic);
void PrescaleClq(CLQ *pclqSrc, float ru, float du, CLQ *pclqDst)
{
pclqDst->w = pclqSrc->w * ru * ru;
pclqDst->v = (pclqSrc->w + pclqSrc->w) * ru * du + pclqSrc->v * ru;
pclqDst->u = pclqSrc->w * du * du + pclqSrc->v * du + pclqSrc->u;
}
INCLUDE_ASM(const s32, "P2/util", CalculateSinCos__FfPfT1);
INCLUDE_ASM(const s32, "P2/util", GTrunc);
INCLUDE_ASM(const s32, "P2/util", GTrunc1);
float GModPositive(float gDividend, float gDivisor)
{
float result = fmodf(gDividend, gDivisor);
if (result < 0.0f)
{
result += gDivisor;
}
return result;
}
void FitClq(float g0, float g1, float u, float gU, CLQ *pclq)
{
pclq->u = g0;
float f = ((gU - g0) / u - (g1 - g0)) / (u - 1.0f);
pclq->w = f;
pclq->v = (g1 - g0) - f;
}
int FCheckLm(LM *plm, float g)
{
return (plm->gMin < g) && (g < plm->gMax);
}
INCLUDE_ASM(const s32, "P2/util", FCheckAlm);
float GLimitLm(struct LM *plm, float g)
{
if (g < plm->gMin)
{
return plm->gMin;
}
if (g > plm->gMax)
{
return plm->gMax;
}
return g;
}
int SgnCompareG(float *pg1, float *pg2)
{
if (*pg1 > *pg2)
{
return 1;
}
else if (*pg2 > *pg1)
{
return -1;
}
return 0;
}
void Force(void *pv)
{
// Does nothing.
return;
}
INCLUDE_ASM(const s32, "P2/util", MinimizeRange);
INCLUDE_ASM(const s32, "P2/util", func_001EB458);