PhysX SDK 3.2 API Reference: PxGeometryHelpers.h Source File

PhysX SDK 3.2 API

PxGeometryHelpers.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you 
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and 
00007 // any modifications thereto. Any use, reproduction, disclosure, or 
00008 // distribution of this software and related documentation without an express 
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 // 
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2012 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00029 
00030 
00031 #ifndef PX_PHYSICS_GEOMETRYHELPERS
00032 #define PX_PHYSICS_GEOMETRYHELPERS
00033 
00037 #include "common/PxPhysXCommon.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 "PxTriangleMeshGeometry.h"
00045 #include "PxHeightFieldGeometry.h"
00046 #include "foundation/PxPlane.h"
00047 #include "foundation/PxTransform.h"
00048 #include "foundation/PxUnionCast.h"
00049 
00050 #ifndef PX_DOXYGEN
00051 namespace physx
00052 {
00053 #endif
00054 
00064 PX_ALIGN_PREFIX(4)
00065 class PxGeometryHolder
00066 {
00067 public:
00068     PX_FORCE_INLINE PxGeometryType::Enum getType() const
00069     {
00070         return any().getType();
00071     }
00072 
00073     PX_FORCE_INLINE PxGeometry& any()
00074     { 
00075         return *PxUnionCast<PxGeometry*>(&bytes.geometry); 
00076     }
00077 
00078     PX_FORCE_INLINE const PxGeometry& any() const 
00079     { 
00080         return *PxUnionCast<const PxGeometry*>(&bytes.geometry); 
00081     }
00082 
00083     PX_FORCE_INLINE PxSphereGeometry& sphere()
00084     {
00085         return get<PxSphereGeometry, PxGeometryType::eSPHERE>();
00086     }
00087 
00088     PX_FORCE_INLINE const PxSphereGeometry& sphere() const
00089     {
00090         return get<const PxSphereGeometry, PxGeometryType::eSPHERE>();
00091     }
00092 
00093     PX_FORCE_INLINE PxPlaneGeometry& plane()
00094     {
00095         return get<PxPlaneGeometry, PxGeometryType::ePLANE>();
00096     }
00097 
00098     PX_FORCE_INLINE const PxPlaneGeometry& plane() const
00099     {
00100         return get<const PxPlaneGeometry, PxGeometryType::ePLANE>();
00101     }
00102 
00103 
00104     PX_FORCE_INLINE PxCapsuleGeometry& capsule()
00105     {
00106         return get<PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
00107     }
00108 
00109     PX_FORCE_INLINE const PxCapsuleGeometry& capsule() const
00110     {
00111         return get<const PxCapsuleGeometry, PxGeometryType::eCAPSULE>();
00112     }
00113 
00114 
00115     PX_FORCE_INLINE PxBoxGeometry& box()
00116     {
00117         return get<PxBoxGeometry, PxGeometryType::eBOX>();
00118     }
00119 
00120     PX_FORCE_INLINE const PxBoxGeometry& box() const
00121     {
00122         return get<const PxBoxGeometry, PxGeometryType::eBOX>();
00123     }
00124 
00125     PX_FORCE_INLINE PxConvexMeshGeometry& convexMesh()
00126     {
00127         return get<PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
00128     }
00129 
00130     PX_FORCE_INLINE const PxConvexMeshGeometry& convexMesh() const
00131     {
00132         return get<const PxConvexMeshGeometry, PxGeometryType::eCONVEXMESH>();
00133     }
00134 
00135 
00136     PX_FORCE_INLINE PxTriangleMeshGeometry& triangleMesh()
00137     {
00138         return get<PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
00139     }
00140 
00141     PX_FORCE_INLINE const PxTriangleMeshGeometry& triangleMesh() const
00142     {
00143         return get<const PxTriangleMeshGeometry, PxGeometryType::eTRIANGLEMESH>();
00144     }
00145 
00146     PX_FORCE_INLINE PxHeightFieldGeometry& heightField()
00147     {
00148         return get<PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
00149     }
00150 
00151     PX_FORCE_INLINE const PxHeightFieldGeometry& heightField() const
00152     {
00153         return get<const PxHeightFieldGeometry, PxGeometryType::eHEIGHTFIELD>();
00154     }
00155 
00156     private:
00157         template<typename T, PxGeometryType::Enum type> T& get()
00158         {
00159             PX_ASSERT(getType() == type);
00160             return static_cast<T&>(any());
00161         }
00162 
00163         template<typename T, PxGeometryType::Enum type> T& get() const
00164         {
00165             PX_ASSERT(getType() == type);
00166             return static_cast<T&>(any());
00167         }
00168 
00169 
00170     union {
00171         PxU8    geometry[sizeof(PxGeometry)];
00172         PxU8    box[sizeof(PxBoxGeometry)];
00173         PxU8    sphere[sizeof(PxSphereGeometry)];
00174         PxU8    capsule[sizeof(PxCapsuleGeometry)];
00175         PxU8    plane[sizeof(PxPlaneGeometry)];
00176         PxU8    convex[sizeof(PxConvexMeshGeometry)];
00177         PxU8    mesh[sizeof(PxTriangleMeshGeometry)];
00178         PxU8    heightfield[sizeof(PxHeightFieldGeometry)];
00179     } bytes;
00180 }
00181 PX_ALIGN_SUFFIX(4);
00182 
00183 
00184 
00185 
00186 #ifndef PX_DOXYGEN
00187 } // namespace physx
00188 #endif
00189 
00191 #endif


Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com