Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | pmbaty | 1 | #include "vector.h" |
2 | #include "harness/trace.h" |
||
3 | #include <math.h> |
||
4 | |||
5 | |||
6 | #define BR_MAC2(A, B, C, D) ((A) * (B) + (C) * (D)) |
||
7 | #define BR_MAC4(A, B, C, D, E, F, G, H) ((A) * (B) + (C) * (D) + (E) * (F) + (G) * (H)) |
||
8 | |||
9 | // IDA: void __cdecl BrVector2Copy(br_vector2 *v1, br_vector2 *v2) |
||
10 | void BrVector2Copy(br_vector2* v1, br_vector2* v2) { |
||
11 | LOG_TRACE("(%p, %p)", v1, v2); |
||
12 | |||
13 | v1->v[0] = v2->v[0]; |
||
14 | v1->v[1] = v2->v[1]; |
||
15 | } |
||
16 | |||
17 | // IDA: void __cdecl BrVector2Set(br_vector2 *v1, br_scalar s1, br_scalar s2) |
||
18 | void BrVector2Set(br_vector2* v1, br_scalar s1, br_scalar s2) { |
||
19 | LOG_TRACE("(%p, %f, %f)", v1, s1, s2); |
||
20 | |||
21 | v1->v[0] = s1; |
||
22 | v1->v[1] = s2; |
||
23 | } |
||
24 | |||
25 | // IDA: void __cdecl BrVector2SetInt(br_vector2 *v1, int i1, int i2) |
||
26 | void BrVector2SetInt(br_vector2* v1, int i1, int i2) { |
||
27 | LOG_TRACE("(%p, %d, %d)", v1, i1, i2); |
||
28 | |||
29 | v1->v[0] = BR_SCALAR(i1); |
||
30 | v1->v[1] = BR_SCALAR(i2); |
||
31 | } |
||
32 | |||
33 | // IDA: void __cdecl BrVector2SetFloat(br_vector2 *v1, float f1, float f2) |
||
34 | void BrVector2SetFloat(br_vector2* v1, float f1, float f2) { |
||
35 | LOG_TRACE("(%p, %f, %f)", v1, f1, f2); |
||
36 | |||
37 | v1->v[0] = f1; |
||
38 | v1->v[1] = f2; |
||
39 | } |
||
40 | |||
41 | // IDA: void __cdecl BrVector2Negate(br_vector2 *v1, br_vector2 *v2) |
||
42 | void BrVector2Negate(br_vector2* v1, br_vector2* v2) { |
||
43 | LOG_TRACE("(%p, %p)", v1, v2); |
||
44 | |||
45 | v1->v[0] = -v2->v[0]; |
||
46 | v1->v[1] = -v2->v[1]; |
||
47 | } |
||
48 | |||
49 | // IDA: void __cdecl BrVector2Add(br_vector2 *v1, br_vector2 *v2, br_vector2 *v3) |
||
50 | void BrVector2Add(br_vector2* v1, br_vector2* v2, br_vector2* v3) { |
||
51 | LOG_TRACE("(%p, %p, %p)", v1, v2, v3); |
||
52 | |||
53 | v1->v[0] = v2->v[0] + v3->v[0]; |
||
54 | v1->v[1] = v2->v[1] + v3->v[1]; |
||
55 | } |
||
56 | |||
57 | // IDA: void __cdecl BrVector2Accumulate(br_vector2 *v1, br_vector2 *v2) |
||
58 | void BrVector2Accumulate(br_vector2* v1, br_vector2* v2) { |
||
59 | LOG_TRACE("(%p, %p)", v1, v2); |
||
60 | |||
61 | v1->v[0] += v2->v[0]; |
||
62 | v1->v[1] += v2->v[1]; |
||
63 | } |
||
64 | |||
65 | // IDA: void __cdecl BrVector2Sub(br_vector2 *v1, br_vector2 *v2, br_vector2 *v3) |
||
66 | void BrVector2Sub(br_vector2* v1, br_vector2* v2, br_vector2* v3) { |
||
67 | LOG_TRACE("(%p, %p, %p)", v1, v2, v3); |
||
68 | |||
69 | v1->v[0] = v2->v[0] - v3->v[0]; |
||
70 | v1->v[1] = v2->v[1] - v3->v[1]; |
||
71 | } |
||
72 | |||
73 | // IDA: void __cdecl BrVector2Scale(br_vector2 *v1, br_vector2 *v2, br_scalar s) |
||
74 | void BrVector2Scale(br_vector2* v1, br_vector2* v2, br_scalar s) { |
||
75 | LOG_TRACE("(%p, %p, %f)", v1, v2, s); |
||
76 | |||
77 | v1->v[0] = v2->v[0] * s; |
||
78 | v1->v[1] = v2->v[1] * s; |
||
79 | } |
||
80 | |||
81 | // IDA: void __cdecl BrVector2InvScale(br_vector2 *v1, br_vector2 *v2, br_scalar s) |
||
82 | void BrVector2InvScale(br_vector2* v1, br_vector2* v2, br_scalar s) { |
||
83 | LOG_TRACE("(%p, %p, %f)", v1, v2, s); |
||
84 | |||
85 | v1->v[0] = v2->v[0] / s; |
||
86 | v1->v[1] = v2->v[1] / s; |
||
87 | } |
||
88 | |||
89 | // IDA: br_scalar __cdecl BrVector2Dot(br_vector2 *v1, br_vector2 *v2) |
||
90 | br_scalar BrVector2Dot(br_vector2* v1, br_vector2* v2) { |
||
91 | LOG_TRACE("(%p, %p)", v1, v2); |
||
92 | |||
93 | return BR_MAC2(v1->v[0], v2->v[0], v1->v[1], v2->v[1]); |
||
94 | } |
||
95 | |||
96 | // IDA: br_scalar __cdecl BrVector2Length(br_vector2 *v1) |
||
97 | br_scalar BrVector2Length(br_vector2* v1) { |
||
98 | LOG_TRACE("(%p)", v1); |
||
99 | |||
100 | return sqrtf(BR_MAC2(v1->v[0], v1->v[0], v1->v[1], v1->v[1])); |
||
101 | } |
||
102 | |||
103 | // IDA: br_scalar __cdecl BrVector2LengthSquared(br_vector2 *v1) |
||
104 | br_scalar BrVector2LengthSquared(br_vector2* v1) { |
||
105 | LOG_TRACE("(%p)", v1); |
||
106 | |||
107 | return BR_MAC2(v1->v[0], v1->v[0], v1->v[1], v1->v[1]); |
||
108 | } |
||
109 | |||
110 | // IDA: void __cdecl BrVector3Copy(br_vector3 *v1, br_vector3 *v2) |
||
111 | void BrVector3Copy(br_vector3* v1, br_vector3* v2) { |
||
112 | LOG_TRACE("(%p, %p)", v1, v2); |
||
113 | |||
114 | v1->v[0] = v2->v[0]; |
||
115 | v1->v[1] = v2->v[1]; |
||
116 | v1->v[2] = v2->v[2]; |
||
117 | } |
||
118 | |||
119 | // IDA: void __cdecl BrVector3Set(br_vector3 *v1, br_scalar s1, br_scalar s2, br_scalar s3) |
||
120 | void BrVector3Set(br_vector3* v1, br_scalar s1, br_scalar s2, br_scalar s3) { |
||
121 | LOG_TRACE("(%p, %f, %f, %f)", v1, s1, s2, s3); |
||
122 | |||
123 | v1->v[0] = s1; |
||
124 | v1->v[1] = s2; |
||
125 | v1->v[2] = s3; |
||
126 | } |
||
127 | |||
128 | // IDA: void __cdecl BrVector3SetInt(br_vector3 *v1, int i1, int i2, int i3) |
||
129 | void BrVector3SetInt(br_vector3* v1, int i1, int i2, int i3) { |
||
130 | LOG_TRACE("(%p, %d, %d, %d)", v1, i1, i2, i3); |
||
131 | |||
132 | v1->v[0] = BR_SCALAR(i1); |
||
133 | v1->v[1] = BR_SCALAR(i2); |
||
134 | v1->v[2] = BR_SCALAR(i3); |
||
135 | } |
||
136 | |||
137 | // IDA: void __cdecl BrVector3SetFloat(br_vector3 *v1, float f1, float f2, float f3) |
||
138 | void BrVector3SetFloat(br_vector3* v1, float f1, float f2, float f3) { |
||
139 | LOG_TRACE8("(%p, %f, %f, %f)", v1, f1, f2, f3); |
||
140 | |||
141 | v1->v[0] = BR_SCALAR(f1); |
||
142 | v1->v[1] = BR_SCALAR(f2); |
||
143 | v1->v[2] = BR_SCALAR(f3); |
||
144 | } |
||
145 | |||
146 | // IDA: void __cdecl BrVector3Negate(br_vector3 *v1, br_vector3 *v2) |
||
147 | void BrVector3Negate(br_vector3* v1, br_vector3* v2) { |
||
148 | LOG_TRACE("(%p, %p)", v1, v2); |
||
149 | |||
150 | v1->v[0] = -v2->v[0]; |
||
151 | v1->v[1] = -v2->v[1]; |
||
152 | v1->v[2] = -v2->v[2]; |
||
153 | } |
||
154 | |||
155 | // IDA: void __cdecl BrVector3Add(br_vector3 *v1, br_vector3 *v2, br_vector3 *v3) |
||
156 | void BrVector3Add(br_vector3* v1, br_vector3* v2, br_vector3* v3) { |
||
157 | LOG_TRACE("(%p, %p, %p)", v1, v2, v3); |
||
158 | |||
159 | v1->v[0] = v2->v[0] + v3->v[0]; |
||
160 | v1->v[1] = v2->v[1] + v3->v[1]; |
||
161 | v1->v[2] = v2->v[2] + v3->v[2]; |
||
162 | } |
||
163 | |||
164 | // IDA: void __cdecl BrVector3Accumulate(br_vector3 *v1, br_vector3 *v2) |
||
165 | void BrVector3Accumulate(br_vector3* v1, br_vector3* v2) { |
||
166 | LOG_TRACE10("(%p, %p)", v1, v2); |
||
167 | |||
168 | v1->v[0] += v2->v[0]; |
||
169 | v1->v[1] += v2->v[1]; |
||
170 | v1->v[2] += v2->v[2]; |
||
171 | } |
||
172 | |||
173 | // IDA: void __cdecl BrVector3Sub(br_vector3 *v1, br_vector3 *v2, br_vector3 *v3) |
||
174 | void BrVector3Sub(br_vector3* v1, br_vector3* v2, br_vector3* v3) { |
||
175 | LOG_TRACE("(%p, %p, %p)", v1, v2, v3); |
||
176 | |||
177 | v1->v[0] = v2->v[0] - v3->v[0]; |
||
178 | v1->v[1] = v2->v[1] - v3->v[1]; |
||
179 | v1->v[2] = v2->v[2] - v3->v[2]; |
||
180 | } |
||
181 | |||
182 | // IDA: void __cdecl BrVector3Scale(br_vector3 *v1, br_vector3 *v2, br_scalar s) |
||
183 | void BrVector3Scale(br_vector3* v1, br_vector3* v2, br_scalar s) { |
||
184 | LOG_TRACE("(%p, %p, %f)", v1, v2, s); |
||
185 | |||
186 | v1->v[0] = v2->v[0] * s; |
||
187 | v1->v[1] = v2->v[1] * s; |
||
188 | v1->v[2] = v2->v[2] * s; |
||
189 | } |
||
190 | |||
191 | // IDA: void __cdecl BrVector3InvScale(br_vector3 *v1, br_vector3 *v2, br_scalar s) |
||
192 | void BrVector3InvScale(br_vector3* v1, br_vector3* v2, br_scalar s) { |
||
193 | LOG_TRACE("(%p, %p, %f)", v1, v2, s); |
||
194 | |||
195 | v1->v[0] = v2->v[0] / s; |
||
196 | v1->v[1] = v2->v[1] / s; |
||
197 | v1->v[2] = v2->v[2] / s; |
||
198 | } |
||
199 | |||
200 | // IDA: br_scalar __cdecl BrVector3Dot(br_vector3 *v1, br_vector3 *v2) |
||
201 | br_scalar BrVector3Dot(br_vector3* v1, br_vector3* v2) { |
||
202 | LOG_TRACE("(%p, %p)", v1, v2); |
||
203 | |||
204 | return BR_MAC3(v1->v[0], v2->v[0], v1->v[1], v2->v[1], v1->v[2], v2->v[2]); |
||
205 | } |
||
206 | |||
207 | // IDA: void __cdecl BrVector3Cross(br_vector3 *v1, br_vector3 *v2, br_vector3 *v3) |
||
208 | void BrVector3Cross(br_vector3* v1, br_vector3* v2, br_vector3* v3) { |
||
209 | LOG_TRACE("(%p, %p, %p)", v1, v2, v3); |
||
210 | |||
211 | v1->v[0] = v2->v[1] * v3->v[2] - v2->v[2] * v3->v[1]; |
||
212 | v1->v[1] = v2->v[2] * v3->v[0] - v2->v[0] * v3->v[2]; |
||
213 | v1->v[2] = v2->v[0] * v3->v[1] - v2->v[1] * v3->v[0]; |
||
214 | } |
||
215 | |||
216 | // IDA: br_scalar __cdecl BrVector3Length(br_vector3 *v1) |
||
217 | br_scalar BrVector3Length(br_vector3* v1) { |
||
218 | LOG_TRACE("(%p)", v1); |
||
219 | |||
220 | return sqrtf(BR_MAC3(v1->v[0], v1->v[0], v1->v[1], v1->v[1], v1->v[2], v1->v[2])); |
||
221 | } |
||
222 | |||
223 | // IDA: br_scalar __cdecl BrVector3LengthSquared(br_vector3 *v1) |
||
224 | br_scalar BrVector3LengthSquared(br_vector3* v1) { |
||
225 | LOG_TRACE("(%p)", v1); |
||
226 | |||
227 | return BR_MAC3(v1->v[0], v1->v[0], v1->v[1], v1->v[1], v1->v[2], v1->v[2]); |
||
228 | } |
||
229 | |||
230 | // IDA: void __cdecl BrVector3Normalise(br_vector3 *v1, br_vector3 *v2) |
||
231 | void BrVector3Normalise(br_vector3* v1, br_vector3* v2) { |
||
232 | br_scalar scale; |
||
233 | LOG_TRACE10("(%p, %p)", v1, v2); |
||
234 | |||
235 | scale = BR_LENGTH3(v2->v[0], v2->v[1], v2->v[2]); |
||
236 | |||
237 | if (scale > BR_SCALAR_EPSILON * 2) { |
||
238 | v1->v[0] = v2->v[0] / scale; |
||
239 | v1->v[1] = v2->v[1] / scale; |
||
240 | v1->v[2] = v2->v[2] / scale; |
||
241 | |||
242 | } else { |
||
243 | v1->v[0] = BR_SCALAR(1.0); |
||
244 | v1->v[1] = BR_SCALAR(0.0); |
||
245 | v1->v[2] = BR_SCALAR(0.0); |
||
246 | } |
||
247 | } |
||
248 | |||
249 | // IDA: void __cdecl BrVector3NormaliseLP(br_vector3 *v1, br_vector3 *v2) |
||
250 | void BrVector3NormaliseLP(br_vector3* v1, br_vector3* v2) { |
||
251 | br_scalar scale; |
||
252 | LOG_TRACE("(%p, %p)", v1, v2); |
||
253 | |||
254 | scale = 1.f / sqrtf(BR_MAC3(v2->v[0], v2->v[0], v2->v[1], v2->v[1], v2->v[2], v2->v[2])); |
||
255 | if (scale != 0.f) { |
||
256 | v1->v[0] = v2->v[0] * scale; |
||
257 | v1->v[1] = v2->v[1] * scale; |
||
258 | v1->v[2] = v2->v[2] * scale; |
||
259 | } |
||
260 | } |
||
261 | |||
262 | // IDA: br_scalar __cdecl BrVector4Dot(br_vector4 *v1, br_vector4 *v2) |
||
263 | br_scalar BrVector4Dot(br_vector4* v1, br_vector4* v2) { |
||
264 | LOG_TRACE("(%p, %p)", v1, v2); |
||
265 | |||
266 | return BR_MAC4(v1->v[0], v2->v[0], v1->v[1], v2->v[1], v1->v[2], v2->v[2], v1->v[3], v2->v[3]); |
||
267 | } |
||
268 | |||
269 | // IDA: void __cdecl BrVector4Copy(br_vector4 *v1, br_vector4 *v2) |
||
270 | void BrVector4Copy(br_vector4* v1, br_vector4* v2) { |
||
271 | LOG_TRACE("(%p, %p)", v1, v2); |
||
272 | |||
273 | v1->v[0] = v2->v[0]; |
||
274 | v1->v[1] = v2->v[1]; |
||
275 | v1->v[2] = v2->v[2]; |
||
276 | v1->v[3] = v2->v[3]; |
||
277 | } |
||
278 | |||
279 | // IDA: br_scalar __usercall BrFVector2Dot@<ST0>(br_fvector2 *v1@<EAX>, br_vector2 *v2@<EDX>) |
||
280 | br_scalar BrFVector2Dot(br_fvector2* v1, br_vector2* v2) { |
||
281 | LOG_TRACE("(%p, %p)", v1, v2); |
||
282 | |||
283 | return BR_MAC2(v1->v[0], v2->v[0], v1->v[1], v2->v[1]); |
||
284 | } |
||
285 | |||
286 | // IDA: void __usercall BrFVector3Copy(br_fvector3 *v1@<EAX>, br_vector3 *v2@<EDX>) |
||
287 | void BrFVector3Copy(br_fvector3* v1, br_vector3* v2) { |
||
288 | LOG_TRACE("(%p, %p)", v1, v2); |
||
289 | |||
290 | v1->v[0] = v2->v[0]; |
||
291 | v1->v[1] = v2->v[1]; |
||
292 | v1->v[2] = v2->v[2]; |
||
293 | } |
||
294 | |||
295 | // IDA: void __usercall BrVector3ScaleF(br_vector3 *v1@<EAX>, br_fvector3 *v2@<EDX>, br_scalar s) |
||
296 | void BrVector3ScaleF(br_vector3* v1, br_fvector3* v2, br_scalar s) { |
||
297 | LOG_TRACE("(%p, %p, %f)", v1, v2, s); |
||
298 | |||
299 | v1->v[0] = v2->v[0] * s; |
||
300 | v1->v[1] = v2->v[1] * s; |
||
301 | v1->v[2] = v2->v[2] * s; |
||
302 | } |
||
303 | |||
304 | // IDA: br_scalar __usercall BrFVector3Dot@<ST0>(br_fvector3 *v1@<EAX>, br_vector3 *v2@<EDX>) |
||
305 | br_scalar BrFVector3Dot(br_fvector3* v1, br_vector3* v2) { |
||
306 | LOG_TRACE("(%p, %p)", v1, v2); |
||
307 | |||
308 | return BR_MAC3(v1->v[0], v2->v[0], v1->v[1], v2->v[1], v1->v[2], v2->v[2]); |
||
309 | } |
||
310 | |||
311 | // IDA: void __usercall BrFVector3Normalise(br_fvector3 *v1@<EAX>, br_vector3 *v2@<EDX>) |
||
312 | void BrFVector3Normalise(br_fvector3* v1, br_vector3* v2) { |
||
313 | br_scalar scale; |
||
314 | LOG_TRACE("(%p, %p)", v1, v2); |
||
315 | |||
316 | scale = sqrtf(BR_MAC3(v2->v[0], v2->v[0], v2->v[1], v2->v[1], v2->v[2], v2->v[2])); |
||
317 | if (scale != 0.f) { |
||
318 | scale = 1.f / scale; |
||
319 | v1->v[0] = v2->v[0] * scale; |
||
320 | v1->v[1] = v2->v[1] * scale; |
||
321 | v1->v[2] = v2->v[2] * scale; |
||
322 | } else { |
||
323 | v1->v[0] = 1.f; |
||
324 | v1->v[1] = 0.f; |
||
325 | v1->v[2] = 0.f; |
||
326 | } |
||
327 | } |
||
328 | |||
329 | // IDA: void __usercall BrFVector3NormaliseLP(br_fvector3 *v1@<EAX>, br_vector3 *v2@<EDX>) |
||
330 | void BrFVector3NormaliseLP(br_fvector3* v1, br_vector3* v2) { |
||
331 | br_scalar scale; |
||
332 | LOG_TRACE("(%p, %p)", v1, v2); |
||
333 | |||
334 | scale = 1.f / sqrtf(BR_MAC3(v2->v[0], v2->v[0], v2->v[1], v2->v[1], v2->v[2], v2->v[2])); |
||
335 | v1->v[0] = v2->v[0] * scale; |
||
336 | v1->v[1] = v2->v[1] * scale; |
||
337 | v1->v[2] = v2->v[2] * scale; |
||
338 | } |
||
339 | |||
340 | // IDA: void __cdecl BrVector2Normalise(br_vector2 *v1, br_vector2 *v2) |
||
341 | void BrVector2Normalise(br_vector2* v1, br_vector2* v2) { |
||
342 | br_scalar scale; |
||
343 | LOG_TRACE("(%p, %p)", v1, v2); |
||
344 | |||
345 | scale = sqrtf(BR_MAC2(v2->v[0], v2->v[0], v2->v[1], v2->v[1])); |
||
346 | if (scale > 2.3841858e-7f) { |
||
347 | scale = 1.f / scale; |
||
348 | v1->v[0] = v2->v[0] * scale; |
||
349 | v1->v[1] = v2->v[1] * scale; |
||
350 | |||
351 | } else { |
||
352 | v1->v[0] = 1.f; |
||
353 | v1->v[1] = 0.f; |
||
354 | } |
||
355 | } |