fork/training-mode-ce

git clone https://git.julia.blue/fork/training-mode-ce

AitchMerge pull request #305 from NickCondron/wda62c21f

techchase-camera
2.5 KiB77 linesraw
1#ifndef MEX_H_MATH
2#define MEX_H_MATH
3
4#include "structs.h"
5#include "datatypes.h"
6
7#define HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow
8#define INFINITY ((float)(HUGE_ENUF * HUGE_ENUF))
9#define M_PI (3.14159265358979323846)
10#define M_1DEGREE (0.0174533)
11#define M_NAN ((float)(INFINITY * 0.0F))
12
13static inline float fabs(float v)
14{
15    if (v < 0.0f)
16        return -v;
17    else
18        return v;
19}
20
21static inline float sign(float v)
22{
23    if (v >= 0.0f)
24        return 1.0f;
25    else
26        return -1.0f;
27}
28
29static inline float squaref(float v)
30{
31    return v*v;
32}
33
34static inline float Vec2_Magnitude(Vec2 *v)
35{
36    return fabs(v->X) + fabs(v->Y);
37}
38
39/*** Functions ***/
40// float fmod(float a, float b);
41float atan(float in);
42float atan2(float y, float x);
43float sin(float x);
44float cos(float x);
45void MTXOrtho(Mtx44 m, f32 t, f32 b, f32 l, f32 r, f32 n, f32 f); //
46void MTXLookAt(Mtx *dest, Vec3 *eye, Vec3 *up, Vec3 *target);
47void MTXRotAxisRad(Mtx *m, Vec3 *axis, float rad); // Sets a matrix for rotation about an arbitrary axis whose ( x, y, z ) components are specified by axis.
48void MTXMultVec(Mtx *m, Vec3 *src, Vec3 *dst);     // Post-multiplies a 3D vector or 3D point by a matrix ( m x src = dst ).
49void MTXLightPerspective(Mtx *m, float fovy, float aspect, float scaleS, float scaleT, float transS, float transT);
50void VECNormalize(Vec3 *src, Vec3 *dest);
51void VECScale(Vec3 *src, Vec3 *dst, float scale);
52void VECAdd(Vec3 *a, Vec3 *b, Vec3 *ab);
53void VECSubtract(Vec3 *a, Vec3 *b, Vec3 *a_b);
54void PSMTXIdentity(Mtx *dest);
55void PSMTXCopy(Mtx *src, Mtx *dest);
56void PSMTXConcat(Mtx *a, Mtx *b, Mtx *ab);
57void VECMultAndAdd(Vec3 *a, Vec3 *b);
58float VECDotProduct(Vec3 *a, Vec3 *b);
59void VECCrossProduct(Vec3 *a, Vec3 *b, Vec3 *axb);
60float Vec2_Normalize(Vec2 *v);
61float Vec3_Normalize(Vec3 *v);
62void Vec2_Add(Vec2 *a, Vec2 *b);
63Vec3 *Vec3_CrossDirection(Vec3 *a, Vec3 *b, Vec3 *axb);
64// void MTXQuat(Mtx *m, Vec4 *dest);           // quat to matrix
65void HSD_MkRotationMtx(Mtx *dest, Vec4 *v); // quat to rot matrix
66void HSD_MtxGetScale(Mtx *m, Vec3 *dest);
67void HSD_MtxGetRotation(Mtx *m, Vec3 *dest);
68void HSD_MtxGetTranslate(Mtx *m, Vec3 *dest);
69void HSD_MtxSRT(Mtx *m, Vec3 *scale, Vec3 *rot, Vec3 *trans, int unk);
70void MatToQuat(Mtx *m, Vec4 *dest); // matrix to quat
71float sqrtf(float num);
72void MTXRotRad(Mtx m, char axis, f32 rad);
73float Vec2_CalculateAngle(Vec2 *a, Vec2 *b);
74float Vec3_CalculateAngle(Vec3 *a, Vec3 *b);
75void Vec3_RotateAboutUnitAxis(Vec3 *v, Vec3 *axis, float angle);
76
77#endif