@@ -33,14 +33,16 @@ enum PlaneIntersectionType
33
33
};
34
34
35
35
struct BoundingBox ;
36
+ struct BoundingOrientedBox ;
37
+ struct BoundingFrustum ;
36
38
37
39
#pragma warning(push)
38
- #pragma warning(disable:4324)
40
+ #pragma warning(disable:4324 4820 )
39
41
40
42
// -------------------------------------------------------------------------------------
41
43
// Bounding sphere
42
44
// -------------------------------------------------------------------------------------
43
- __declspec (align( 16 )) struct BoundingSphere
45
+ struct BoundingSphere
44
46
{
45
47
XMFLOAT3 Center; // Center of the sphere.
46
48
float Radius; // Radius of the sphere.
@@ -63,10 +65,14 @@ __declspec(align(16)) struct BoundingSphere
63
65
ContainmentType Contains ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
64
66
ContainmentType Contains ( _In_ const BoundingSphere& sh ) const ;
65
67
ContainmentType Contains ( _In_ const BoundingBox& box ) const ;
68
+ ContainmentType Contains ( _In_ const BoundingOrientedBox& box ) const ;
69
+ ContainmentType Contains ( _In_ const BoundingFrustum& fr ) const ;
66
70
67
71
bool Intersects ( _In_ const BoundingSphere& sh ) const ;
68
72
bool Intersects ( _In_ const BoundingBox& box ) const ;
69
-
73
+ bool Intersects ( _In_ const BoundingOrientedBox& box ) const ;
74
+ bool Intersects ( _In_ const BoundingFrustum& fr ) const ;
75
+
70
76
bool Intersects ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
71
77
// Triangle-sphere test
72
78
@@ -76,19 +82,26 @@ __declspec(align(16)) struct BoundingSphere
76
82
bool Intersects ( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float & Dist ) const ;
77
83
// Ray-sphere test
78
84
85
+ ContainmentType ContainedBy ( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
86
+ _In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const ;
87
+ // Test sphere against six planes (see BoundingFrustum::GetPlanes)
88
+
79
89
// Static methods
80
90
static void CreateMerged ( _Out_ BoundingSphere& Out, _In_ const BoundingSphere& S1, _In_ const BoundingSphere& S2 );
81
91
82
92
static void CreateFromBoundingBox ( _Out_ BoundingSphere& Out, _In_ const BoundingBox& box );
93
+ static void CreateFromBoundingBox ( _Out_ BoundingSphere& Out, _In_ const BoundingOrientedBox& box );
83
94
84
95
static void CreateFromPoints ( _Out_ BoundingSphere& Out, _In_ size_t Count,
85
96
_In_reads_bytes_ (sizeof (XMFLOAT3)+Stride*(Count-1 )) const XMFLOAT3* pPoints, _In_ size_t Stride );
97
+
98
+ static void CreateFromFrustum ( _Out_ BoundingSphere& Out, _In_ const BoundingFrustum& fr );
86
99
};
87
100
88
101
// -------------------------------------------------------------------------------------
89
102
// Axis-aligned bounding box
90
103
// -------------------------------------------------------------------------------------
91
- __declspec (align( 16 )) struct BoundingBox
104
+ struct BoundingBox
92
105
{
93
106
static const size_t CORNER_COUNT = 8 ;
94
107
@@ -114,9 +127,13 @@ __declspec(align(16)) struct BoundingBox
114
127
ContainmentType Contains ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
115
128
ContainmentType Contains ( _In_ const BoundingSphere& sh ) const ;
116
129
ContainmentType Contains ( _In_ const BoundingBox& box ) const ;
130
+ ContainmentType Contains ( _In_ const BoundingOrientedBox& box ) const ;
131
+ ContainmentType Contains ( _In_ const BoundingFrustum& fr ) const ;
117
132
118
133
bool Intersects ( _In_ const BoundingSphere& sh ) const ;
119
134
bool Intersects ( _In_ const BoundingBox& box ) const ;
135
+ bool Intersects ( _In_ const BoundingOrientedBox& box ) const ;
136
+ bool Intersects ( _In_ const BoundingFrustum& fr ) const ;
120
137
121
138
bool Intersects ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
122
139
// Triangle-Box test
@@ -127,6 +144,10 @@ __declspec(align(16)) struct BoundingBox
127
144
bool Intersects ( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float & Dist ) const ;
128
145
// Ray-Box test
129
146
147
+ ContainmentType ContainedBy ( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
148
+ _In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const ;
149
+ // Test box against six planes (see BoundingFrustum::GetPlanes)
150
+
130
151
// Static methods
131
152
static void CreateMerged ( _Out_ BoundingBox& Out, _In_ const BoundingBox& b1, _In_ const BoundingBox& b2 );
132
153
@@ -137,6 +158,164 @@ __declspec(align(16)) struct BoundingBox
137
158
_In_reads_bytes_ (sizeof (XMFLOAT3)+Stride*(Count-1 )) const XMFLOAT3* pPoints, _In_ size_t Stride );
138
159
};
139
160
161
+ // -------------------------------------------------------------------------------------
162
+ // Oriented bounding box
163
+ // -------------------------------------------------------------------------------------
164
+ struct BoundingOrientedBox
165
+ {
166
+ static const size_t CORNER_COUNT = 8 ;
167
+
168
+ XMFLOAT3 Center; // Center of the box.
169
+ XMFLOAT3 Extents; // Distance from the center to each side.
170
+ XMFLOAT4 Orientation; // Unit quaternion representing rotation (box -> world).
171
+
172
+ // Creators
173
+ BoundingOrientedBox () : Center(0 ,0 ,0 ), Extents( 1 .f, 1 .f, 1 .f ), Orientation(0 ,0 ,0 , 1 .f ) {}
174
+ BoundingOrientedBox ( _In_ const XMFLOAT3& _Center, _In_ const XMFLOAT3& _Extents, _In_ const XMFLOAT4& _Orientation )
175
+ : Center(_Center), Extents(_Extents), Orientation(_Orientation)
176
+ {
177
+ assert (_Extents.x >= 0 && _Extents.y >= 0 && _Extents.z >= 0 );
178
+ }
179
+ BoundingOrientedBox ( _In_ const BoundingOrientedBox& box )
180
+ : Center(box.Center), Extents(box.Extents), Orientation(box.Orientation) {}
181
+
182
+ // Methods
183
+ BoundingOrientedBox& operator =( _In_ const BoundingOrientedBox& box ) { Center = box.Center ; Extents = box.Extents ; Orientation = box.Orientation ; return *this ; }
184
+
185
+ void Transform ( _Out_ BoundingOrientedBox& Out, _In_ CXMMATRIX M ) const ;
186
+ void Transform ( _Out_ BoundingOrientedBox& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation ) const ;
187
+
188
+ void GetCorners ( _Out_writes_(8 ) XMFLOAT3* Corners ) const ;
189
+ // Gets the 8 corners of the box
190
+
191
+ ContainmentType Contains ( _In_ FXMVECTOR Point ) const ;
192
+ ContainmentType Contains ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
193
+ ContainmentType Contains ( _In_ const BoundingSphere& sh ) const ;
194
+ ContainmentType Contains ( _In_ const BoundingBox& box ) const ;
195
+ ContainmentType Contains ( _In_ const BoundingOrientedBox& box ) const ;
196
+ ContainmentType Contains ( _In_ const BoundingFrustum& fr ) const ;
197
+
198
+ bool Intersects ( _In_ const BoundingSphere& sh ) const ;
199
+ bool Intersects ( _In_ const BoundingBox& box ) const ;
200
+ bool Intersects ( _In_ const BoundingOrientedBox& box ) const ;
201
+ bool Intersects ( _In_ const BoundingFrustum& fr ) const ;
202
+
203
+ bool Intersects ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
204
+ // Triangle-OrientedBox test
205
+
206
+ PlaneIntersectionType Intersects ( _In_ FXMVECTOR Plane ) const ;
207
+ // Plane-OrientedBox test
208
+
209
+ bool Intersects ( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float & Dist ) const ;
210
+ // Ray-OrientedBox test
211
+
212
+ ContainmentType ContainedBy ( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
213
+ _In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const ;
214
+ // Test OrientedBox against six planes (see BoundingFrustum::GetPlanes)
215
+
216
+ // Static methods
217
+ static void CreateFromBoundingBox ( _Out_ BoundingOrientedBox& Out, _In_ const BoundingBox& box );
218
+
219
+ static void CreateFromPoints ( _Out_ BoundingOrientedBox& Out, _In_ size_t Count,
220
+ _In_reads_bytes_ (sizeof (XMFLOAT3)+Stride*(Count-1 )) const XMFLOAT3* pPoints, _In_ size_t Stride );
221
+ };
222
+
223
+ // -------------------------------------------------------------------------------------
224
+ // Bounding frustum
225
+ // -------------------------------------------------------------------------------------
226
+ struct BoundingFrustum
227
+ {
228
+ static const size_t CORNER_COUNT = 8 ;
229
+
230
+ XMFLOAT3 Origin; // Origin of the frustum (and projection).
231
+ XMFLOAT4 Orientation; // Quaternion representing rotation.
232
+
233
+ float RightSlope; // Positive X slope (X/Z).
234
+ float LeftSlope; // Negative X slope.
235
+ float TopSlope; // Positive Y slope (Y/Z).
236
+ float BottomSlope; // Negative Y slope.
237
+ float Near, Far; // Z of the near plane and far plane.
238
+
239
+ // Creators
240
+ BoundingFrustum () : Origin(0 ,0 ,0 ), Orientation(0 ,0 ,0 , 1 .f), RightSlope( 1 .f ), LeftSlope( -1 .f ),
241
+ TopSlope ( 1 .f ), BottomSlope( -1 .f ), Near(0 ), Far( 1 .f ) {}
242
+ BoundingFrustum ( _In_ const XMFLOAT3& _Origin, _In_ const XMFLOAT4& _Orientation,
243
+ _In_ float _RightSlope, _In_ float _LeftSlope, _In_ float _TopSlope, _In_ float _BottomSlope,
244
+ _In_ float _Near, _In_ float _Far )
245
+ : Origin(_Origin), Orientation(_Orientation),
246
+ RightSlope(_RightSlope), LeftSlope(_LeftSlope), TopSlope(_TopSlope), BottomSlope(_BottomSlope),
247
+ Near(_Near), Far(_Far) { assert ( _Near <= _Far ); }
248
+ BoundingFrustum ( _In_ const BoundingFrustum& fr )
249
+ : Origin(fr.Origin), Orientation(fr.Orientation), RightSlope(fr.RightSlope), LeftSlope(fr.LeftSlope),
250
+ TopSlope(fr.TopSlope), BottomSlope(fr.BottomSlope), Near(fr.Near), Far(fr.Far) {}
251
+ BoundingFrustum ( _In_ CXMMATRIX Projection ) { CreateFromMatrix ( *this , Projection ); }
252
+
253
+ // Methods
254
+ BoundingFrustum& operator =( _In_ const BoundingFrustum& fr ) { Origin=fr.Origin ; Orientation=fr.Orientation ;
255
+ RightSlope=fr.RightSlope ; LeftSlope=fr.LeftSlope ;
256
+ TopSlope=fr.TopSlope ; BottomSlope=fr.BottomSlope ;
257
+ Near=fr.Near ; Far=fr.Far ; return *this ; }
258
+
259
+ void Transform ( _Out_ BoundingFrustum& Out, _In_ CXMMATRIX M ) const ;
260
+ void Transform ( _Out_ BoundingFrustum& Out, _In_ float Scale, _In_ FXMVECTOR Rotation, _In_ FXMVECTOR Translation ) const ;
261
+
262
+ void GetCorners ( _Out_writes_(8 ) XMFLOAT3* Corners ) const ;
263
+ // Gets the 8 corners of the frustum
264
+
265
+ ContainmentType Contains ( _In_ FXMVECTOR Point ) const ;
266
+ ContainmentType Contains ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
267
+ ContainmentType Contains ( _In_ const BoundingSphere& sp ) const ;
268
+ ContainmentType Contains ( _In_ const BoundingBox& box ) const ;
269
+ ContainmentType Contains ( _In_ const BoundingOrientedBox& box ) const ;
270
+ ContainmentType Contains ( _In_ const BoundingFrustum& fr ) const ;
271
+ // Frustum-Frustum test
272
+
273
+ bool Intersects ( _In_ const BoundingSphere& sh ) const ;
274
+ bool Intersects ( _In_ const BoundingBox& box ) const ;
275
+ bool Intersects ( _In_ const BoundingOrientedBox& box ) const ;
276
+ bool Intersects ( _In_ const BoundingFrustum& fr ) const ;
277
+
278
+ bool Intersects ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2 ) const ;
279
+ // Triangle-Frustum test
280
+
281
+ PlaneIntersectionType Intersects ( _In_ FXMVECTOR Plane ) const ;
282
+ // Plane-Frustum test
283
+
284
+ bool Intersects ( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _Out_ float & Dist ) const ;
285
+ // Ray-Frustum test
286
+
287
+ ContainmentType ContainedBy ( _In_ FXMVECTOR Plane0, _In_ FXMVECTOR Plane1, _In_ FXMVECTOR Plane2,
288
+ _In_ GXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 ) const ;
289
+ // Test frustum against six planes (see BoundingFrustum::GetPlanes)
290
+
291
+ void GetPlanes ( _Out_opt_ XMVECTOR* NearPlane, _Out_opt_ XMVECTOR* FarPlane, _Out_opt_ XMVECTOR* RightPlane,
292
+ _Out_opt_ XMVECTOR* LeftPlane, _Out_opt_ XMVECTOR* TopPlane, _Out_opt_ XMVECTOR* BottomPlane ) const ;
293
+ // Create 6 Planes representation of Frustum
294
+
295
+ // Static methods
296
+ static void CreateFromMatrix ( _Out_ BoundingFrustum& Out, _In_ CXMMATRIX Projection );
297
+ };
298
+
299
+ // -----------------------------------------------------------------------------
300
+ // Triangle intersection testing routines.
301
+ // -----------------------------------------------------------------------------
302
+ namespace TriangleTests
303
+ {
304
+ bool Intersects ( _In_ FXMVECTOR Origin, _In_ FXMVECTOR Direction, _In_ FXMVECTOR V0, _In_ GXMVECTOR V1, _In_ CXMVECTOR V2, _Out_ float & Dist );
305
+ // Ray-Triangle
306
+
307
+ bool Intersects ( _In_ FXMVECTOR A0, _In_ FXMVECTOR A1, _In_ FXMVECTOR A2, _In_ GXMVECTOR B0, _In_ CXMVECTOR B1, _In_ CXMVECTOR B2 );
308
+ // Triangle-Triangle
309
+
310
+ PlaneIntersectionType Intersects ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2, _In_ GXMVECTOR Plane );
311
+ // Plane-Triangle
312
+
313
+ ContainmentType ContainedBy ( _In_ FXMVECTOR V0, _In_ FXMVECTOR V1, _In_ FXMVECTOR V2,
314
+ _In_ GXMVECTOR Plane0, _In_ CXMVECTOR Plane1, _In_ CXMVECTOR Plane2,
315
+ _In_ CXMVECTOR Plane3, _In_ CXMVECTOR Plane4, _In_ CXMVECTOR Plane5 );
316
+ // Test a triangle against six planes at once (see BoundingFrustum::GetPlanes)
317
+ };
318
+
140
319
#pragma warning(pop)
141
320
142
321
/* ***************************************************************************
@@ -146,7 +325,7 @@ __declspec(align(16)) struct BoundingBox
146
325
****************************************************************************/
147
326
148
327
#pragma warning(push)
149
- #pragma warning(disable: 4068)
328
+ #pragma warning(disable : 4068 4616 6001 )
150
329
151
330
#pragma prefast(push)
152
331
#pragma prefast(disable : 25000, "FXMVECTOR is 16 bytes")
0 commit comments