| 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_EXTENSIONS_DEFAULTSIMULATIONFILTERSHADER_H |
| 15 | #define PX_PHYSICS_EXTENSIONS_DEFAULTSIMULATIONFILTERSHADER_H |
| 16 | /** \addtogroup extensions |
| 17 | @{ |
| 18 | */ |
| 19 | |
| 20 | #include "PxPhysXConfig.h" |
| 21 | |
| 22 | #include "PxFiltering.h" |
| 23 | |
| 24 | #ifndef PX_DOXYGEN |
| 25 | namespace physx |
| 26 | { |
| 27 | #endif |
| 28 | |
| 29 | class PxActor; |
| 30 | |
| 31 | /** |
| 32 | \brief 64-bit mask used for collision filtering. |
| 33 | |
| 34 | The collision filtering equation for 2 objects o0 and o1 is: |
| 35 | |
| 36 | <pre> (G0 op0 K0) op2 (G1 op1 K1) == b </pre> |
| 37 | |
| 38 | with |
| 39 | |
| 40 | <ul> |
| 41 | <li> G0 = PxGroupsMask for object o0. See PxSetGroupsMask </li> |
| 42 | <li> G1 = PxGroupsMask for object o1. See PxSetGroupsMask </li> |
| 43 | <li> K0 = filtering constant 0. See PxSetFilterConstants </li> |
| 44 | <li> K1 = filtering constant 1. See PxSetFilterConstants </li> |
| 45 | <li> b = filtering boolean. See PxSetFilterBool </li> |
| 46 | <li> op0, op1, op2 = filtering operations. See PxSetFilterOps </li> |
| 47 | </ul> |
| 48 | |
| 49 | If the filtering equation is true, collision detection is enabled. |
| 50 | |
| 51 | @see PxSetFilterOps() |
| 52 | */ |
| 53 | class PxGroupsMask |
| 54 | { |
| 55 | public: |
| 56 | PX_INLINE PxGroupsMask():bits0(0),bits1(0),bits2(0),bits3(0) {} |
| 57 | PX_INLINE ~PxGroupsMask() {} |
| 58 | |
| 59 | PxU16 bits0, bits1, bits2, bits3; |
| 60 | }; |
| 61 | |
| 62 | /** |
| 63 | \brief Collision filtering operations. |
| 64 | |
| 65 | @see PxGroupsMask |
| 66 | */ |
| 67 | struct PxFilterOp |
| 68 | { |
| 69 | enum Enum |
| 70 | { |
| 71 | PX_FILTEROP_AND, |
| 72 | PX_FILTEROP_OR, |
| 73 | PX_FILTEROP_XOR, |
| 74 | PX_FILTEROP_NAND, |
| 75 | PX_FILTEROP_NOR, |
| 76 | PX_FILTEROP_NXOR, |
| 77 | PX_FILTEROP_SWAP_AND |
| 78 | }; |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | \brief Implementation of a simple filter shader that emulates PhysX 2.8.x filtering |
| 83 | |
| 84 | This shader provides the following logic: |
| 85 | \li If one of the two filter objects is a trigger, the pair is acccepted and #PxPairFlag::eTRIGGER_DEFAULT will be used for trigger reports |
| 86 | \li Else, if the filter mask logic (see further below) discards the pair it will be suppressed (#PxFilterFlag::eSUPPRESS) |
| 87 | \li Else, the pair gets accepted and collision response gets enabled (#PxPairFlag::eCONTACT_DEFAULT) |
| 88 | |
| 89 | Filter mask logic: |
| 90 | Given the two #PxFilterData structures fd0 and fd1 of two collision objects, the pair passes the filter if the following |
| 91 | conditions are met: |
| 92 | |
| 93 | 1) Collision groups of the pair are enabled |
| 94 | 2) Collision filtering equation is satisfied |
| 95 | |
| 96 | @see PxSimulationFilterShader |
| 97 | */ |
| 98 | |
| 99 | PxFilterFlags PxDefaultSimulationFilterShader( |
| 100 | PxFilterObjectAttributes attributes0, |
| 101 | PxFilterData filterData0, |
| 102 | PxFilterObjectAttributes attributes1, |
| 103 | PxFilterData filterData1, |
| 104 | PxPairFlags& pairFlags, |
| 105 | const void* constantBlock, |
| 106 | PxU32 constantBlockSize); |
| 107 | |
| 108 | /** |
| 109 | \brief Determines if collision detection is performed between a pair of groups |
| 110 | |
| 111 | \note Collision group is an integer between 0 and 31. |
| 112 | |
| 113 | \param[in] group1 First Group |
| 114 | \param[in] group2 Second Group |
| 115 | |
| 116 | \return True if the groups could collide |
| 117 | |
| 118 | @see PxSetGroupCollisionFlag |
| 119 | */ |
| 120 | bool PxGetGroupCollisionFlag(const PxU16 group1, const PxU16 group2); |
| 121 | |
| 122 | /** |
| 123 | \brief Specifies if collision should be performed by a pair of groups |
| 124 | |
| 125 | \note Collision group is an integer between 0 and 31. |
| 126 | |
| 127 | \param[in] group1 First Group |
| 128 | \param[in] group2 Second Group |
| 129 | \param[in] enable True to enable collision between the groups |
| 130 | |
| 131 | @see PxGetGroupCollisionFlag |
| 132 | */ |
| 133 | void PxSetGroupCollisionFlag(const PxU16 group1, const PxU16 group2, const bool enable); |
| 134 | |
| 135 | /** |
| 136 | \brief Retrieves the value set with PxSetGroup() |
| 137 | |
| 138 | \note Collision group is an integer between 0 and 31. |
| 139 | |
| 140 | \param[in] actor The actor |
| 141 | |
| 142 | \return The collision group this actor belongs to |
| 143 | |
| 144 | @see PxSetGroup |
| 145 | */ |
| 146 | PxU16 PxGetGroup(const PxActor& actor); |
| 147 | |
| 148 | /** |
| 149 | \brief Sets which collision group this actor is part of |
| 150 | |
| 151 | \note Collision group is an integer between 0 and 31. |
| 152 | |
| 153 | \param[in] actor The actor |
| 154 | \param[in] collisionGroup Collision group this actor belongs to |
| 155 | |
| 156 | @see PxGetGroup |
| 157 | */ |
| 158 | void PxSetGroup(PxActor& actor, const PxU16 collisionGroup); |
| 159 | |
| 160 | /** |
| 161 | \brief Retrieves filtering operation. See comments for PxGroupsMask |
| 162 | |
| 163 | \param[out] op0 First filter operator. |
| 164 | \param[out] op1 Second filter operator. |
| 165 | \param[out] op2 Third filter operator. |
| 166 | |
| 167 | \return the filter operations requested |
| 168 | |
| 169 | @see PxSetFilterOps PxSetFilterBool PxSetFilterConstants |
| 170 | */ |
| 171 | void PxGetFilterOps(PxFilterOp::Enum& op0, PxFilterOp::Enum& op1, PxFilterOp::Enum& op2); |
| 172 | |
| 173 | /** |
| 174 | \brief Setups filtering operations. See comments for PxGroupsMask |
| 175 | |
| 176 | \param[in] op0 Filter op 0. |
| 177 | \param[in] op1 Filter op 1. |
| 178 | \param[in] op2 Filter op 2. |
| 179 | |
| 180 | @see PxSetFilterBool PxSetFilterConstants |
| 181 | */ |
| 182 | void PxSetFilterOps(const PxFilterOp::Enum& op0, const PxFilterOp::Enum& op1, const PxFilterOp::Enum& op2); |
| 183 | |
| 184 | /** |
| 185 | \brief Retrieves filtering's boolean value. See comments for PxGroupsMask |
| 186 | |
| 187 | \return flag Boolean value for filter. |
| 188 | |
| 189 | @see PxSetFilterBool PxSetFilterConstants |
| 190 | */ |
| 191 | bool PxGetFilterBool(); |
| 192 | |
| 193 | /** |
| 194 | \brief Setups filtering's boolean value. See comments for PxGroupsMask |
| 195 | |
| 196 | \param[in] enable Boolean value for filter. |
| 197 | |
| 198 | @see PxSetFilterOps PxSsetFilterConstants |
| 199 | */ |
| 200 | void PxSetFilterBool(const bool enable); |
| 201 | |
| 202 | /** |
| 203 | \brief Gets filtering constant K0 and K1. See comments for PxGroupsMask |
| 204 | |
| 205 | \return the filtering constants, as a mask. See #PxGroupsMask. |
| 206 | |
| 207 | @see PxSetFilterOps PxSetFilterBool PxSetFilterConstants |
| 208 | */ |
| 209 | void PxGetFilterConstants(PxGroupsMask& c0, PxGroupsMask& c1); |
| 210 | |
| 211 | /** |
| 212 | \brief Setups filtering's K0 and K1 value. See comments for PxGroupsMask |
| 213 | |
| 214 | \param[in] c0 The new group mask. See #PxGroupsMask. |
| 215 | \param[in] c1 The new group mask. See #PxGroupsMask. |
| 216 | |
| 217 | @see PxSetFilterOps PxSetFilterBool PxGetFilterConstants |
| 218 | */ |
| 219 | void PxSetFilterConstants(const PxGroupsMask& c0, const PxGroupsMask& c1); |
| 220 | |
| 221 | /** |
| 222 | \brief Gets 64-bit mask used for collision filtering. See comments for PxGroupsMask |
| 223 | |
| 224 | \param[in] actor The actor |
| 225 | |
| 226 | \return The group mask for the actor. |
| 227 | |
| 228 | @see PxSetGroupsMask() |
| 229 | */ |
| 230 | PxGroupsMask PxGetGroupsMask(const PxActor& actor); |
| 231 | |
| 232 | /** |
| 233 | \brief Sets 64-bit mask used for collision filtering. See comments for PxGroupsMask |
| 234 | |
| 235 | \param[in] actor The actor |
| 236 | \param[in] mask The group mask to set for the actor. |
| 237 | |
| 238 | @see PxGetGroupsMask() |
| 239 | */ |
| 240 | void PxSetGroupsMask(PxActor& actor, const PxGroupsMask& mask); |
| 241 | |
| 242 | #ifndef PX_DOXYGEN |
| 243 | } // namespace physx |
| 244 | #endif |
| 245 | |
| 246 | /** @} */ |
| 247 | #endif |
| 248 | |