Main Page
Class Hierarchy
Compound List
Compound Members
Include
foundation
PxBounds3.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3
*
4
* NVIDIA CORPORATION and its licensors retain all intellectual property
5
* and proprietary rights in and to this software, related documentation
6
* and any modifications thereto. Any use, reproduction, disclosure or
7
* distribution of this software and related documentation without an express
8
* license agreement from NVIDIA CORPORATION is strictly prohibited.
9
*/
10
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14
#ifndef PX_FOUNDATION_PX_BOUNDS3_H
15
#define PX_FOUNDATION_PX_BOUNDS3_H
16
21
#include "
foundation/PxTransform.h
"
22
#include "
foundation/PxMat33.h
"
23
24
#ifndef PX_DOXYGEN
25
namespace
physx
26
{
27
#endif
28
29
// maximum extents defined such that floating point exceptions are avoided for standard use cases
30
#define PX_MAX_BOUNDS_EXTENTS (PX_MAX_REAL * 0.25f)
31
41
class
PxBounds3
42
{
43
public
:
44
49
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
() {}
50
54
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
(
const
PxVec3
& minimum,
const
PxVec3
& maximum);
55
59
static
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
empty();
60
66
static
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
boundsOfPoints(
const
PxVec3
& v0,
const
PxVec3
& v1);
67
73
static
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
centerExtents(
const
PxVec3
& center,
const
PxVec3
& extent);
74
78
static
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
basisExtent(
const
PxVec3
& center,
const
PxMat33
& basis,
const
PxVec3
& extent);
79
83
static
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
poseExtent(
const
PxTransform
& pose,
const
PxVec3
& extent);
84
93
static
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
transformSafe(
const
PxMat33
& matrix,
const
PxBounds3
& bounds);
94
103
static
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
transformFast(
const
PxMat33
& matrix,
const
PxBounds3
& bounds);
104
113
static
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
transformSafe(
const
PxTransform
& transform,
const
PxBounds3
& bounds);
114
123
static
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
transformFast(
const
PxTransform
& transform,
const
PxBounds3
& bounds);
124
128
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
setEmpty();
129
133
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
setMaximal();
134
139
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
include(
const
PxVec3
& v);
140
145
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
include(
const
PxBounds3
& b);
146
147
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
isEmpty()
const
;
148
153
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
intersects(
const
PxBounds3
& b)
const
;
154
160
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
intersects1D(
const
PxBounds3
& a,
PxU32
axis)
const
;
161
166
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
contains(
const
PxVec3
& v)
const
;
167
172
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
isInside(
const
PxBounds3
&
box
)
const
;
173
177
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec3
getCenter()
const
;
178
182
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
getCenter(
PxU32
axis)
const
;
183
187
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
getExtents(
PxU32
axis)
const
;
188
192
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec3
getDimensions()
const
;
193
197
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec3
getExtents()
const
;
198
206
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
scaleSafe(
PxF32
scale);
207
215
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
scaleFast(
PxF32
scale);
216
222
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
fattenSafe(
PxReal
distance);
223
229
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
fattenFast(
PxReal
distance);
230
234
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
isFinite()
const
;
235
239
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
isValid()
const
;
240
241
PxVec3
minimum
, maximum;
242
};
243
244
245
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3::PxBounds3
(
const
PxVec3
& minimum_,
const
PxVec3
& maximum_)
246
: minimum(minimum_), maximum(maximum_)
247
{
248
}
249
250
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
PxBounds3::empty
()
251
{
252
return
PxBounds3
(
PxVec3
(
PX_MAX_BOUNDS_EXTENTS
),
PxVec3
(-
PX_MAX_BOUNDS_EXTENTS
));
253
}
254
255
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::isFinite
()
const
256
{
257
return
minimum
.
isFinite
() &&
maximum
.
isFinite
();
258
}
259
260
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
PxBounds3::boundsOfPoints
(
const
PxVec3
& v0,
const
PxVec3
& v1)
261
{
262
return
PxBounds3
(v0.
minimum
(v1), v0.
maximum
(v1));
263
}
264
265
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxBounds3
PxBounds3::centerExtents
(
const
PxVec3
& center,
const
PxVec3
& extent)
266
{
267
return
PxBounds3
(center - extent, center + extent);
268
}
269
270
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
PxBounds3::basisExtent
(
const
PxVec3
& center,
const
PxMat33
& basis,
const
PxVec3
& extent)
271
{
272
// extended basis vectors
273
PxVec3
c0 = basis.
column0
* extent.
x
;
274
PxVec3
c1 = basis.
column1
* extent.
y
;
275
PxVec3
c2 = basis.
column2
* extent.
z
;
276
277
PxVec3
w;
278
// find combination of base vectors that produces max. distance for each component = sum of abs()
279
w.
x
=
PxAbs
(c0.
x
) +
PxAbs
(c1.
x
) +
PxAbs
(c2.
x
);
280
w.
y
=
PxAbs
(c0.
y
) +
PxAbs
(c1.
y
) +
PxAbs
(c2.
y
);
281
w.
z
=
PxAbs
(c0.
z
) +
PxAbs
(c1.
z
) +
PxAbs
(c2.
z
);
282
283
return
PxBounds3
(center - w, center + w);
284
}
285
286
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
PxBounds3::poseExtent
(
const
PxTransform
& pose,
const
PxVec3
& extent)
287
{
288
return
basisExtent
(pose.
p
,
PxMat33
(pose.
q
), extent);
289
}
290
291
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::setEmpty
()
292
{
293
minimum
=
PxVec3
(
PX_MAX_BOUNDS_EXTENTS
);
294
maximum
=
PxVec3
(-
PX_MAX_BOUNDS_EXTENTS
);
295
}
296
297
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::setMaximal
()
298
{
299
minimum
=
PxVec3
(-
PX_MAX_BOUNDS_EXTENTS
);
300
maximum
=
PxVec3
(
PX_MAX_BOUNDS_EXTENTS
);
301
}
302
303
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::include
(
const
PxVec3
& v)
304
{
305
PX_ASSERT
(
isValid
());
306
minimum
=
minimum
.
minimum
(v);
307
maximum
=
maximum
.
maximum
(v);
308
}
309
310
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::include
(
const
PxBounds3
& b)
311
{
312
PX_ASSERT
(
isValid
());
313
minimum
=
minimum
.
minimum
(b.
minimum
);
314
maximum
=
maximum
.
maximum
(b.
maximum
);
315
}
316
317
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::isEmpty
()
const
318
{
319
PX_ASSERT
(
isValid
());
320
return
minimum
.
x
>
maximum
.
x
;
321
}
322
323
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::intersects
(
const
PxBounds3
& b)
const
324
{
325
PX_ASSERT
(
isValid
() && b.
isValid
());
326
return
!(b.
minimum
.
x
>
maximum
.
x
||
minimum
.
x
> b.
maximum
.
x
||
327
b.
minimum
.
y
>
maximum
.
y
||
minimum
.
y
> b.
maximum
.
y
||
328
b.
minimum
.
z
>
maximum
.
z
||
minimum
.
z
> b.
maximum
.
z
);
329
}
330
331
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::intersects1D
(
const
PxBounds3
& a,
PxU32
axis)
const
332
{
333
PX_ASSERT
(
isValid
() && a.
isValid
());
334
return
maximum
[axis] >= a.
minimum
[axis] && a.
maximum
[axis] >=
minimum
[axis];
335
}
336
337
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::contains
(
const
PxVec3
& v)
const
338
{
339
PX_ASSERT
(
isValid
());
340
341
return
!(v.
x
<
minimum
.
x
|| v.
x
>
maximum
.
x
||
342
v.
y
<
minimum
.
y
|| v.
y
>
maximum
.
y
||
343
v.
z
<
minimum
.
z
|| v.
z
>
maximum
.
z
);
344
}
345
346
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::isInside
(
const
PxBounds3
&
box
)
const
347
{
348
PX_ASSERT
(
isValid
() && box.
isValid
());
349
if
(box.
minimum
.
x
>
minimum
.
x
)
return
false
;
350
if
(box.
minimum
.
y
>
minimum
.
y
)
return
false
;
351
if
(box.
minimum
.
z
>
minimum
.
z
)
return
false
;
352
if
(box.
maximum
.
x
<
maximum
.
x
)
return
false
;
353
if
(box.
maximum
.
y
<
maximum
.
y
)
return
false
;
354
if
(box.
maximum
.
z
<
maximum
.
z
)
return
false
;
355
return
true
;
356
}
357
358
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec3
PxBounds3::getCenter
()
const
359
{
360
PX_ASSERT
(
isValid
());
361
return
(
minimum
+
maximum
) * 0.5f;
362
}
363
364
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
PxBounds3::getCenter
(
PxU32
axis)
const
365
{
366
PX_ASSERT
(
isValid
());
367
return
(
minimum
[axis] +
maximum
[axis]) * 0.5f;
368
}
369
370
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxReal
PxBounds3::getExtents
(
PxU32
axis)
const
371
{
372
PX_ASSERT
(
isValid
());
373
return
(
maximum
[axis] -
minimum
[axis]) * 0.5f;
374
}
375
376
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec3
PxBounds3::getDimensions
()
const
377
{
378
PX_ASSERT
(
isValid
());
379
return
maximum
-
minimum
;
380
}
381
382
PX_CUDA_CALLABLE
PX_FORCE_INLINE
PxVec3
PxBounds3::getExtents
()
const
383
{
384
PX_ASSERT
(
isValid
());
385
return
getDimensions
() * 0.5f;
386
}
387
388
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::scaleSafe
(
PxF32
scale)
389
{
390
PX_ASSERT
(
isValid
());
391
if
(!
isEmpty
())
392
scaleFast
(scale);
393
}
394
395
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::scaleFast
(
PxF32
scale)
396
{
397
PX_ASSERT
(
isValid
());
398
*
this
=
centerExtents
(
getCenter
(),
getExtents
() * scale);
399
}
400
401
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::fattenSafe
(
PxReal
distance)
402
{
403
PX_ASSERT
(
isValid
());
404
if
(!
isEmpty
())
405
fattenFast
(distance);
406
}
407
408
PX_CUDA_CALLABLE
PX_FORCE_INLINE
void
PxBounds3::fattenFast
(
PxReal
distance)
409
{
410
PX_ASSERT
(
isValid
());
411
minimum
.
x
-= distance;
412
minimum
.
y
-= distance;
413
minimum
.
z
-= distance;
414
415
maximum
.
x
+= distance;
416
maximum
.
y
+= distance;
417
maximum
.
z
+= distance;
418
}
419
420
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
PxBounds3::transformSafe
(
const
PxMat33
& matrix,
const
PxBounds3
& bounds)
421
{
422
PX_ASSERT
(bounds.
isValid
());
423
return
!bounds.
isEmpty
() ?
transformFast
(matrix, bounds) : bounds;
424
}
425
426
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
PxBounds3::transformFast
(
const
PxMat33
& matrix,
const
PxBounds3
& bounds)
427
{
428
PX_ASSERT
(bounds.
isValid
());
429
return
PxBounds3::basisExtent
(matrix * bounds.
getCenter
(), matrix, bounds.
getExtents
());
430
}
431
432
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
PxBounds3::transformSafe
(
const
PxTransform
& transform,
const
PxBounds3
& bounds)
433
{
434
PX_ASSERT
(bounds.
isValid
());
435
return
!bounds.
isEmpty
() ?
transformFast
(transform, bounds) : bounds;
436
}
437
438
PX_CUDA_CALLABLE
PX_INLINE
PxBounds3
PxBounds3::transformFast
(
const
PxTransform
& transform,
const
PxBounds3
& bounds)
439
{
440
PX_ASSERT
(bounds.
isValid
());
441
return
PxBounds3::basisExtent
(transform.
transform
(bounds.
getCenter
()),
PxMat33
(transform.
q
), bounds.
getExtents
());
442
}
443
444
PX_CUDA_CALLABLE
PX_FORCE_INLINE
bool
PxBounds3::isValid
()
const
445
{
446
return
(
isFinite
() &&
447
(((
minimum
.
x
<=
maximum
.
x
) && (
minimum
.
y
<=
maximum
.
y
) && (
minimum
.
z
<=
maximum
.
z
)) ||
448
((
minimum
.
x
==
PX_MAX_BOUNDS_EXTENTS
) && (
minimum
.
y
==
PX_MAX_BOUNDS_EXTENTS
) && (
minimum
.
z
==
PX_MAX_BOUNDS_EXTENTS
) &&
449
(
maximum
.
x
== -
PX_MAX_BOUNDS_EXTENTS
) && (
maximum
.
y
== -
PX_MAX_BOUNDS_EXTENTS
) && (
maximum
.
z
== -
PX_MAX_BOUNDS_EXTENTS
)))
450
);
451
}
452
453
#ifndef PX_DOXYGEN
454
}
// namespace physx
455
#endif
456
458
#endif // PX_FOUNDATION_PX_BOUNDS3_H
Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved.
www.nvidia.com