summaryrefslogtreecommitdiff
path: root/common/ihfx/types/hfxvec3.h
blob: be8bb8d4824eca6eff1748b3bcdaf5bc24702b3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#ifndef HFX_INTERNAL
struct HFX_vect3Base32
{
	union
	{
		struct
		{
			float x;
			float y;
			float z;
		};
		struct
		{
			float x;
			float y;
			float z;
		} axis;
		struct
		{
			float right;
			float up;
			float backward;
		} direction;
		struct
		{
			float pitch;
			float yaw;
			float roll;
		} rotation;
		struct
		{
			float wide;
			float tall;
			float deep;
		} dimension;
		float m[3];
	};
};
// 192 == 3 * 64 == 3 doubles
struct HFX_vect3Base64
{
	union
	{
		struct
		{
			double x;
			double y;
			double z;
		};
		struct
		{
			double x;
			double y;
			double z;
		} axis;
		struct
		{
			double right;
			double up;
			double backward;
		} direction;
		struct
		{
			double pitch;
			double yaw;
			double roll;
		} rotation;
		struct
		{
			double wide;
			double tall;
			double deep;
		} dimension;
		double m[3];
	};
};
#endif
#ifdef HFX_INTERNAL
struct hfxVec3internal
#endif
#ifndef HFX_INTERNAL
struct hfxVec3
#endif
	: public HFX_vect3Base64
{
#ifndef HFX_INTERNAL
	HFX_INLINE HFX_EXPLICIT hfxVec3(const double &_x, const double &_y, const double &_z);
	HFX_INLINE HFX_EXPLICIT hfxVec3(const double array_d[3] );
	HFX_INLINE hfxVec3(const hfxVec3 &_copy);
#ifdef HFX_ZERO_INIT
	HFX_INLINE HFX_EXPLICIT hfxVec3();
#endif HFX_ZERO_INIT
	HFX_INLINE hfxVec3();
#endif
	
	HFX_INLINE double &operator [](int i);
	HFX_INLINE const double &operator[](int i) const;

	HFX_INLINE operator double *();
	HFX_INLINE operator const double *() const;
	
	HFX_INLINE hfxVec3 operator -() const;
	
	HFX_INLINE hfxVec3 operator -(const hfxVec3 &vect) const;
	HFX_INLINE hfxVec3 &operator -=(const hfxVec3 &vect);

	HFX_INLINE hfxVec3 operator +(const hfxVec3 &vect) const;
	HFX_INLINE hfxVec3 &operator +=(const hfxVec3 &vect);

	HFX_INLINE hfxVec3 operator *(const hfxVec3 &vect) const;
	HFX_INLINE hfxVec3 operator *(const double &df) const;
	//HFX_INLINE hfxVec3 operator *(const float f) const;
	//HFX_INLINE hfxVec3 operator *(const int i){return ((*this)*((double)i));};
	
	HFX_INLINE hfxVec3 operator /(const hfxVec3 &vect) const;
	HFX_INLINE hfxVec3 operator /(const double &df) const;
	//HFX_INLINE hfxVec3 operator /(const float f) const;
	//HFX_INLINE hfxVec3 operator /(const int i){return ((*this)/((double)i));};
	
	HFX_INLINE hfxVec3 &operator /=(const hfxVec3 &vect);
	HFX_INLINE hfxVec3 &operator /=(const double &df);
	//HFX_INLINE hfxVec3 &operator /=(const float f);
	//HFX_INLINE hfxVec3 &operator /=(const int i){return ((*this)/=((double)i));};

	HFX_INLINE hfxVec3 &operator *=(const hfxVec3 &vect);
	HFX_INLINE hfxVec3 &operator *=(const double &df);
	//HFX_INLINE hfxVec3 &operator *=(const float f);
	//HFX_INLINE hfxVec3 &operator *=(const int i){return ((*this)*=((double)i));};
	HFX_INLINE hfxVec3 &operator =(const hfxVec3 &vect);
	HFX_INLINE hfxVec3 &operator =(const double &all);
	//HFX_INLINE hfxVec3 &operator =(const float all);
	//HFX_INLINE hfxVec3 &operator =(const int i){return ((*this)=((double)i));}

	HFX_INLINE const double *operator *()const;
	HFX_INLINE double *operator *();
	
	HFX_INLINE hfxVec3 Cross(const hfxVec3 &vect) const;
	HFX_INLINE double Dot( const hfxVec3 &vect ) const;
	HFX_INLINE double Magnitude() const;
	// get normalize
	HFX_INLINE hfxVec3 Normalized() const;
	// normalize in place
	HFX_INLINE hfxVec3 &Normalize();
	HFX_INLINE bool IsValid() const;
	HFX_INLINE bool IsNaN() const;
#ifdef HFX_INTERNAL
	HFX_INLINE hfxVec3internal *GetVec3Pointer(){ return (this); };
	HFX_INLINE const hfxVec3internal *GetVec3Pointer()const{ return (this); };
	HFX_INLINE operator hfxVec3 &(){ return *(reinterpret_cast<hfxVec3*>(this)); }
	HFX_INLINE operator const hfxVec3 &()const { return *(reinterpret_cast<const hfxVec3*>(this)); }
#endif
#ifndef HFX_PAT_DOESNT_KNOW
	HFX_INLINE double Length() const;
	HFX_INLINE hfxVec3 Normal() const;
#endif
};
#ifndef HFX_INTERNAL
#ifndef HFX_NO_TYPEDEFS
typedef hfxVec3 Vect3;
#endif
struct hfxVec3F : public HFX_vect3Base32
{
	HFX_INLINE hfxVec3F(const float _x, const float _y, const float _z);
	HFX_INLINE hfxVec3F(const float array_f[3] );
	HFX_INLINE hfxVec3F(const hfxVec3F &_copy);
	HFX_INLINE hfxVec3F();
	
