| 1 | /* |
| 2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
| 5 | * and proprietary rights in and to this software, related documentation |
| 6 | * and any modifications thereto. Any use, reproduction, disclosure or |
| 7 | * distribution of this software and related documentation without an express |
| 8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
| 9 | */ |
| 10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
| 11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
| 12 | |
| 13 | |
| 14 | #ifndef PX_PHYSICS_NX_HEIGHTFIELD_GEOMETRY |
| 15 | #define PX_PHYSICS_NX_HEIGHTFIELD_GEOMETRY |
| 16 | /** \addtogroup geomutils |
| 17 | @{ |
| 18 | */ |
| 19 | #include "geometry/PxTriangleMeshGeometry.h" |
| 20 | #include "common/PxCoreUtilityTypes.h" |
| 21 | |
| 22 | #ifndef PX_DOXYGEN |
| 23 | namespace physx |
| 24 | { |
| 25 | #endif |
| 26 | |
| 27 | #define PX_MIN_HEIGHTFIELD_XZ_SCALE 1e-8f |
| 28 | #define PX_MIN_HEIGHTFIELD_Y_SCALE (0.0001f / PxReal(0xFFFF)) |
| 29 | |
| 30 | class PxHeightField; |
| 31 | |
| 32 | /** |
| 33 | \brief Height field geometry class. |
| 34 | |
| 35 | This class allows to create a scaled height field geometry instance. |
| 36 | |
| 37 | There is a minimum allowed value for Y and XZ scaling - PX_MIN_HEIGHTFIELD_XZ_SCALE, heightfield creation will fail if XZ value is below this value. |
| 38 | */ |
| 39 | class PxHeightFieldGeometry : public PxGeometry |
| 40 | { |
| 41 | public: |
| 42 | PX_INLINE PxHeightFieldGeometry() : |
| 43 | PxGeometry (PxGeometryType::eHEIGHTFIELD), |
| 44 | heightField (NULL), |
| 45 | heightScale (1.0f), |
| 46 | rowScale (1.0f), |
| 47 | columnScale (1.0f), |
| 48 | heightFieldFlags(0) |
| 49 | {} |
| 50 | |
| 51 | PX_INLINE PxHeightFieldGeometry(PxHeightField* hf, |
| 52 | PxMeshGeometryFlags flags, |
| 53 | PxReal heightScale_, |
| 54 | PxReal rowScale_, |
| 55 | PxReal columnScale_) : |
| 56 | PxGeometry (PxGeometryType::eHEIGHTFIELD), |
| 57 | heightField (hf) , |
| 58 | heightScale (heightScale_), |
| 59 | rowScale (rowScale_), |
| 60 | columnScale (columnScale_), |
| 61 | heightFieldFlags (flags) |
| 62 | { |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | \brief Returns true if the geometry is valid. |
| 67 | |
| 68 | \return True if the current settings are valid |
| 69 | |
| 70 | \note A valid height field has a positive scale value in each direction (heightScale > 0, rowScale > 0, columnScale > 0). |
| 71 | It is illegal to call PxRigidActor::createShape and PxPhysics::createShape with a height field that has zero extents in any direction. |
| 72 | |
| 73 | @see PxRigidActor::createShape, PxPhysics::createShape |
| 74 | */ |
| 75 | PX_INLINE bool isValid() const; |
| 76 | |
| 77 | public: |
| 78 | /** |
| 79 | \brief The height field data. |
| 80 | */ |
| 81 | PxHeightField* heightField; |
| 82 | |
| 83 | /** |
| 84 | \brief The scaling factor for the height field in vertical direction (y direction in local space). |
| 85 | */ |
| 86 | PxReal heightScale; |
| 87 | |
| 88 | /** |
| 89 | \brief The scaling factor for the height field in the row direction (x direction in local space). |
| 90 | */ |
| 91 | PxReal rowScale; |
| 92 | |
| 93 | /** |
| 94 | \brief The scaling factor for the height field in the column direction (z direction in local space). |
| 95 | */ |
| 96 | PxReal columnScale; |
| 97 | |
| 98 | /** |
| 99 | \brief Flags to specify some collision properties for the height field. |
| 100 | */ |
| 101 | PxMeshGeometryFlags heightFieldFlags; |
| 102 | |
| 103 | PxPadding<3> paddingFromFlags; //< padding for mesh flags. |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | PX_INLINE bool PxHeightFieldGeometry::isValid() const |
| 108 | { |
| 109 | if (mType != PxGeometryType::eHEIGHTFIELD) |
| 110 | return false; |
| 111 | if (!PxIsFinite(heightScale) || !PxIsFinite(rowScale) || !PxIsFinite(columnScale)) |
| 112 | return false; |
| 113 | if (rowScale < PX_MIN_HEIGHTFIELD_XZ_SCALE || columnScale < PX_MIN_HEIGHTFIELD_XZ_SCALE || heightScale < PX_MIN_HEIGHTFIELD_Y_SCALE) |
| 114 | return false; |
| 115 | if (!heightField) |
| 116 | return false; |
| 117 | |
| 118 | return true; |
| 119 | } |
| 120 | |
| 121 | #ifndef PX_DOXYGEN |
| 122 | } // namespace physx |
| 123 | #endif |
| 124 | |
| 125 | /** @} */ |
| 126 | #endif |
| 127 | |