2499
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6 #include <utility>
|
|
7
|
|
8 #include "mm7_data.h"
|
|
9 #include "OurMath.h"
|
|
10
|
|
11 //----- (004621DA) --------------------------------------------------------
|
|
12 uint32_t int_get_vector_length(int32_t x, int32_t y, int32_t z)
|
|
13 {
|
|
14 if (x < y)
|
|
15 {
|
|
16 std::swap(x, y);
|
|
17 }
|
|
18 if (x < z)
|
|
19 {
|
|
20 std::swap(x, z);
|
|
21 }
|
|
22 if (y < z)
|
|
23 {
|
|
24 std::swap(y, z);
|
|
25 }
|
|
26
|
|
27 return x + (11 * y >> 5) + (z >> 2);
|
|
28 }
|
|
29
|
|
30 //----- (0044C362) --------------------------------------------------------
|
|
31 template <class T>
|
|
32 void Vec3<T>::Normalize_float()
|
|
33 {
|
|
34 double x = this->x;
|
|
35 double y = this->y;
|
|
36 double z = this->z;
|
|
37 double s = sqrt(x * x + y * y + z * z);
|
|
38
|
|
39 this->x = bankersRounding(x / s);
|
|
40 this->y = bankersRounding(y / s);
|
|
41 this->z = bankersRounding(z / s);
|
|
42 }
|
|
43
|
|
44 //----- (0043AA99) --------------------------------------------------------
|
|
45 template <class T>
|
|
46 void __fastcall Vec3<T>::Rotate(T sDepth, T sRotY, T sRotX, Vec3<T> v, T *outx, T *outy, T *outz)
|
|
47 {
|
|
48 float cosf_x = cosf(3.14159265f * sRotX / 1024.0f),
|
|
49 sinf_x = sinf(3.14159265f * sRotX / 1024.0f),
|
|
50 cosf_y = cosf(3.14159265f * sRotY / 1024.0f),
|
|
51 sinf_y = sinf(3.14159265f * sRotY / 1024.0f);
|
|
52
|
|
53 *outx = v.x + ((unsigned __int64)(sinf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16)));
|
|
54 *outy = v.y + ((unsigned __int64)(cosf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16)));
|
|
55 *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16);
|
|
56 }
|
|
57
|
|
58 //----- (0043AB61) --------------------------------------------------------
|
|
59 template <class T>
|
|
60 void Vec3<T>::Normalize(T *x, T *y, T *z)
|
|
61 {
|
|
62 extern int integer_sqrt(int val);
|
|
63 *x *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
|
|
64 *y *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
|
|
65 *z *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
|
|
66 }
|
|
67
|
|
68 template Vec3<int32_t>;
|
|
69
|
|
70 //----- (004369DB) --------------------------------------------------------
|
|
71 void Vec3_float_::Normalize()
|
|
72 {
|
|
73 this->x = (1.0 / sqrt(this->x * this->x + this->y * this->y + this->z * this->z)) * this->x;
|
|
74 this->y = (1.0 / sqrt(this->x * this->x + this->y * this->y + this->z * this->z)) * this->y;
|
|
75 this->z = (1.0 / sqrt(this->x * this->x + this->y * this->y + this->z * this->z)) * this->z;
|
|
76 } |