Mercurial > mm7
annotate VectorTypes.cpp @ 2289:60293358b4b3
byte_5111F6 to byte_5111F6_OwnedArtifacts, changed magic numbers to enums in GetItemTextureFilename
author | Grumpy7 |
---|---|
date | Sun, 16 Mar 2014 03:08:26 +0100 |
parents | aff7a7b072b7 |
children | f4af3b203f65 |
rev | line source |
---|---|
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2152
diff
changeset
|
1 #define _CRT_SECURE_NO_WARNINGS |
1513 | 2 #include <utility> |
3 | |
1504 | 4 #include "mm7_data.h" |
2037
7a9477135943
Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents:
1528
diff
changeset
|
5 #include "OurMath.h" |
1504 | 6 |
1513 | 7 //----- (004621DA) -------------------------------------------------------- |
8 uint32_t int_get_vector_length(int32_t x, int32_t y, int32_t z) | |
9 { | |
10 if (x < y) | |
11 { | |
12 std::swap(x, y); | |
13 } | |
14 if (x < z) | |
15 { | |
16 std::swap(x, z); | |
17 } | |
18 if (y < z) | |
19 { | |
20 std::swap(y, z); | |
21 } | |
22 | |
23 return x + (11 * y >> 5) + (z >> 2); | |
24 } | |
25 | |
1504 | 26 //----- (0044C362) -------------------------------------------------------- |
1513 | 27 template <class T> |
28 void Vec3<T>::Normalize_float() | |
1504 | 29 { |
1528 | 30 double x = this->x; |
31 double y = this->y; | |
32 double z = this->z; | |
33 double s = sqrt(x * x + y * y + z * z); | |
1504 | 34 |
1528 | 35 this->x = bankersRounding(x / s); |
36 this->y = bankersRounding(y / s); | |
37 this->z = bankersRounding(z / s); | |
1504 | 38 } |
39 | |
40 //----- (0043AA99) -------------------------------------------------------- | |
1513 | 41 template <class T> |
42 void __fastcall Vec3<T>::Rotate(T sDepth, T sRotY, T sRotX, Vec3<T> v, T *outx, T *outy, T *outz) | |
1504 | 43 { |
44 float cosf_x = cosf(3.14159265f * sRotX / 1024.0f), | |
45 sinf_x = sinf(3.14159265f * sRotX / 1024.0f), | |
46 cosf_y = cosf(3.14159265f * sRotY / 1024.0f), | |
47 sinf_y = sinf(3.14159265f * sRotY / 1024.0f); | |
48 | |
49 *outx = v.x + ((unsigned __int64)(sinf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16))); | |
50 *outy = v.y + ((unsigned __int64)(cosf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16))); | |
51 *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16); | |
52 } | |
53 | |
54 //----- (0043AB61) -------------------------------------------------------- | |
1513 | 55 template <class T> |
56 void Vec3<T>::Normalize(T *x, T *y, T *z) | |
1504 | 57 { |
2152 | 58 extern int integer_sqrt(int val); |
1504 | 59 *x *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1); |
60 *y *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1); | |
61 *z *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1); | |
62 } | |
1513 | 63 |
64 template Vec3<int32_t>; |