annotate Engine/VectorTypes.h @ 2542:bacf9809126a

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