-
Notifications
You must be signed in to change notification settings - Fork 344
/
_intmath.hpp
83 lines (64 loc) · 2.34 KB
/
_intmath.hpp
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
// This file is distributed under a BSD license. See LICENSE.txt for details.
#pragma once
#include "_types.hpp"
/****************************************************************************/
#define sFIXONE 0x4000
#define sFIXHALF 0x2000
#define sFIXSHIFT 14
void sInitIntMath2();
struct sIVector3;
struct sSVector3;
struct sISRT;
struct sIMatrix34;
/****************************************************************************/
#if sPLATFORM==sPLAT_PDA && sMOBILE
inline sInt sCountLeadingZeroes(sU32 x) { return _CountLeadingZeros(x); }
#else
sInt sCountLeadingZeroes(sU32 x);
#endif
inline sInt sIMul(sInt a,sInt b) { return (((sS64)a)*b)>>sFIXSHIFT; }
sInt sIntSqrt15D(sU32 r);
sInt sISin(sInt a); // 0..sFIXONE -> -sFIXONE..sFIXONE
sInt sICos(sInt a); // 0..sFIXONE -> -sFIXONE..sFIXONE
/****************************************************************************/
struct sIVector3 // integer vector, usually 1:15:16
{
sInt x,y,z;
void Init(sInt X,sInt Y,sInt Z) { x=X; y=Y; z=Z; }
void Rotate34(const sIMatrix34 &mat);
void Sub(const sIVector3 &a,const sIVector3 &b) { x=a.x-b.x; y=a.y-b.y; z=a.z-b.z; }
void Add(const sIVector3 &a,const sIVector3 &b) { x=a.x+b.x; y=a.y+b.y; z=a.z+b.z; }
void Sub(const sIVector3 &b) { x=x-b.x; y=y-b.y; z=z-b.z; }
void Add(const sIVector3 &b) { x=x+b.x; y=y+b.y; z=z+b.z; }
void AddScale(const sIVector3 &b,sInt s) { x+=sIMul(b.x,s); y+=sIMul(b.y,s); z+=sIMul(b.z,s); }
void Unit();
void Cross(const sIVector3 &a,const sIVector3 &b);
};
struct sSVector3 // short vector, usually 1:1:14
{
sS16 x,y,z;
void Init(sInt X,sInt Y,sInt Z) { x=X; y=Y; z=Z; }
void Init(const sIVector3 &a) { x=a.x; y=a.y; z=a.z; }
};
struct sISRT // srt values to initialize a matrix
{
sIVector3 s;
sIVector3 r;
sIVector3 t;
void Init();
void Fix14();
};
struct sIMatrix34 // a 3d matrix
{
sIVector3 i;
sIVector3 j;
sIVector3 k;
sIVector3 l;
void Init();
void InitEuler(sInt a,sInt b,sInt c);
void InitSRT(sISRT &srt);
void Mul(const sIMatrix34 &a,const sIMatrix34 &b);
void TransR();
};
/****************************************************************************/
/****************************************************************************/