annotate OurMath.cpp @ 2466:5a6cd79069ae

project and filter
author zipi
date Sun, 17 Aug 2014 20:34:56 +0100
parents f4af3b203f65
children
rev   line source
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2378
diff changeset
1 #define _CRTDBG_MAP_ALLOC
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2378
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2378
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2378
diff changeset
4
2331
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
5 #include "OurMath.h"
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
6 #include "MM7_data.h"
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
7
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
8 //----- (00452969) --------------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
9 stru193_math::stru193_math()
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
10 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
11 double v3; // ST18_8@2
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
12
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
13 this->pTanTable[0] = 0;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
14 this->pCosTable[0] = 65536;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
15 this->pInvCosTable[0] = 65536;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
16 for(int i = 1; i < (signed int)this->uIntegerHalfPi; i++)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
17 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
18 v3 = (double)i * 3.141592653589793 / (double)uIntegerPi;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
19 pTanTable[i] = (signed __int64)(tan(v3) * (double)this->pCosTable[0] + 0.5);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
20 pCosTable[i] = (signed __int64)(cos(v3) * (double)this->pCosTable[0] + 0.5);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
21 pInvCosTable[i] = (signed __int64)(1.0 / cos(v3) * (double)this->pCosTable[0] + 0.5);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
22 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
23 for(int i = this->uIntegerHalfPi; i < 520; i++)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
24 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
25 this->pTanTable[i] = 0xEFFFFFFFu;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
26 this->pCosTable[i] = 0;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
27 this->pInvCosTable[i] = 0xEFFFFFFFu;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
28 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
29 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
30
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
31
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
32 //----- (00402CAE) --------------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
33 int stru193_math::Cos(int angle)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
34 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
35 int v2; // eax@1
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
36
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
37 //a2: (angle - uIntegerHalfPi) for sin(angle)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
38 // (angle) for cos(angle)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
39
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
40 v2 = uDoublePiMask & angle;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
41
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
42 if ( v2 > uIntegerPi )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
43 v2 = uIntegerDoublePi - v2;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
44 if ( v2 >= uIntegerHalfPi )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
45 return -pCosTable[uIntegerPi - v2];
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
46 else
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
47 return pCosTable[v2];
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
48 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
49
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
50
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
51 //----- (0045281E) --------------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
52 // Calculates atan2(y/x)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
53 // return value: angle in integer format (multiplier of Pi/1024)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
54 unsigned int stru193_math::Atan2(int x, int y)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
55 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
56 signed int quadrant;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
57 __int64 dividend;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
58 int quotient;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
59 int lowIdx;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
60 int highIdx;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
61 int angle;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
62
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
63 int X = x;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
64 int Y = y;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
65
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
66 if ( abs(X) < 65536 )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
67 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
68 if ( (abs(Y) >> 15) >= abs(X) )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
69 X = 0;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
70 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
71
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
72 if ( !X )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
73 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
74 if ( Y > 0 )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
75 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
76 return uIntegerHalfPi; //Pi/2
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
77 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
78 else
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
79 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
80 return uIntegerHalfPi + uIntegerPi; //3*(Pi/2)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
81 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
82 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
83
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
84 if ( Y )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
85 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
86 if ( X < 0 )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
87 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
88 X = -X;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
89 if ( Y > 0 )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
90 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
91 quadrant = 4;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
92 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
93 else
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
94 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
95 quadrant = 3;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
96 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
97 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
98 else
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
99 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
100 if ( Y > 0 )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
101 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
102 quadrant = 1;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
103 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
104 else
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
105 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
106 quadrant = 2;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
107 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
108 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
109
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
110 if ( Y < 0 )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
111 Y = -Y;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
112
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
113 LODWORD(dividend) = Y << 16;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
114 HIDWORD(dividend) = Y >> 16;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
115 quotient = dividend / X;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
116
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
117 //looks like binary search
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
118 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
119 int i;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
120 highIdx = uIntegerHalfPi;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
121 lowIdx = 0;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
122
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
123 for (i = 0; i < 6; ++i)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
124 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
125 if (quotient <= pTanTable[(lowIdx + highIdx) / 2])
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
126 highIdx = (lowIdx + highIdx) / 2;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
127 else
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
128 lowIdx = (lowIdx + highIdx) / 2;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
129 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
130 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
131
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
132 angle = lowIdx + 1;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
133 while ( angle < (highIdx - 1) && quotient >= pTanTable[angle] )
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
134 ++angle;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
135
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
136 switch (quadrant)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
137 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
138 case 1: //X > 0, Y > 0
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
139 return angle;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
140
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
141 case 2: //X > 0, Y < 0
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
142 return uIntegerDoublePi - angle; //2*Pi - angle
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
143
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
144 case 3: //X > 0, Y < 0
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
145 return uIntegerPi + angle; //Pi + angle
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
146
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
147 case 4: //X < 0, Y > 0
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
148 return uIntegerPi - angle; //Pi - angle
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
149 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
150
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
151 //should newer get here
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
152 return 0;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
153 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
154
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
155 if ( X < 0 ) //Y == 0, X < 0
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
156 return uIntegerPi;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
157
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
158 return 0;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
159 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
160
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
161 //----- (0042EBDB) --------------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
162 int stru193_math::Sin(int angle)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
163 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
164 return Cos(angle - this->uIntegerHalfPi);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
165 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
166
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
167 //----- (0042EBBE) --------------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
168 //----- (004453C0) mm6-----------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
169 //----- (004A1760) mm6_chinese---------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
170 __int64 fixpoint_mul(int a1, int a2)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
171 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
172 return ((__int64)a1 * (__int64)a2) >> 16;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
173 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
174
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
175 __int64 fixpoint_dot(int x1, int x2, int y1, int y2, int z1, int z2)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
176 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
177 return fixpoint_mul(x1, x2) +
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
178 fixpoint_mul(y1, y2) +
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
179 fixpoint_mul(z1, z2);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
180 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
181
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
182 //----- (004A1780) mm6_chinese---------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
183 __int64 fixpoint_div(int a1, int a2)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
184 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
185 return ((__int64)a1 << 16) / a2;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
186 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
187
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
188 __int64 fixpoint_sub_unknown(int a1, int a2)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
189 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
190 return (((__int64)a1 << 16) * a2) >> 16;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
191 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
192
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
193 //----- (0048B561) --------------------------------------------------------
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
194 int fixpoint_from_float(float val)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
195 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
196 // float X.Yf -> int XXXX YYYY
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
197 int left = floorf((val - 0.5f) + 0.5f);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
198 int right = floorf((val - left) * 65536.0f);
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
199 return (left << 16) | right;
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
200 }
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
201
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
202 int fixpoint_from_int(int lhv, int rhv)
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
203 {
9551756f46c4 Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
Grumpy7
parents:
diff changeset
204 return (lhv << 16) | rhv;
2340
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
205 }
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
206
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
207
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
208 //----- (00452A9E) --------------------------------------------------------
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
209 int integer_sqrt(int val)
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
210 {
2378
48dbf99c0f7f spawn_light_elemental cleaned
Ritor1
parents: 2340
diff changeset
211 ///////////////////////////////
48dbf99c0f7f spawn_light_elemental cleaned
Ritor1
parents: 2340
diff changeset
212 //Получение квадратного корня//
48dbf99c0f7f spawn_light_elemental cleaned
Ritor1
parents: 2340
diff changeset
213 ///////////////////////////////
48dbf99c0f7f spawn_light_elemental cleaned
Ritor1
parents: 2340
diff changeset
214
2340
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
215 signed int result; // eax@2
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
216 unsigned int v2; // edx@3
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
217 unsigned int v3; // edi@3
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
218 int v5; // esi@4
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
219
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
220 if (val < 1)
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
221 return val;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
222
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
223 v2 = 0;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
224 v3 = val;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
225 result = 0;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
226 for (uint i = 0; i < 16; ++i)
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
227 {
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
228 result *= 2;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
229 v2 = (v3 >> 30) | 4 * v2;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
230 v5 = 2 * result + 1;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
231 v3 *= 4;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
232 if ( v2 >= v5 )
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
233 {
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
234 ++result;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
235 v2 -= v5;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
236 }
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
237 }
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
238 if ( val - result * result >= (unsigned int)(result - 1) )
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
239 ++result;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
240 return result;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
241 }
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
242
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
243 //----- (00452B2E) --------------------------------------------------------
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
244 int __fastcall GetDiceResult(unsigned int uNumDice, unsigned int uDiceSides)
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
245 {
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
246 int v3; // esi@1
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
247
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
248 v3 = 0;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
249 if ( uDiceSides )
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
250 {
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
251 for ( uint i = 0; i < uNumDice; ++i)
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
252 v3 += rand() % uDiceSides + 1;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
253 return v3;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
254 }
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
255 return 0;
dc822157c98d Moving functions from unsorted_subs.h pt4
Grumpy7
parents: 2331
diff changeset
256 }