	HFX_INLINE float &operator [](int i);
	HFX_INLINE const float &operator[](int i) const;

	HFX_INLINE operator float *();
	HFX_INLINE operator const float *() const;
	
	HFX_INLINE hfxVec3F operator -() const;
	
	HFX_INLINE hfxVec3F operator -(const hfxVec3F &vect) const;
	HFX_INLINE hfxVec3F &operator -=(const hfxVec3F &vect);

	HFX_INLINE hfxVec3F operator +(const hfxVec3F &vect) const;
	HFX_INLINE hfxVec3F &operator +=(const hfxVec3F &vect);

	HFX_INLINE hfxVec3F operator *(const hfxVec3F &vect) const;
	HFX_INLINE hfxVec3F operator *(const float f) const;
	//HFX_INLINE hfxVec3F operator *(const double &df) const;
	//HFX_INLINE hfxVec3F operator *(const int i){return ((*this)*(double)i);};
	
	HFX_INLINE hfxVec3F operator /(const hfxVec3F &vect) const;
	HFX_INLINE hfxVec3F operator /(const float f) const;
	//HFX_INLINE hfxVec3F operator /(const double &df) const;
	//HFX_INLINE hfxVec3F operator /(const int i){return ((*this)/(double)i);};
	
	HFX_INLINE hfxVec3F &operator /=(const hfxVec3F &vect);
	HFX_INLINE hfxVec3F &operator /=(const float f);
	//HFX_INLINE hfxVec3F &operator /=(const double &df);
	//HFX_INLINE hfxVec3F &operator /=(const int i){return ((*this)/=(double)i);};

	HFX_INLINE hfxVec3F &operator *=(const hfxVec3F &vect);
	HFX_INLINE hfxVec3F &operator *=(const float f);
	//HFX_INLINE hfxVec3F &operator *=(const double &df);
	//HFX_INLINE hfxVec3F &operator *=(const int i){return ((*this)*=(double)i);};

	HFX_INLINE hfxVec3F &operator =(const hfxVec3F &vect);
	HFX_INLINE hfxVec3F &operator =(const float all);
	//HFX_INLINE hfxVec3F &operator =(const double &all);
	//HFX_INLINE hfxVec3F &operator =(const int i){return ((*this)=(double)i);}

	HFX_INLINE const float *operator *()const;
	HFX_INLINE float *operator *();
	
	HFX_INLINE hfxVec3F Cross(const hfxVec3F &vect) const;
	HFX_INLINE float Dot( const hfxVec3F &vect ) const;
	HFX_INLINE float Magnitude() const;
	// get normalize
	HFX_INLINE hfxVec3F Normalized() const;
	// normalize in place
	HFX_INLINE hfxVec3F &Normalize();
	HFX_INLINE bool IsValid() const;
	HFX_INLINE bool IsNaN() const;
#ifndef HFX_PAT_DOESNT_KNOW
	HFX_INLINE float Length() const;
	HFX_INLINE hfxVec3F Normal() const;
#endif
};

