| 1 | // | 
| 2 | // Redistribution and use in source and binary forms, with or without | 
| 3 | // modification, are permitted provided that the following conditions | 
| 4 | // are met: | 
| 5 | //  * Redistributions of source code must retain the above copyright | 
| 6 | //    notice, this list of conditions and the following disclaimer. | 
| 7 | //  * Redistributions in binary form must reproduce the above copyright | 
| 8 | //    notice, this list of conditions and the following disclaimer in the | 
| 9 | //    documentation and/or other materials provided with the distribution. | 
| 10 | //  * Neither the name of NVIDIA CORPORATION nor the names of its | 
| 11 | //    contributors may be used to endorse or promote products derived | 
| 12 | //    from this software without specific prior written permission. | 
| 13 | // | 
| 14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY | 
| 15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| 16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 
| 17 | // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR | 
| 18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 
| 19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 
| 20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 
| 21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 
| 22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
| 23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| 24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| 25 | // | 
| 26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. | 
| 27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. | 
| 28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.   | 
| 29 |  | 
| 30 |  | 
| 31 | #ifndef PX_PHYSICS_EXTENSIONS_DEFAULTSIMULATIONFILTERSHADER_H | 
| 32 | #define PX_PHYSICS_EXTENSIONS_DEFAULTSIMULATIONFILTERSHADER_H | 
| 33 | /** \addtogroup extensions | 
| 34 |   @{ | 
| 35 | */ | 
| 36 |  | 
| 37 | #include "PxPhysXConfig.h" | 
| 38 |  | 
| 39 | #include "PxFiltering.h" | 
| 40 |  | 
| 41 | #if !PX_DOXYGEN | 
| 42 | namespace physx | 
| 43 | { | 
| 44 | #endif | 
| 45 |  | 
| 46 | class PxActor; | 
| 47 |  | 
| 48 | /** | 
| 49 | \brief 64-bit mask used for collision filtering. | 
| 50 |  | 
| 51 | The collision filtering equation for 2 objects o0 and o1 is: | 
| 52 |  | 
| 53 | <pre> (G0 op0 K0) op2 (G1 op1 K1) == b </pre> | 
| 54 |  | 
| 55 | with | 
| 56 |  | 
| 57 | <ul> | 
| 58 | <li> G0 = PxGroupsMask for object o0. See PxSetGroupsMask </li> | 
| 59 | <li> G1 = PxGroupsMask for object o1. See PxSetGroupsMask </li> | 
| 60 | <li> K0 = filtering constant 0. See PxSetFilterConstants </li> | 
| 61 | <li> K1 = filtering constant 1. See PxSetFilterConstants </li> | 
| 62 | <li> b = filtering boolean. See PxSetFilterBool </li> | 
| 63 | <li> op0, op1, op2 = filtering operations. See PxSetFilterOps </li> | 
| 64 | </ul> | 
| 65 |  | 
| 66 | If the filtering equation is true, collision detection is enabled. | 
| 67 |  | 
| 68 | @see PxSetFilterOps() | 
| 69 | */ | 
| 70 | class PxGroupsMask | 
| 71 | { | 
| 72 | public: | 
| 73 | 	PX_INLINE	PxGroupsMask():bits0(0),bits1(0),bits2(0),bits3(0) {} | 
| 74 | 	PX_INLINE	~PxGroupsMask() {} | 
| 75 | 	 | 
| 76 | 	PxU16		bits0, bits1, bits2, bits3; | 
| 77 | }; | 
| 78 |  | 
| 79 | /** | 
| 80 | \brief Collision filtering operations. | 
| 81 |  | 
| 82 | @see PxGroupsMask | 
| 83 | */ | 
| 84 | struct PxFilterOp | 
| 85 | { | 
| 86 | 	enum Enum | 
| 87 | 	{ | 
| 88 | 		PX_FILTEROP_AND, | 
| 89 | 		PX_FILTEROP_OR, | 
| 90 | 		PX_FILTEROP_XOR, | 
| 91 | 		PX_FILTEROP_NAND, | 
| 92 | 		PX_FILTEROP_NOR, | 
| 93 | 		PX_FILTEROP_NXOR, | 
| 94 | 		PX_FILTEROP_SWAP_AND | 
| 95 | 	}; | 
| 96 | }; | 
| 97 |  | 
| 98 | /** | 
| 99 | \brief Implementation of a simple filter shader that emulates PhysX 2.8.x filtering | 
| 100 |  | 
| 101 | This shader provides the following logic: | 
| 102 | \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 | 
| 103 | \li Else, if the filter mask logic (see further below) discards the pair it will be suppressed (#PxFilterFlag::eSUPPRESS) | 
| 104 | \li Else, the pair gets accepted and collision response gets enabled (#PxPairFlag::eCONTACT_DEFAULT) | 
| 105 |  | 
| 106 | Filter mask logic: | 
| 107 | Given the two #PxFilterData structures fd0 and fd1 of two collision objects, the pair passes the filter if the following | 
| 108 | conditions are met: | 
| 109 |  | 
| 110 | 	1) Collision groups of the pair are enabled | 
| 111 | 	2) Collision filtering equation is satisfied | 
| 112 |  | 
| 113 | @see PxSimulationFilterShader | 
| 114 | */ | 
| 115 |  | 
| 116 | PxFilterFlags PxDefaultSimulationFilterShader( | 
| 117 | 	PxFilterObjectAttributes attributes0, | 
| 118 | 	PxFilterData filterData0,  | 
| 119 | 	PxFilterObjectAttributes attributes1, | 
| 120 | 	PxFilterData filterData1, | 
| 121 | 	PxPairFlags& pairFlags, | 
| 122 | 	const void* constantBlock, | 
| 123 | 	PxU32 constantBlockSize); | 
| 124 |  | 
| 125 | /** | 
| 126 | 	\brief Determines if collision detection is performed between a pair of groups | 
| 127 |  | 
| 128 | 	\note Collision group is an integer between 0 and 31. | 
| 129 |  | 
| 130 | 	\param[in] group1 First Group | 
| 131 | 	\param[in] group2 Second Group | 
| 132 |  | 
| 133 | 	\return True if the groups could collide | 
| 134 |  | 
| 135 | 	@see PxSetGroupCollisionFlag | 
| 136 | */ | 
| 137 | bool PxGetGroupCollisionFlag(const PxU16 group1, const PxU16 group2); | 
| 138 |  | 
| 139 | /** | 
| 140 | 	\brief Specifies if collision should be performed by a pair of groups | 
| 141 |  | 
| 142 | 	\note Collision group is an integer between 0 and 31. | 
| 143 |  | 
| 144 | 	\param[in] group1 First Group | 
| 145 | 	\param[in] group2 Second Group | 
| 146 | 	\param[in] enable True to enable collision between the groups | 
| 147 |  | 
| 148 | 	@see PxGetGroupCollisionFlag | 
| 149 | */ | 
| 150 | void PxSetGroupCollisionFlag(const PxU16 group1, const PxU16 group2, const bool enable); | 
| 151 |  | 
| 152 | /** | 
| 153 | 	\brief Retrieves the value set with PxSetGroup() | 
| 154 |  | 
| 155 | 	\note Collision group is an integer between 0 and 31. | 
| 156 |  | 
| 157 | 	\param[in] actor The actor | 
| 158 |  | 
| 159 | 	\return The collision group this actor belongs to | 
| 160 |  | 
| 161 | 	@see PxSetGroup | 
| 162 | */ | 
| 163 | PxU16 PxGetGroup(const PxActor& actor); | 
| 164 |  | 
| 165 | /** | 
| 166 | 	\brief Sets which collision group this actor is part of | 
| 167 |  | 
| 168 | 	\note Collision group is an integer between 0 and 31. | 
| 169 |  | 
| 170 | 	\param[in] actor The actor | 
| 171 | 	\param[in] collisionGroup Collision group this actor belongs to | 
| 172 |  | 
| 173 | 	@see PxGetGroup | 
| 174 | */ | 
| 175 | void PxSetGroup(PxActor& actor, const PxU16 collisionGroup); | 
| 176 |  | 
| 177 | /** | 
| 178 | \brief Retrieves filtering operation. See comments for PxGroupsMask | 
| 179 |  | 
| 180 | \param[out] op0 First filter operator. | 
| 181 | \param[out] op1 Second filter operator. | 
| 182 | \param[out] op2 Third filter operator. | 
| 183 |  | 
| 184 | @see PxSetFilterOps PxSetFilterBool PxSetFilterConstants | 
| 185 | */ | 
| 186 | void PxGetFilterOps(PxFilterOp::Enum& op0, PxFilterOp::Enum& op1, PxFilterOp::Enum& op2); | 
| 187 |  | 
| 188 | /** | 
| 189 | \brief Setups filtering operations. See comments for PxGroupsMask | 
| 190 |  | 
| 191 | \param[in] op0 Filter op 0. | 
| 192 | \param[in] op1 Filter op 1. | 
| 193 | \param[in] op2 Filter op 2. | 
| 194 |  | 
| 195 | @see PxSetFilterBool PxSetFilterConstants | 
| 196 | */ | 
| 197 | void PxSetFilterOps(const PxFilterOp::Enum& op0, const PxFilterOp::Enum& op1, const PxFilterOp::Enum& op2); | 
| 198 |  | 
| 199 | /** | 
| 200 | \brief Retrieves filtering's boolean value. See comments for PxGroupsMask | 
| 201 |  | 
| 202 | \return flag Boolean value for filter. | 
| 203 |  | 
| 204 | @see PxSetFilterBool PxSetFilterConstants | 
| 205 | */ | 
| 206 | bool PxGetFilterBool(); | 
| 207 |  | 
| 208 | /** | 
| 209 | \brief Setups filtering's boolean value. See comments for PxGroupsMask | 
| 210 |  | 
| 211 | \param[in] enable Boolean value for filter. | 
| 212 |  | 
| 213 | @see PxSetFilterOps PxSsetFilterConstants | 
| 214 | */ | 
| 215 | void PxSetFilterBool(const bool enable); | 
| 216 |  | 
| 217 | /** | 
| 218 | \brief Gets filtering constant K0 and K1. See comments for PxGroupsMask | 
| 219 |  | 
| 220 | \param[out] c0 the filtering constants, as a mask. See #PxGroupsMask. | 
| 221 | \param[out] c1 the filtering constants, as a mask. See #PxGroupsMask. | 
| 222 |  | 
| 223 | @see PxSetFilterOps PxSetFilterBool PxSetFilterConstants | 
| 224 | */ | 
| 225 | void PxGetFilterConstants(PxGroupsMask& c0, PxGroupsMask& c1); | 
| 226 |  | 
| 227 | /** | 
| 228 | \brief Setups filtering's K0 and K1 value. See comments for PxGroupsMask | 
| 229 |  | 
| 230 | \param[in] c0 The new group mask. See #PxGroupsMask. | 
| 231 | \param[in] c1 The new group mask. See #PxGroupsMask. | 
| 232 |  | 
| 233 | @see PxSetFilterOps PxSetFilterBool PxGetFilterConstants | 
| 234 | */ | 
| 235 | void PxSetFilterConstants(const PxGroupsMask& c0, const PxGroupsMask& c1); | 
| 236 |  | 
| 237 | /** | 
| 238 | \brief Gets 64-bit mask used for collision filtering. See comments for PxGroupsMask | 
| 239 |  | 
| 240 | \param[in] actor The actor | 
| 241 |  | 
| 242 | \return The group mask for the actor. | 
| 243 |  | 
| 244 | @see PxSetGroupsMask() | 
| 245 | */ | 
| 246 | PxGroupsMask PxGetGroupsMask(const PxActor& actor); | 
| 247 |  | 
| 248 | /** | 
| 249 | \brief Sets 64-bit mask used for collision filtering. See comments for PxGroupsMask | 
| 250 |  | 
| 251 | \param[in] actor The actor | 
| 252 | \param[in] mask The group mask to set for the actor. | 
| 253 |  | 
| 254 | @see PxGetGroupsMask() | 
| 255 | */ | 
| 256 | void PxSetGroupsMask(PxActor& actor, const PxGroupsMask& mask); | 
| 257 |  | 
| 258 | #if !PX_DOXYGEN | 
| 259 | } // namespace physx | 
| 260 | #endif | 
| 261 |  | 
| 262 | /** @} */ | 
| 263 | #endif | 
| 264 |  |