forked from KapLex/PGE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpgeMath.h
458 lines (403 loc) · 9.04 KB
/
pgeMath.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
/*
* pgeMath.h: Header for VFPU math operations
*
* This file is part of "Phoenix Game Engine".
*
* Copyright (C) 2008 Phoenix Game Engine
* Copyright (C) 2008 InsertWittyName <[email protected]>
* Copyright (C) 2008 MK2k <[email protected]>
*
* Phoenix Game Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Phoenix Game Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Phoenix Game Engine. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef __PGEMATH_H__
#define __PGEMATH_H__
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup pgeMath VFPU Math Library
* @{
*/
#include <psptypes.h>
/**
* Another rect datatype
*/
typedef struct
{
float x1, y1, x2, y2;
int clean;
} pgeRect2;
/**
* Calculate absolute value
*
* @param x - Input
*/
float pgeMathAbs(float x);
/**
* Round value up
*
* @param x - Input
*/
float pgeMathCeil(float x);
/**
* Round value down
*
* @param x - Input
*/
float pgeMathFloor(float x);
/**
* Calculate inverse tangent (arctan)
*
* @param x - Input in radians
*/
float pgeMathAtan(float x);
/**
* Calculate inverse tangent, with quadrant fix-up
*
* @param y - Input in radians
*
* @param x - Input in radians
*/
float pgeMathAtan2(float y, float x);
/**
* Calculate square root
*
* @param x - Input
*/
float pgeMathSqrt(float x);
/**
* Calculate cosine
*
* @param x - Input in radians
*/
float pgeMathCos(float rad);
/**
* Calculate sine
*
* @param x - Input in radians
*/
float pgeMathSin(float rad);
/**
* Calculate inverse cosine (arccos)
*
* @param x - Input in radians
*/
float pgeMathAcos(float x);
/**
* Calculate inverse sine (arcsin)
*
* @param x - Input in radians
*/
float pgeMathAsin(float x);
/**
* Calculate hyperbolic cosine
*
* @param x - Input in radians
*/
float pgeMathCosh(float x);
/**
* Calculate exponent
*
* @param x - Input in radians
*/
float pgeMathExp(float x);
/**
* Calculate maximum numeric value
*
* @param x - Input
*
* @param y - Input
*/
float pgeMathFmax(float x, float y);
/**
* Calculate minimum numeric value
*
* @param x - Input
*
* @param y - Input
*/
float pgeMathFmin(float x, float y);
/**
* Calculate floating point remainder of x/y
*
* @param x - Input
*
* @param y - Input
*/
float pgeMathFmod(float x, float y);
/**
* Calculate natural logarithm
*
* @param x - Input in radians
*/
float pgeMathLog(float x);
/**
* Calculate base 2 logarithm
*
* @param x - Input in radians
*/
float pgeMathLog2(float x);
/**
* Calculate base 10 logarithm
*
* @param x - Input in radians
*/
float pgeMathLog10(float x);
/**
* Calculate x raised to the power of y
*
* @param x - Number to raise power of
*
* @param y - Power to raise x by
*/
float pgeMathPow(float x, float y);
/**
* Calculate 2 raised to the power of x
*
* @param x - Input
*/
float pgeMathPow2(float x);
/**
* Round to nearest value
*
* @param x - Input
*/
float pgeMathRound(float x);
/**
* Round towards 0
*
* @param x - Input
*/
float pgeMathTrunc(float x);
/**
* Set random generator seed
*
* @param x - Seed value
*/
void pgeMathSrand(unsigned int x);
/**
* Generate random float value
*
* @param min - Minimum value to return
*
* @param max - Maximum value to return
*
* @returns A value between min and max
*/
float pgeMathRandFloat(float min, float max);
/**
* Generate random int value
*
* @param min - Minimum value to return
*
* @param max - Maximum value to return
*
* @returns A value between min and max
*/
int pgeMathRandInt(float min, float max);
/**
* Calculate sine and cosine
*
* @param r - Input in radians
*
* @param s - Pointer to a float for sin result
*
* @param c - pointer to a float for cos result
*/
void pgeMathSincos(float r, float *s, float *c);
/**
* Calculate hyperbolic sine
*
* @param x - Input in radians
*/
float pgeMathSinh(float x);
/**
* Calculate tangent
*
* @param x - Input in radians
*/
float pgeMathTan(float x);
/**
* Calculate hyperbolic tangent
*
* @param x - Input in radians
*/
float pgeMathTanh(float x);
/**
* Calculate inverse square root (1/sqrt(x))
*
* @param x - Input value
*/
float pgeMathInvSqrt(float x);
/**
* Calculate radian angle from euler angle
*
* @param x - Input value in degrees
*/
float pgeMathDegToRad(float x);
/**
* Calculate euler angle from radian angle
*
* @param x - Input value in degrees
*/
float pgeMathRadToDeg(float x);
/**
* Normalize an ::ScePSPFVector3
*
* @param result - pointer to an ::ScePSPFVector3 the result gets stored in
*
* @param vec - pointer to an ::ScePSPFVector3 to be normalized
*
* @returns a pointer to an ::ScePSPFVector3 as result
*/
ScePspFVector3 *pgeMathVecNormalize3f(ScePspFVector3 *result, const ScePspFVector3 *vec);
/**
* Add two ::ScePSPFVector3
*
* @param result - pointer to an ::ScePSPFVector3 the result gets stored in
*
* @param vec1 - pointer to an ::ScePSPFVector3 to be added
*
* @param vec2 - pointer to an ::ScePSPFVector3 to be added
*
* @returns a pointer to an ::ScePSPFVector3 as result
*/
ScePspFVector3 *pgeMathVecAdd3f(ScePspFVector3 *result, const ScePspFVector3 *vec1, const ScePspFVector3 *vec2);
/**
* Subtract a ::ScePSPFVector3 from another ::ScePSPFVector3
*
* @param result - pointer to an ::ScePSPFVector3 the result gets stored in
*
* @param vec1 - pointer to an ::ScePSPFVector3 as minuend
*
* @param vec2 - pointer to an ::ScePSPFVector3 as subtrahend
*
* @returns a pointer to an ::ScePSPFVector3 as result
*/
ScePspFVector3 *pgeMathVecSub3f(ScePspFVector3 *result, const ScePspFVector3 *vec1, const ScePspFVector3 *vec2);
/**
* Compare two ::ScePSPFVector3
*
* @param vec1 - pointer to an ::ScePSPFVector3 for comparison
*
* @param vec2 - pointer to an ::ScePSPFVector3 for comparison
*
* @returns 1 if vec1 == vec2, else 0
*/
int pgeMathVecCompare3f(const ScePspFVector3 *vec1, const ScePspFVector3 *vec2);
/**
* Scale a ::ScePSPFVector3 by a scalar
*
* @param result - pointer to an ::ScePSPFVector3 the result gets stored in
*
* @param vec - pointer to an ::ScePSPFVector3 for multiplication
*
* @param scalar - float for multiplication
*
* @returns a pointer to an ::ScePSPFVector3 as result
*/
ScePspFVector3 *pgeMathVecScale3f(ScePspFVector3 *result, const ScePspFVector3 *vec, float scalar);
/**
* Calculate the dot product of two ::ScePSPFVector3
*
* @param vec1 - pointer to an ::ScePSPFVector3 as Input
*
* @param vec2 - pointer to an ::ScePSPFVector3 as Input
*
* @returns float result of the dot product of vec1 and vec2
*/
float pgeMathVecDot3f(const ScePspFVector3 *vec1, const ScePspFVector3 *vec2);
/**
* Calculate the length of a ::ScePSPFVector3
*
* @param vec - pointer to an ::ScePSPFVector3 as Input
*
* @returns float result of the length calculation of vec
*/
float pgeMathVecLength3f(const ScePspFVector3 *vec);
/**
* Calculate the angle between two ::ScePSPFVector3
*
* @param vec1 - pointer to an ::ScePSPFVector3 as Input
*
* @param vec2 - pointer to an ::ScePSPFVector3 as Input
*
* @returns float result of the dot product of vec1 and vec2
*/
float pgeMathVecAngle3f(const ScePspFVector3 *vec1, const ScePspFVector3 *vec2);
/**
* Rotate a ::ScePSPFVector3 about the Z-axis
*
* @param vec - pointer to an ::ScePSPFVector3 as Input
*
* @param a - float Input angle in radians
*
* @param result - pointer to an ::ScePSPFVector3 the result gets stored in
*
* @returns pointer to the ::ScePSPFVector3 result
*/
ScePspFVector3 *pgeMathVecRotateZ3f(const ScePspFVector3 *vec, float a, ScePspFVector3 *result);
/**
* Clear a ::pgeRect2
*
* @param rect - pointer to a ::pgeRect2 as Input
*/
void pgeMathRectClear(pgeRect2 *rect);
/**
* Set the coordinates of a ::pgeRect2
*
* @param rect - pointer to a ::pgeRect2 to be processed
*
* @param x - x coordinate of the center
*
* @param y - y coordinate of the center
*
* @param r - radius of the rect's inner circle
*/
void pgeMathRectSetRadius(pgeRect2 *rect, float x, float y, float r);
/**
* Encapsulate a point into a ::pgeRect2
*
* @param rect - pointer to a ::pgeRect2 to be processed
*
* @param x - float x coordinate
*
* @param y - float y coordinate
*/
void pgeMathRectEncapsulate(pgeRect2 *rect, float x, float y);
/**
* Test if a point lies within a ::pgeRect2
*
* @param rect - pointer to a ::pgeRect2 as Input
*
* @param x - float x coordinate
*
* @param y - float y coordinate
*
* @returns int 1 if x,y is withing rect, else 0
*/
int pgeMathRectTestPoint(pgeRect2 *rect, float x, float y);
/**
* Test if two ::pgeRect2 intersect
*
* @param rect1 - pointer to a ::pgeRect2 as Input
*
* @param rect2 - pointer to a ::pgeRect2 as Input
*
* @returns int 1 if rect1 intersects rect2, else 0
*/
int pgeMathRectIntersect(pgeRect2 *rect1, pgeRect2 *rect2);
/** @} */
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // __PGEMATH_H__