struct _box3Base
{
	union
	{
		struct{
			HFX_vect3Base64 bound_min;
			HFX_vect3Base64 bound_max;
		}box;
		HFX_vect3Base64 min_max[2];
		struct
		{
			double left;
			double down;
			double forward;
			double right;
			double up;
			double backward;
		}side;
		double m[6];
	};
};
struct BoundingBox3 : public _box3Base
{
	inline BoundingBox3(const double &left=0, const double &down=0, const double &forward=0,
		const double &right=0, const double &up=0, const double &backward=0)
	{
		side.left = left;
		side.down = down;
		side.forward = forward;
		side.right = right;
		side.up = up;
		side.backward = backward;
	}
	inline BoundingBox3(const hfxVec3 &bMin, const hfxVec3 &bMax)
	{
		BoxMin() = bMin;
		BoxMax() = bMax;
	}
	inline hfxVec3 &BoxMin(){return (hfxVec3&)box.bound_min;};
	inline const hfxVec3 &BoxMin() const {return (const hfxVec3&)box.bound_min;};
	inline hfxVec3 &BoxMax(){return (hfxVec3&)box.bound_max;};
	inline const hfxVec3 &BoxMax() const {return (const hfxVec3&)box.bound_max;};
	inline hfxVec3 Center() const { return (BoxMin() + BoxMax())/(double)2.0; };
	inline hfxVec3 Dimensions() const { return BoxMax() - BoxMin();};
	inline hfxVec3 SpaceBetweenCentered(const BoundingBox3 &other) const {return other.Dimensions() - Dimensions();};
	inline BoundingBox3 SpaceBetween(const BoundingBox3 &other) const {return other - *this;}
	inline BoundingBox3 &SetDimensions(const hfxVec3 &dimm) { hfxVec3 cent = Center(); hfxVec3 dim = dimm/2.0; BoxMin() = cent - dim; BoxMax() = cent + dim; return *this; }
	inline BoundingBox3 &SetCenter(const hfxVec3 &cent) { hfxVec3 dim = Dimensions(); BoxMin() = cent - dim; BoxMax() = cent + dim; return *this; }
	inline operator hfxVec3 *(){return (hfxVec3*)min_max;};
	inline operator const hfxVec3 *() const {return (const hfxVec3*)min_max;};
	inline operator double *() {return m;};
	inline operator const double *() const {return m;};
	inline BoundingBox3 operator -(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() - vect, BoxMax() - vect ); }
	inline BoundingBox3 operator +(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() + vect, BoxMax() + vect ); }
	inline BoundingBox3 operator *(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() * vect, BoxMax() * vect ); }
	inline BoundingBox3 operator /(const hfxVec3 &vect) const { return BoundingBox3( BoxMin() / vect, BoxMax() / vect ); }
	inline BoundingBox3 operator *(const double &df) const{ return BoundingBox3( BoxMin() * df, BoxMax() * df ); }
	inline BoundingBox3 operator /(const double &df) const{ return BoundingBox3( BoxMin() / df, BoxMax() / df ); }
	inline BoundingBox3 operator -(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() - bbox.BoxMin(), BoxMax() - bbox.BoxMax() ); }
	inline BoundingBox3 operator +(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() + bbox.BoxMin(), BoxMax() + bbox.BoxMax() ); }
	inline BoundingBox3 operator *(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() * bbox.BoxMin(), BoxMax() * bbox.BoxMax() ); }
	inline BoundingBox3 operator /(const BoundingBox3 &bbox) const { return BoundingBox3( BoxMin() / bbox.BoxMin(), BoxMax() / bbox.BoxMax() ); }
	inline BoundingBox3 &operator =(const BoundingBox3 &bbox) { BoxMin() = bbox.BoxMin(); BoxMax() = bbox.BoxMax(); return *this; }
	inline BoundingBox3 &operator -=(const hfxVec3 &vect){ BoxMin()-=vect; BoxMax()-=vect; return *this; }
	inline BoundingBox3 &operator +=(const hfxVec3 &vect){ BoxMin()+=vect; BoxMax()+=vect; return *this; }
	inline BoundingBox3 &operator *=(const hfxVec3 &vect){ BoxMin()*=vect; BoxMax()*=vect; return *this; }
	inline BoundingBox3 &operator /=(const hfxVec3 &vect){ BoxMin()/=vect; BoxMax()/=vect; return *this; }
	inline BoundingBox3 &operator *=(const double &df){ BoxMin()*=df; BoxMax()*=df; return *this; }
	inline BoundingBox3 &operator /=(const double &df){ BoxMin()/=df; BoxMax()/=df; return *this; }
	inline BoundingBox3 &operator -=(const BoundingBox3 &bbox){ BoxMin()-=bbox.BoxMin(); BoxMax()-=bbox.BoxMax(); return *this; }
	inline BoundingBox3 &operator +=(const BoundingBox3 &bbox){ BoxMin()+=bbox.BoxMin(); BoxMax()+=bbox.BoxMax(); return *this; }
	inline BoundingBox3 &operator *=(const BoundingBox3 &bbox){ BoxMin()*=bbox.BoxMin(); BoxMax()*=bbox.BoxMax(); return *this; }
	inline BoundingBox3 &operator /=(const BoundingBox3 &bbox){ BoxMin()/=bbox.BoxMin(); BoxMax()/=bbox.BoxMax(); return *this; }
};
#endif
#include "inl_hfxMath.h"
#ifdef HFX_INTERNAL
typedef ::hfxVec3 hfxVec3;
//VECTOR CLASS
#endif