annotate VectorTypes.cpp @ 1513:4055b09160ae

Clean and decouple. (2)
author yoctozepto
date Mon, 02 Sep 2013 22:08:21 +0200
parents ff1867836af5
children 270627b54ed4
rev   line source
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
1 #include <utility>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
2
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
3 #include "mm7_data.h"
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
4
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
5 //----- (004621DA) --------------------------------------------------------
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
6 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
7 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
8 if (x < y)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
9 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
10 std::swap(x, y);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
11 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
12 if (x < z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
13 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
14 std::swap(x, z);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
15 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
16 if (y < z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
17 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
18 std::swap(y, z);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
19 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
20
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
21 return x + (11 * y >> 5) + (z >> 2);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
22 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
23
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
24 //----- (0044C362) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
25 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
26 void Vec3<T>::Normalize_float()
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
27 {
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
28 long double x = this->x;
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
29 long double y = this->y;
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
30 long double z = this->z;
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
31 long double s = sqrtl(x * x + y * y + z * z);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
32
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
33 this->x = (T)(x / s);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
34 this->y = (T)(y / s);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
35 this->z = (T)(z / s);
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
36 }
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
37
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
38 //----- (0043AA99) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
39 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
40 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
41 {
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
42 float cosf_x = cosf(3.14159265f * sRotX / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
43 sinf_x = sinf(3.14159265f * sRotX / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
44 cosf_y = cosf(3.14159265f * sRotY / 1024.0f),
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
45 sinf_y = sinf(3.14159265f * sRotY / 1024.0f);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
46
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
47 *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
48 *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
49 *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
50 }
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
51
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
52 //----- (0043AB61) --------------------------------------------------------
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
53 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
54 void Vec3<T>::Normalize(T *x, T *y, T *z)
1504
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
55 {
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
56 *x *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
57 *y *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
58 *z *= 65536 / (integer_sqrt(*y * *y + *z * *z + *x * *x) | 1);
ff1867836af5 Cleanup of VectorTypes.
yoctozepto
parents:
diff changeset
59 }
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
60
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1504
diff changeset
61 template Vec3<int32_t>;