00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PX_PHYSICS_GEOMETRYHELPERS
00032 #define PX_PHYSICS_GEOMETRYHELPERS
00033
00037 #include "common/PxPhysXCommonConfig.h"
00038 #include "PxGeometry.h"
00039 #include "PxBoxGeometry.h"
00040 #include "PxSphereGeometry.h"
00041 #include "PxCapsuleGeometry.h"
00042 #include "PxPlaneGeometry.h"
00043 #include "PxConvexMeshGeometry.h"
00044 #include "PxHeightFieldGeometry.h"
00045 #include "foundation/PxPlane.h"
00046 #include "foundation/PxTransform.h"
00047 #include "foundation/PxUnionCast.h"
00048
00049 #if !PX_DOXYGEN
00050 namespace physx
00051 {
00052 #endif
00053
00063 PX_ALIGN_PREFIX(4)
00064 class PxGeometryHolder
00065 {
00066 public:
00067 PX_FORCE_INLINE PxGeometryType::Enum getType() const
00068 {
00069 return any().getType();
00070 }
00071
00072 PX_FORCE_INLINE PxGeometry& any()
00073 {
00074 return *PxUnionCast<PxGeometry*>(&bytes.geometry);
00075 }
00076
00077 PX_FORCE_INLINE const PxGeometry& any() const
00078 {
00079 return *PxUnionCast<const PxGeometry*>(&bytes.geometry);
00080 }
00081
00082 PX_FORCE_INLINE PxSphereGeometry& sphere()
00083 {
00084 return get<PxSphereGeometry, PxGeometryType::eSPHERE>();
00085 }
00086
00087 PX_FORCE_INLINE const PxSphereGeometry& sphere() const
00088 {
00089 return get<const PxSphereGeometry, PxGeometryType::eSPHERE>();
00090 }
00091
00092 PX_FORCE_INLINE PxPlaneGeometry& plane()
00093 {
00094 return get<PxPlaneGeometry, PxGeometryType::ePLANE>();
00095 }
00096
00097 PX_FORCE_INLINE const PxPlaneGeometry& plane() const
00098 {
00099 return get<const PxPlaneGeometry, PxGeometryType::ePLANE>();
00100 }
00101
00102 PX_FORCE_INLINE PxCapsuleGeometry& capsule()
00103 {
00104 return get<PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
00105 }
00106
00107 PX_FORCE_INLINE const PxCapsuleGeometry& capsule() const
00108 {
00109 return get<const PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
00110 }
00111
00112 PX_FORCE_INLINE PxBoxGeometry& box()
00113 {
00114 return get<PxBoxGeometry, PxGeometryType::eBOX>();
00115 }
00116
00117 PX_FORCE_INLINE const PxBoxGeometry& box() const
00118 {
00119 return get<const PxBoxGeometry, PxGeometryType::eBOX>();
00120 }
00121
00122 PX_FORCE_INLINE PxConvexMeshGeometry& convexMesh()
00123 {
00124 return get<PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
00125 }
00126
00127 PX_FORCE_INLINE const PxConvexMeshGeometry& convexMesh() const
00128 {
00129 return get<const PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
00130 }
00131
00132 PX_FORCE_INLINE PxTriangleMeshGeometry& triangleMesh()
00133 {
00134 return get<PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
00135 }
00136
00137 PX_FORCE_INLINE const PxTriangleMeshGeometry& triangleMesh() const
00138 {
00139 return get<const PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
00140 }
00141
00142 PX_FORCE_INLINE PxHeightFieldGeometry& heightField()
00143 {
00144 return get<PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
00145 }
00146
00147 PX_FORCE_INLINE const PxHeightFieldGeometry& heightField() const
00148 {
00149 return get<const PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
00150 }
00151
00152 PX_FORCE_INLINE void storeAny(const PxGeometry& geometry)
00153 {
00154 PX_ASSERT_WITH_MESSAGE( (geometry.getType() >= PxGeometryType::eSPHERE) &&
00155 (geometry.getType() < PxGeometryType::eGEOMETRY_COUNT),
00156 "Unexpected GeometryType in PxGeometryHolder::storeAny");
00157
00158 switch(geometry.getType())
00159 {
00160 case PxGeometryType::eSPHERE: put<PxSphereGeometry>(geometry); break;
00161 case PxGeometryType::ePLANE: put<PxPlaneGeometry>(geometry); break;
00162 case PxGeometryType::eCAPSULE: put<PxCapsuleGeometry>(geometry); break;
00163 case PxGeometryType::eBOX: put<PxBoxGeometry>(geometry); break;
00164 case PxGeometryType::eCONVEXMESH: put<PxConvexMeshGeometry>(geometry); break;
00165 case PxGeometryType::eTRIANGLEMESH: put<PxTriangleMeshGeometry>(geometry); break;
00166 case PxGeometryType::eHEIGHTFIELD: put<PxHeightFieldGeometry>(geometry); break;
00167 case PxGeometryType::eGEOMETRY_COUNT:
00168 case PxGeometryType::eINVALID: break;
00169 }
00170 }
00171
00172 PX_FORCE_INLINE PxGeometryHolder() {}
00173 PX_FORCE_INLINE PxGeometryHolder(const PxGeometry& geometry){ storeAny(geometry); }
00174
00175 private:
00176 template<typename T> void put(const PxGeometry& geometry)
00177 {
00178 static_cast<T&>(any()) = static_cast<const T&>(geometry);
00179 }
00180
00181 template<typename T, PxGeometryType::Enum type> T& get()
00182 {
00183 PX_ASSERT(getType() == type);
00184 return static_cast<T&>(any());
00185 }
00186
00187 template<typename T, PxGeometryType::Enum type> T& get() const
00188 {
00189 PX_ASSERT(getType() == type);
00190 return static_cast<T&>(any());
00191 }
00192
00193 union {
00194 PxU8 geometry[sizeof(PxGeometry)];
00195 PxU8 box[sizeof(PxBoxGeometry)];
00196 PxU8 sphere[sizeof(PxSphereGeometry)];
00197 PxU8 capsule[sizeof(PxCapsuleGeometry)];
00198 PxU8 plane[sizeof(PxPlaneGeometry)];
00199 PxU8 convex[sizeof(PxConvexMeshGeometry)];
00200 PxU8 mesh[sizeof(PxTriangleMeshGeometry)];
00201 PxU8 heightfield[sizeof(PxHeightFieldGeometry)];
00202 } bytes;
00203 }
00204 PX_ALIGN_SUFFIX(4);
00205
00206
00207
00208
00209 #if !PX_DOXYGEN
00210 }
00211 #endif
00212
00214 #endif