PxGeometryHelpers.h
Go to the documentation of this file.
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 
31 #ifndef PX_PHYSICS_GEOMETRYHELPERS
32 #define PX_PHYSICS_GEOMETRYHELPERS
33 
37 #include "foundation/PxPlane.h"
38 #include "foundation/PxTransform.h"
39 #include "foundation/PxUnionCast.h"
41 #include "geometry/PxGeometry.h"
42 #include "geometry/PxBoxGeometry.h"
48 
49 #if !PX_DOXYGEN
50 namespace physx
51 {
52 #endif
53 
65 {
66 public:
68  {
69  return any().getType();
70  }
71 
73  {
74  return *PxUnionCast<PxGeometry*>(&bytes.geometry);
75  }
76 
77  PX_FORCE_INLINE const PxGeometry& any() const
78  {
79  return *PxUnionCast<const PxGeometry*>(&bytes.geometry);
80  }
81 
83  {
84  return get<PxSphereGeometry, PxGeometryType::eSPHERE>();
85  }
86 
88  {
89  return get<const PxSphereGeometry, PxGeometryType::eSPHERE>();
90  }
91 
93  {
94  return get<PxPlaneGeometry, PxGeometryType::ePLANE>();
95  }
96 
98  {
99  return get<const PxPlaneGeometry, PxGeometryType::ePLANE>();
100  }
101 
103  {
104  return get<PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
105  }
106 
108  {
109  return get<const PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
110  }
111 
113  {
114  return get<PxBoxGeometry, PxGeometryType::eBOX>();
115  }
116 
118  {
119  return get<const PxBoxGeometry, PxGeometryType::eBOX>();
120  }
121 
123  {
124  return get<PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
125  }
126 
128  {
129  return get<const PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
130  }
131 
133  {
134  return get<PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
135  }
136 
138  {
139  return get<const PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
140  }
141 
143  {
144  return get<PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
145  }
146 
148  {
149  return get<const PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
150  }
151 
153  {
156  "Unexpected GeometryType in PxGeometryHolder::storeAny");
157 
158  switch(geometry.getType())
159  {
160  case PxGeometryType::eSPHERE: put<PxSphereGeometry>(geometry); break;
161  case PxGeometryType::ePLANE: put<PxPlaneGeometry>(geometry); break;
162  case PxGeometryType::eCAPSULE: put<PxCapsuleGeometry>(geometry); break;
163  case PxGeometryType::eBOX: put<PxBoxGeometry>(geometry); break;
164  case PxGeometryType::eCONVEXMESH: put<PxConvexMeshGeometry>(geometry); break;
165  case PxGeometryType::eTRIANGLEMESH: put<PxTriangleMeshGeometry>(geometry); break;
166  case PxGeometryType::eHEIGHTFIELD: put<PxHeightFieldGeometry>(geometry); break;
168  case PxGeometryType::eINVALID: break;
169  }
170  }
171 
174 
175  private:
176  template<typename T> void put(const PxGeometry& geometry)
177  {
178  static_cast<T&>(any()) = static_cast<const T&>(geometry);
179  }
180 
181  template<typename T, PxGeometryType::Enum type> T& get()
182  {
183  PX_ASSERT(getType() == type);
184  return static_cast<T&>(any());
185  }
186 
187  template<typename T, PxGeometryType::Enum type> T& get() const
188  {
189  PX_ASSERT(getType() == type);
190  return static_cast<T&>(any());
191  }
192 
193  union {
202  } bytes;
203 }
204 PX_ALIGN_SUFFIX(4);
205 
206 
207 
208 
209 #if !PX_DOXYGEN
210 } // namespace physx
211 #endif
212 
214 #endif
Definition: GuContactBuffer.h:37
PX_CUDA_CALLABLE PX_FORCE_INLINE PxGeometryType::Enum getType() const
Returns the type of the geometry.
Definition: PxGeometry.h:82
PX_FORCE_INLINE const PxTriangleMeshGeometry & triangleMesh() const
Definition: PxGeometryHelpers.h:137
PX_FORCE_INLINE const PxHeightFieldGeometry & heightField() const
Definition: PxGeometryHelpers.h:147
PX_FORCE_INLINE void storeAny(const PxGeometry &geometry)
Definition: PxGeometryHelpers.h:152
PxU8 heightfield[sizeof(PxHeightFieldGeometry)]
Definition: PxGeometryHelpers.h:222
Class representing the geometry of a capsule.
Definition: PxCapsuleGeometry.h:55
PxU8 plane[sizeof(PxPlaneGeometry)]
Definition: PxGeometryHelpers.h:219
PX_FORCE_INLINE PxGeometry & any()
Definition: PxGeometryHelpers.h:93
PxU8 sphere[sizeof(PxSphereGeometry)]
Definition: PxGeometryHelpers.h:217
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
A class representing the geometry of a sphere.
Definition: PxSphereGeometry.h:49
PX_FORCE_INLINE PxGeometry & any()
Definition: PxGeometryHelpers.h:72
Definition: PxGeometry.h:57
Definition: PxGeometry.h:61
A geometry object.
Definition: PxGeometry.h:75
Definition: PxGeometry.h:55
internal use only!
Definition: PxGeometry.h:62
Height field geometry class.
Definition: PxHeightFieldGeometry.h:56
PX_FORCE_INLINE PxPlaneGeometry & plane()
Definition: PxGeometryHelpers.h:92
PX_FORCE_INLINE const PxCapsuleGeometry & capsule() const
Definition: PxGeometryHelpers.h:107
PxU8 mesh[sizeof(PxTriangleMeshGeometry)]
Definition: PxGeometryHelpers.h:221
PX_FORCE_INLINE PxConvexMeshGeometry & convexMesh()
Definition: PxGeometryHelpers.h:122
PX_FORCE_INLINE const PxGeometry & any() const
Definition: PxGeometryHelpers.h:77
PxU8 geometry[sizeof(PxGeometry)]
Definition: PxGeometryHelpers.h:215
internal use only!
Definition: PxGeometry.h:63
PX_FORCE_INLINE const PxPlaneGeometry & plane() const
Definition: PxGeometryHelpers.h:97
PX_FORCE_INLINE PxGeometryType::Enum getType() const
Definition: PxGeometryHelpers.h:88
#define PX_ALIGN_PREFIX(alignment)
Definition: PxPreprocessor.h:409
uint8_t PxU8
Definition: PxSimpleTypes.h:75
Enum
Definition: PxGeometry.h:53
PX_FORCE_INLINE PxGeometryHolder()
Definition: PxGeometryHelpers.h:172
PX_FORCE_INLINE const PxConvexMeshGeometry & convexMesh() const
Definition: PxGeometryHelpers.h:127
PX_FORCE_INLINE const PxBoxGeometry & box() const
Definition: PxGeometryHelpers.h:117
void put(const PxGeometry &geometry)
Definition: PxGeometryHelpers.h:176
Geometry holder class.
Definition: PxGeometryHelpers.h:64
union @3 bytes
Class describing a plane geometry.
Definition: PxPlaneGeometry.h:59
PxU8 convex[sizeof(PxConvexMeshGeometry)]
Definition: PxGeometryHelpers.h:220
PX_FORCE_INLINE PxSphereGeometry & sphere()
Definition: PxGeometryHelpers.h:82
PX_FORCE_INLINE PxTriangleMeshGeometry & triangleMesh()
Definition: PxGeometryHelpers.h:132
Definition: PxGeometry.h:59
#define PX_ASSERT_WITH_MESSAGE(condition, message)
Definition: PxAssert.h:61
PX_FORCE_INLINE void storeAny(const PxGeometry &geometry)
Definition: PxGeometryHelpers.h:173
PX_FORCE_INLINE PxGeometryHolder()
Definition: PxGeometryHelpers.h:193
Definition: PxGeometry.h:58
PxU8 box[sizeof(PxBoxGeometry)]
Definition: PxGeometryHelpers.h:216
PX_FORCE_INLINE PxGeometryType::Enum getType() const
Definition: PxGeometryHelpers.h:67
PxU8 capsule[sizeof(PxCapsuleGeometry)]
Definition: PxGeometryHelpers.h:218
#define PX_ASSERT(exp)
Definition: PxAssert.h:59
Definition: PxGeometry.h:60
class PxGeometryHolder PX_ALIGN_SUFFIX(4)
PX_FORCE_INLINE PxCapsuleGeometry & capsule()
Definition: PxGeometryHelpers.h:102
PX_FORCE_INLINE PxHeightFieldGeometry & heightField()
Definition: PxGeometryHelpers.h:142
PX_FORCE_INLINE const PxSphereGeometry & sphere() const
Definition: PxGeometryHelpers.h:87
Definition: PxGeometry.h:56
Triangle mesh geometry class.
Definition: PxTriangleMeshGeometry.h:82
Convex mesh geometry class.
Definition: PxConvexMeshGeometry.h:80
Class representing the geometry of a box.
Definition: PxBoxGeometry.h:50
PX_FORCE_INLINE PxBoxGeometry & box()
Definition: PxGeometryHelpers.h:112