annotate Engine/VectorTypes.cpp @ 2567:d569340b05ff

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