comparison Engine/VectorTypes.h @ 2499:68cdef6879a0

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