1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30#ifndef GU_CENTER_EXTENTS_H
31#define GU_CENTER_EXTENTS_H
32
33/** \addtogroup geomutils
34@{
35*/
36
37#include "CmMatrix34.h"
38#include "CmUtils.h"
39#include "PsUserAllocated.h"
40
41namespace physx
42{
43namespace Gu
44{
45 class CenterExtents : public physx::shdfnd::UserAllocated
46 {
47 public:
48 PX_FORCE_INLINE CenterExtents() {}
49 PX_FORCE_INLINE CenterExtents(const PxBounds3& b) { mCenter = b.getCenter(); mExtents = b.getExtents(); }
50 PX_FORCE_INLINE ~CenterExtents() {}
51
52 PX_FORCE_INLINE void getMin(PxVec3& min) const { min = mCenter - mExtents; }
53 PX_FORCE_INLINE void getMax(PxVec3& max) const { max = mCenter + mExtents; }
54
55 PX_FORCE_INLINE float getMin(PxU32 axis) const { return mCenter[axis] - mExtents[axis]; }
56 PX_FORCE_INLINE float getMax(PxU32 axis) const { return mCenter[axis] + mExtents[axis]; }
57
58 PX_FORCE_INLINE PxVec3 getMin() const { return mCenter - mExtents; }
59 PX_FORCE_INLINE PxVec3 getMax() const { return mCenter + mExtents; }
60
61 PX_FORCE_INLINE void setMinMax(const PxVec3& min, const PxVec3& max)
62 {
63 mCenter = (max + min)*0.5f;
64 mExtents = (max - min)*0.5f;
65 }
66
67 PX_FORCE_INLINE PxU32 isInside(const CenterExtents& box) const
68 {
69 if(box.getMin(axis: 0)>getMin(axis: 0)) return 0;
70 if(box.getMin(axis: 1)>getMin(axis: 1)) return 0;
71 if(box.getMin(axis: 2)>getMin(axis: 2)) return 0;
72 if(box.getMax(axis: 0)<getMax(axis: 0)) return 0;
73 if(box.getMax(axis: 1)<getMax(axis: 1)) return 0;
74 if(box.getMax(axis: 2)<getMax(axis: 2)) return 0;
75 return 1;
76 }
77
78 PX_FORCE_INLINE void setEmpty()
79 {
80 mExtents = PxVec3(-PX_MAX_BOUNDS_EXTENTS);
81 }
82
83 PX_FORCE_INLINE bool isEmpty() const
84 {
85 return Cm::isEmpty(c: mCenter, e: mExtents);
86 }
87
88 PX_FORCE_INLINE bool isFinite() const
89 {
90 return mCenter.isFinite() && mExtents.isFinite();
91 }
92
93 PX_FORCE_INLINE bool isValid() const
94 {
95 return Cm::isValid(c: mCenter, e: mExtents);
96 }
97
98 PX_FORCE_INLINE PxBounds3 transformFast(const PxMat33& matrix) const
99 {
100 PX_ASSERT(isValid());
101 return PxBounds3::basisExtent(center: matrix * mCenter, basis: matrix, extent: mExtents);
102 }
103
104 PX_INLINE PxBounds3 transformSafe(const Cm::Matrix34& matrix) const
105 {
106 if(isEmpty())
107 return PxBounds3::centerExtents(center: mCenter, extent: mExtents);
108 else
109 return Cm::basisExtent(center: matrix.transform(other: mCenter), basis0: matrix.m.column0, basis1: matrix.m.column1, basis2: matrix.m.column2, extent: mExtents);
110 }
111
112 PxVec3 mCenter;
113 PxVec3 mExtents;
114 };
115
116 //! A padded version of CenterExtents, to safely load its data using SIMD
117 class CenterExtentsPadded : public CenterExtents
118 {
119 public:
120 PX_FORCE_INLINE CenterExtentsPadded() {}
121 PX_FORCE_INLINE ~CenterExtentsPadded() {}
122 PxU32 padding;
123 };
124 PX_COMPILE_TIME_ASSERT(sizeof(CenterExtentsPadded) == 7*4);
125
126}
127
128}
129
130/** @} */
131#endif
132

source code of qtquick3dphysics/src/3rdparty/PhysX/source/geomutils/src/GuCenterExtents.h