RavEngine
Loading...
Searching...
No Matches
PxGeometryHelpers.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_GEOMETRY_HELPERS_H
30#define PX_GEOMETRY_HELPERS_H
35#include "foundation/PxPlane.h"
36#include "foundation/PxTransform.h"
37#include "foundation/PxUnionCast.h"
38#include "common/PxPhysXCommonConfig.h"
39#include "geometry/PxGeometry.h"
40#include "geometry/PxBoxGeometry.h"
41#include "geometry/PxSphereGeometry.h"
42#include "geometry/PxCapsuleGeometry.h"
43#include "geometry/PxPlaneGeometry.h"
44#include "geometry/PxConvexMeshGeometry.h"
45#include "geometry/PxHeightFieldGeometry.h"
46#include "geometry/PxParticleSystemGeometry.h"
47#include "geometry/PxHairSystemGeometry.h"
48#include "geometry/PxTetrahedronMeshGeometry.h"
49#include "geometry/PxCustomGeometry.h"
50
51#if !PX_DOXYGEN
52namespace physx
53{
54#endif
55
64PX_ALIGN_PREFIX(4)
66{
67 class PxInvalidGeometry : public PxGeometry
68 {
69 public:
70 PX_INLINE PxInvalidGeometry() : PxGeometry(PxGeometryType::eINVALID) {}
71 };
72
73public:
75 {
76 return any().getType();
77 }
78
80 {
81 return *PxUnionCast<PxGeometry*>(&bytes.geometry);
82 }
83
84 PX_FORCE_INLINE const PxGeometry& any() const
85 {
86 return *PxUnionCast<const PxGeometry*>(&bytes.geometry);
87 }
88
90 PX_FORCE_INLINE PxSphereGeometry& sphere() { return get<PxSphereGeometry, PxGeometryType::eSPHERE>(); }
91 PX_FORCE_INLINE const PxSphereGeometry& sphere() const { return get<const PxSphereGeometry, PxGeometryType::eSPHERE>(); }
92
93 PX_FORCE_INLINE PxPlaneGeometry& plane() { return get<PxPlaneGeometry, PxGeometryType::ePLANE>(); }
94 PX_FORCE_INLINE const PxPlaneGeometry& plane() const { return get<const PxPlaneGeometry, PxGeometryType::ePLANE>(); }
95
96 PX_FORCE_INLINE PxCapsuleGeometry& capsule() { return get<PxCapsuleGeometry, PxGeometryType::eCAPSULE>(); }
97 PX_FORCE_INLINE const PxCapsuleGeometry& capsule() const { return get<const PxCapsuleGeometry, PxGeometryType::eCAPSULE>(); }
98
99 PX_FORCE_INLINE PxBoxGeometry& box() { return get<PxBoxGeometry, PxGeometryType::eBOX>(); }
100 PX_FORCE_INLINE const PxBoxGeometry& box() const { return get<const PxBoxGeometry, PxGeometryType::eBOX>(); }
101
102 PX_FORCE_INLINE PxConvexMeshGeometry& convexMesh() { return get<PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>(); }
103 PX_FORCE_INLINE const PxConvexMeshGeometry& convexMesh() const { return get<const PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>(); }
104
105 PX_FORCE_INLINE PxTetrahedronMeshGeometry& tetMesh() { return get<PxTetrahedronMeshGeometry, PxGeometryType::eTETRAHEDRONMESH>(); }
106 PX_FORCE_INLINE const PxTetrahedronMeshGeometry& tetMesh() const { return get<const PxTetrahedronMeshGeometry, PxGeometryType::eTETRAHEDRONMESH>(); }
107
108 PX_FORCE_INLINE PxTriangleMeshGeometry& triangleMesh() { return get<PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>(); }
109 PX_FORCE_INLINE const PxTriangleMeshGeometry& triangleMesh() const { return get<const PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>(); }
110
111 PX_FORCE_INLINE PxHeightFieldGeometry& heightField() { return get<PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>(); }
112 PX_FORCE_INLINE const PxHeightFieldGeometry& heightField() const { return get<const PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>(); }
113
114 PX_FORCE_INLINE PxParticleSystemGeometry& particleSystem() { return get<PxParticleSystemGeometry, PxGeometryType::ePARTICLESYSTEM>(); }
115 PX_FORCE_INLINE const PxParticleSystemGeometry& particleSystem() const { return get<const PxParticleSystemGeometry, PxGeometryType::ePARTICLESYSTEM>(); }
116
117 PX_FORCE_INLINE PxHairSystemGeometry& hairSystem() { return get<PxHairSystemGeometry, PxGeometryType::eHAIRSYSTEM>(); }
118 PX_FORCE_INLINE const PxHairSystemGeometry& hairSystem() const { return get<const PxHairSystemGeometry, PxGeometryType::eHAIRSYSTEM>(); }
119
120 PX_FORCE_INLINE PxCustomGeometry& custom() { return get<PxCustomGeometry, PxGeometryType::eCUSTOM>(); }
121 PX_FORCE_INLINE const PxCustomGeometry& custom() const { return get<const PxCustomGeometry, PxGeometryType::eCUSTOM>(); }
123
124 PX_FORCE_INLINE void storeAny(const PxGeometry& geometry)
125 {
126 PX_ASSERT_WITH_MESSAGE( (geometry.getType() >= PxGeometryType::eSPHERE) &&
127 (geometry.getType() < PxGeometryType::eGEOMETRY_COUNT),
128 "Unexpected GeometryType in PxGeometryHolder::storeAny");
129
130 switch(geometry.getType())
131 {
132 case PxGeometryType::eSPHERE: put<PxSphereGeometry>(geometry); break;
133 case PxGeometryType::ePLANE: put<PxPlaneGeometry>(geometry); break;
134 case PxGeometryType::eCAPSULE: put<PxCapsuleGeometry>(geometry); break;
135 case PxGeometryType::eBOX: put<PxBoxGeometry>(geometry); break;
136 case PxGeometryType::eCONVEXMESH: put<PxConvexMeshGeometry>(geometry); break;
137 case PxGeometryType::eTRIANGLEMESH: put<PxTriangleMeshGeometry>(geometry); break;
138 case PxGeometryType::eTETRAHEDRONMESH: put<PxTetrahedronMeshGeometry>(geometry); break;
139 case PxGeometryType::eHEIGHTFIELD: put<PxHeightFieldGeometry>(geometry); break;
140 case PxGeometryType::ePARTICLESYSTEM: put<PxParticleSystemGeometry>(geometry); break;
141 case PxGeometryType::eHAIRSYSTEM: put<PxHairSystemGeometry>(geometry); break;
142 case PxGeometryType::eCUSTOM: put<PxCustomGeometry>(geometry); break;
144 case PxGeometryType::eINVALID: break;
145 }
146 }
147
148 PX_FORCE_INLINE PxGeometryHolder() { put<PxInvalidGeometry>(PxInvalidGeometry()); }
149 PX_FORCE_INLINE PxGeometryHolder(const PxGeometry& geometry){ storeAny(geometry); }
150
151 private:
152 template<typename T> void put(const PxGeometry& geometry)
153 {
154 static_cast<T&>(any()) = static_cast<const T&>(geometry);
155 }
156
157 template<typename T, PxGeometryType::Enum type> T& get()
158 {
159 PX_ASSERT(getType() == type);
160 return static_cast<T&>(any());
161 }
162
163 template<typename T, PxGeometryType::Enum type> T& get() const
164 {
165 PX_ASSERT(getType() == type);
166 return static_cast<T&>(any());
167 }
168
169 union {
170 PxU8 geometry[sizeof(PxGeometry)];
171 PxU8 box[sizeof(PxBoxGeometry)];
172 PxU8 sphere[sizeof(PxSphereGeometry)];
173 PxU8 capsule[sizeof(PxCapsuleGeometry)];
174 PxU8 plane[sizeof(PxPlaneGeometry)];
175 PxU8 convex[sizeof(PxConvexMeshGeometry)];
176 PxU8 tetMesh[sizeof(PxTetrahedronMeshGeometry)];
177 PxU8 mesh[sizeof(PxTriangleMeshGeometry)];
178 PxU8 heightfield[sizeof(PxHeightFieldGeometry)];
179 PxU8 particleSystem[sizeof(PxParticleSystemGeometry)];
180 PxU8 hairSystem[sizeof(PxHairSystemGeometry)];
181 PxU8 custom[sizeof(PxCustomGeometry)];
182 } bytes;
183}
184PX_ALIGN_SUFFIX(4);
185
186#if !PX_DOXYGEN
187} // namespace physx
188#endif
189
191#endif
Definition format.h:4067
Class representing the geometry of a box.
Definition PxBoxGeometry.h:49
Class representing the geometry of a capsule.
Definition PxCapsuleGeometry.h:54
Convex mesh geometry class.
Definition PxConvexMeshGeometry.h:79
Custom geometry class. This class allows user to create custom geometries by providing a set of virtu...
Definition PxCustomGeometry.h:52
Geometry holder class.
Definition PxGeometryHelpers.h:66
A geometry object.
Definition PxGeometry.h:79
Hair system geometry class.
Definition PxHairSystemGeometry.h:45
Height field geometry class.
Definition PxHeightFieldGeometry.h:55
Particle system geometry class.
Definition PxParticleSystemGeometry.h:51
Class describing a plane geometry.
Definition PxPlaneGeometry.h:56
A class representing the geometry of a sphere.
Definition PxSphereGeometry.h:48
Tetrahedron mesh geometry class.
Definition PxTetrahedronMeshGeometry.h:50
Triangle mesh geometry class.
Definition PxTriangleMeshGeometry.h:81
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Enum
Definition PxGeometry.h:52
@ eGEOMETRY_COUNT
internal use only!
Definition PxGeometry.h:65
@ eINVALID
internal use only!
Definition PxGeometry.h:66