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
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
2 #include <utility>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
3
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
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
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
6
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
7 //----- (004621DA) --------------------------------------------------------
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
8 uint32_t int_get_vector_length(int32_t x, int32_t y, int32_t z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
9 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
10 if (x < y)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
11 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
12 std::swap(x, y);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
13 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
14 if (x < z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
15 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
16 std::swap(x, z);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
17 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
18 if (y < z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
19 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
20 std::swap(y, z);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
21 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
22
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
23 return x + (11 * y >> 5) + (z >> 2);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
24 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
25
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
26 //----- (0044C362) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
27 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
28 void Vec3<T>::Normalize_float()
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
29 {
1528
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
30 double x = this->x;
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
31 double y = this->y;
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
32 double z = this->z;
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
33 double s = sqrt(x * x + y * y + z * z);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
34
1528
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
35 this->x = bankersRounding(x / s);
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
36 this->y = bankersRounding(y / s);
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
37 this->z = bankersRounding(z / s);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
38 }
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
39
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
40 //----- (0043AA99) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
41 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
42 void __fastcall Vec3<T>::Rotate(T sDepth, T sRotY, T sRotX, Vec3<T> v, T *outx, T *outy, T *outz)
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
43 {
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
44 float cosf_x = cosf(3.14159265f * sRotX / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
45 sinf_x = sinf(3.14159265f * sRotX / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
46 cosf_y = cosf(3.14159265f * sRotY / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
47 sinf_y = sinf(3.14159265f * sRotY / 1024.0f);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
48
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
49 *outx = v.x + ((unsigned __int64)(sinf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16)));
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
50 *outy = v.y + ((unsigned __int64)(cosf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16)));
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
51 *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
52 }
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
53
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
54 //----- (0043AB61) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
55 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
56 void Vec3<T>::Normalize(T *x, T *y, T *z)
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
57 {
2152
d44b7775fc06 Removed DirectDraw2 compatibility.
Nomad
parents: 2037
diff changeset
58 extern int integer_sqrt(int val);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
59 *x *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
60 *y *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
61 *z *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
62 }
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
63
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
64 template Vec3<int32_t>;