annotate VectorTypes.cpp @ 2461:ff7f4995aa25

function MakeScreenshot()
author Ritor1
date Tue, 05 Aug 2014 17:00:35 +0600
parents f4af3b203f65
children 104fdbea0386
rev   line source
2415
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
1 #define _CRTDBG_MAP_ALLOC
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
2 #include <stdlib.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
3 #include <crtdbg.h>
f4af3b203f65 LOD.cpp cleaned and search memory corrupt
Ritor1
parents: 2253
diff changeset
4
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
5 #define _CRT_SECURE_NO_WARNINGS
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
6 #include <utility>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
7
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
8 #include "mm7_data.h"
2037
7a9477135943 Renamed Math.h -> OurMath.h (file resolution was sometimes ambiguous)
Nomad
parents: 1528
diff changeset
9 #include "OurMath.h"
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
10
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
11 //----- (004621DA) --------------------------------------------------------
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
12 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
13 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
14 if (x < y)
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, y);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
17 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
18 if (x < 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(x, z);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
21 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
22 if (y < z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
23 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
24 std::swap(y, z);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
25 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
26
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
27 return x + (11 * y >> 5) + (z >> 2);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
28 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
29
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
30 //----- (0044C362) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
31 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
32 void Vec3<T>::Normalize_float()
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
33 {
1528
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
34 double x = this->x;
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
35 double y = this->y;
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
36 double z = this->z;
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
37 double s = sqrt(x * x + y * y + z * z);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
38
1528
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
39 this->x = bankersRounding(x / s);
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
40 this->y = bankersRounding(y / s);
270627b54ed4 Fix Vec3<T>::Normalize_float().
yoctozepto
parents: 1513
diff changeset
41 this->z = bankersRounding(z / s);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
42 }
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
43
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
44 //----- (0043AA99) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
45 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
46 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
47 {
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
48 float cosf_x = cosf(3.14159265f * sRotX / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
49 sinf_x = sinf(3.14159265f * sRotX / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
50 cosf_y = cosf(3.14159265f * sRotY / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
51 sinf_y = sinf(3.14159265f * sRotY / 1024.0f);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
52
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
53 *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
54 *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
55 *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
56 }
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
57
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
58 //----- (0043AB61) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
59 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
60 void Vec3<T>::Normalize(T *x, T *y, T *z)
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
61 {
2152
d44b7775fc06 Removed DirectDraw2 compatibility.
Nomad
parents: 2037
diff changeset
62 extern int integer_sqrt(int val);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
63 *x *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
64 *y *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
65 *z *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
66 }
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
67
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
68 template Vec3<int32_t>;