annotate VectorTypes.h @ 2213:05e74b19991d

Draw arcomage
author Ritor1
date Thu, 13 Feb 2014 17:34:47 +0600
parents 4055b09160ae
children
rev   line source
0
Ritor1
parents:
diff changeset
1 #pragma once
1165
29a8defbad9e temporary _CRT_SECURE_NO_WARNINGS to remove some warnings
Grumpy7
parents: 1025
diff changeset
2
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
3 #include <cstdint>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
4
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
5 uint32_t int_get_vector_length(int32_t x, int32_t y, int32_t z);
0
Ritor1
parents:
diff changeset
6
Ritor1
parents:
diff changeset
7 #pragma pack(push, 1)
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
8 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
9 struct Vec2
0
Ritor1
parents:
diff changeset
10 {
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
11 T x;
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
12 T y;
0
Ritor1
parents:
diff changeset
13
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
14 inline Vec2(T a = 0, T b = 0):
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
15 x(a), y(b)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
16 {}
0
Ritor1
parents:
diff changeset
17 };
Ritor1
parents:
diff changeset
18 #pragma pack(pop)
Ritor1
parents:
diff changeset
19
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
20 #define Vec2_int_ Vec2<int32_t>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
21 #define Vec2_float_ Vec2<float>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
22
0
Ritor1
parents:
diff changeset
23 #pragma pack(push, 1)
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
24 template <class T>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
25 struct Vec3: public Vec2<T>
0
Ritor1
parents:
diff changeset
26 {
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
27 T z;
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
28
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
29 inline Vec3(T a = 0, T b = 0, T c = 0):
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
30 Vec2(a, b), z(c)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
31 {}
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
32
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
33 void Normalize_float();
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
34 template <class U>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
35 inline uint32_t GetDistanceTo(Vec3<U> &o)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
36 {
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
37 return int_get_vector_length(
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
38 abs(this->x - o.x),
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
39 abs(this->y - o.y),
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
40 abs(this->z - o.z)
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
41 );
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
42 }
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
43
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
44 static void __fastcall Rotate(T sDepth, T sRotY, T sRotX, Vec3<T> v, T *outx, T *outy, T *outz);
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
45 static void Normalize(T *x, T *y, T *z);
0
Ritor1
parents:
diff changeset
46 };
Ritor1
parents:
diff changeset
47 #pragma pack(pop)
Ritor1
parents:
diff changeset
48
1513
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
49 #define Vec3_short_ Vec3<int16_t>
4055b09160ae Clean and decouple. (2)
yoctozepto
parents: 1512
diff changeset
50 #define Vec3_int_ Vec3<int32_t>
0
Ritor1
parents:
diff changeset
51
Ritor1
parents:
diff changeset
52 #pragma pack(push, 1)
1512
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
53 struct Vec3_float_
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
54 {
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
55 void Normalize();
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
56
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
57 //----- (0049B32D) --------------------------------------------------------
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
58 static Vec3_float_ *Vec3_float_::Cross(Vec3_float_ *v1, Vec3_float_ *pOut, float x, float y, float z)
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
59 {
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
60 pOut->x = z * v1->y - y * v1->z;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
61 pOut->y = x * v1->z - z * v1->x;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
62 pOut->z = y * v1->x - x * v1->y;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
63 return pOut;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
64 }
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
65
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
66 //----- (0049B02E) --------------------------------------------------------
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
67 inline static float NegDot(Vec3_float_ *a1, Vec3_float_ *a2, float *a3)
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
68 {
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
69 return *a3 = -(a1->z * a2->z + a1->y * a2->y + a1->x * a2->x);
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
70 }
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
71
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
72 float x;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
73 float y;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
74 float z;
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
75 };
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
76 #pragma pack(pop)
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
77
af57b3b76fe4 Clean and decouple. (1)
yoctozepto
parents: 1504
diff changeset
78 #pragma pack(push, 1)
0
Ritor1
parents:
diff changeset
79 struct Vec4_int_
Ritor1
parents:
diff changeset
80 {
Ritor1
parents:
diff changeset
81 int x;
Ritor1
parents:
diff changeset
82 int y;
Ritor1
parents:
diff changeset
83 int z;
Ritor1
parents:
diff changeset
84 int w;
Ritor1
parents:
diff changeset
85 };
Ritor1
parents:
diff changeset
86 #pragma pack(pop)
Ritor1
parents:
diff changeset
87
Ritor1
parents:
diff changeset
88 /* 82 */
Ritor1
parents:
diff changeset
89 #pragma pack(push, 1)
Ritor1
parents:
diff changeset
90 struct Plane_int_
Ritor1
parents:
diff changeset
91 {
Ritor1
parents:
diff changeset
92 Vec3_int_ vNormal;
Ritor1
parents:
diff changeset
93 int dist;
Ritor1
parents:
diff changeset
94 };
Ritor1
parents:
diff changeset
95 #pragma pack(pop)
Ritor1
parents:
diff changeset
96
Ritor1
parents:
diff changeset
97 #pragma pack(push, 1)
Ritor1
parents:
diff changeset
98 struct BBox_short_
Ritor1
parents:
diff changeset
99 {
Ritor1
parents:
diff changeset
100 __int16 x1;
Ritor1
parents:
diff changeset
101 __int16 x2;
Ritor1
parents:
diff changeset
102 __int16 y1;
Ritor1
parents:
diff changeset
103 __int16 y2;
Ritor1
parents:
diff changeset
104 __int16 z1;
Ritor1
parents:
diff changeset
105 __int16 z2;
Ritor1
parents:
diff changeset
106 };
Ritor1
parents:
diff changeset
107 #pragma pack(pop)
Ritor1
parents:
diff changeset
108
Ritor1
parents:
diff changeset
109 #pragma pack(push, 1)
Ritor1
parents:
diff changeset
110 struct BBox_int_
Ritor1
parents:
diff changeset
111 {
Ritor1
parents:
diff changeset
112 int x1;
Ritor1
parents:
diff changeset
113 int x2;
Ritor1
parents:
diff changeset
114 int y1;
Ritor1
parents:
diff changeset
115 int y2;
Ritor1
parents:
diff changeset
116 int z1;
Ritor1
parents:
diff changeset
117 int z2;
Ritor1
parents:
diff changeset
118 };
Ritor1
parents:
diff changeset
119 #pragma pack(pop)
Ritor1
parents:
diff changeset
120
Ritor1
parents:
diff changeset
121 #pragma pack(push, 1)
Ritor1
parents:
diff changeset
122 struct Plane_float_
Ritor1
parents:
diff changeset
123 {
Ritor1
parents:
diff changeset
124 struct Vec3_float_ vNormal;
Ritor1
parents:
diff changeset
125 float dist;
Ritor1
parents:
diff changeset
126 };
Ritor1
parents:
diff changeset
127 #pragma pack(pop)
Ritor1
parents:
diff changeset
128
Ritor1
parents:
diff changeset
129 /* 196 */
Ritor1
parents:
diff changeset
130 #pragma pack(push, 1)
Ritor1
parents:
diff changeset
131 struct Matrix3x3_float_
Ritor1
parents:
diff changeset
132 {
Ritor1
parents:
diff changeset
133 union
Ritor1
parents:
diff changeset
134 {
Ritor1
parents:
diff changeset
135 struct
Ritor1
parents:
diff changeset
136 {
Ritor1
parents:
diff changeset
137 float _11; float _12; float _13;
Ritor1
parents:
diff changeset
138 float _21; float _22; float _23;
Ritor1
parents:
diff changeset
139 float _31; float _32; float _33;
Ritor1
parents:
diff changeset
140 };
Ritor1
parents:
diff changeset
141 float v[3][3];
Ritor1
parents:
diff changeset
142 };
Ritor1
parents:
diff changeset
143 };
Ritor1
parents:
diff changeset
144 #pragma pack(pop)