| 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_CCT_MANAGER | 
| 32 | #define PX_PHYSICS_CCT_MANAGER | 
| 33 | /** \addtogroup character | 
| 34 |   @{ | 
| 35 | */ | 
| 36 |  | 
| 37 | #include "PxPhysXConfig.h" | 
| 38 | #include "foundation/PxFlags.h" | 
| 39 | #include "foundation/PxErrorCallback.h" | 
| 40 | #include "common/PxRenderBuffer.h" | 
| 41 |  | 
| 42 | #if !PX_DOXYGEN | 
| 43 | namespace physx | 
| 44 | { | 
| 45 | #endif | 
| 46 |  | 
| 47 | class PxPhysics; | 
| 48 | class PxScene; | 
| 49 | class PxController; | 
| 50 | class PxControllerDesc; | 
| 51 | class PxObstacleContext; | 
| 52 | class PxControllerFilterCallback; | 
| 53 |  | 
| 54 | /** | 
| 55 | \brief specifies debug-rendering flags | 
| 56 | */ | 
| 57 | struct PxControllerDebugRenderFlag | 
| 58 | { | 
| 59 | 	enum Enum | 
| 60 | 	{ | 
| 61 | 		eTEMPORAL_BV	= (1<<0),	//!< Temporal bounding volume around controllers | 
| 62 | 		eCACHED_BV		= (1<<1),	//!< Cached bounding volume around controllers | 
| 63 | 		eOBSTACLES		= (1<<2),	//!< User-defined obstacles | 
| 64 |  | 
| 65 | 		eNONE			= 0, | 
| 66 | 		eALL			= 0xffffffff | 
| 67 | 	}; | 
| 68 | }; | 
| 69 |  | 
| 70 | /** | 
| 71 | \brief Bitfield that contains a set of raised flags defined in PxControllerDebugRenderFlag. | 
| 72 |  | 
| 73 | @see PxControllerDebugRenderFlag | 
| 74 | */ | 
| 75 | typedef PxFlags<PxControllerDebugRenderFlag::Enum, PxU32> PxControllerDebugRenderFlags; | 
| 76 | PX_FLAGS_OPERATORS(PxControllerDebugRenderFlag::Enum, PxU32) | 
| 77 |  | 
| 78 |  | 
| 79 | /** | 
| 80 | \brief Manages an array of character controllers. | 
| 81 |  | 
| 82 | @see PxController PxBoxController PxCapsuleController | 
| 83 | */ | 
| 84 | class PxControllerManager | 
| 85 | { | 
| 86 | public: | 
| 87 | 	/** | 
| 88 | 	\brief Releases the controller manager. | 
| 89 |  | 
| 90 | 	\note This will release all associated controllers and obstacle contexts. | 
| 91 |  | 
| 92 | 	\note This function is required to be called to release foundation usage. | 
| 93 |  | 
| 94 | 	*/ | 
| 95 | 	virtual void				release() = 0; | 
| 96 |  | 
| 97 | 	/** | 
| 98 | 	\brief Returns the scene the manager is adding the controllers to. | 
| 99 |  | 
| 100 | 	\return The associated physics scene. | 
| 101 | 	*/ | 
| 102 | 	virtual PxScene&			getScene() const = 0; | 
| 103 |  | 
| 104 | 	/** | 
| 105 | 	\brief Returns the number of controllers that are being managed. | 
| 106 |  | 
| 107 | 	\return The number of controllers. | 
| 108 | 	*/ | 
| 109 | 	virtual PxU32				getNbControllers() const = 0; | 
| 110 |  | 
| 111 | 	/** | 
| 112 | 	\brief Retrieve one of the controllers in the manager. | 
| 113 |  | 
| 114 | 	\param index the index of the controller to return | 
| 115 | 	\return The controller with the specified index. | 
| 116 | 	*/ | 
| 117 | 	virtual PxController*		getController(PxU32 index) = 0; | 
| 118 |  | 
| 119 | 	/** | 
| 120 | 	\brief Creates a new character controller. | 
| 121 |  | 
| 122 | 	\param[in] desc The controllers descriptor | 
| 123 | 	\return The new controller | 
| 124 |  | 
| 125 | 	@see PxController PxController.release() PxControllerDesc | 
| 126 | 	*/ | 
| 127 | 	virtual PxController*		createController(const PxControllerDesc& desc) = 0; | 
| 128 |  | 
| 129 | 	/** | 
| 130 | 	\brief Releases all the controllers that are being managed. | 
| 131 | 	*/ | 
| 132 | 	virtual void				purgeControllers() = 0; | 
| 133 |  | 
| 134 | 	/** | 
| 135 | 	\brief Retrieves debug data. | 
| 136 |  | 
| 137 | 	\return The render buffer filled with debug-render data | 
| 138 |  | 
| 139 | 	@see PxControllerManager.setDebugRenderingFlags() | 
| 140 | 	*/ | 
| 141 | 	virtual	PxRenderBuffer&		getRenderBuffer()		= 0; | 
| 142 |  | 
| 143 | 	/** | 
| 144 | 	\brief Sets debug rendering flags | 
| 145 |  | 
| 146 | 	\param[in] flags The debug rendering flags (combination of PxControllerDebugRenderFlags) | 
| 147 |  | 
| 148 | 	@see PxControllerManager.getRenderBuffer() PxControllerDebugRenderFlags | 
| 149 | 	*/ | 
| 150 | 	virtual	void				setDebugRenderingFlags(PxControllerDebugRenderFlags flags)	= 0; | 
| 151 |  | 
| 152 | 	/** | 
| 153 | 	\brief Returns the number of obstacle contexts that are being managed. | 
| 154 |  | 
| 155 | 	\return The number of obstacle contexts. | 
| 156 | 	*/ | 
| 157 | 	virtual PxU32				getNbObstacleContexts() const = 0; | 
| 158 |  | 
| 159 | 	/** | 
| 160 | 	\brief Retrieve one of the obstacle contexts in the manager. | 
| 161 |  | 
| 162 | 	\param index The index of the obstacle context to retrieve. | 
| 163 | 	\return The obstacle context with the specified index. | 
| 164 | 	*/ | 
| 165 | 	virtual PxObstacleContext*	getObstacleContext(PxU32 index) = 0; | 
| 166 |  | 
| 167 | 	/** | 
| 168 | 	\brief Creates an obstacle context. | 
| 169 |  | 
| 170 | 	\return New obstacle context | 
| 171 |  | 
| 172 | 	@see PxObstacleContext | 
| 173 | 	*/ | 
| 174 | 	virtual	PxObstacleContext*	createObstacleContext()	= 0; | 
| 175 |  | 
| 176 | 	/** | 
| 177 | 	\brief Computes character-character interactions. | 
| 178 |  | 
| 179 | 	This function is an optional helper to properly resolve interactions between characters, in case they overlap (which can happen for gameplay reasons, etc). | 
| 180 |  | 
| 181 | 	You should call this once per frame, before your PxController::move() calls. The function will not move the characters directly, but it will | 
| 182 | 	compute overlap information for each character that will be used in the next move() call. | 
| 183 | 	 | 
| 184 | 	You need to provide a proper time value here so that interactions are resolved in a way that do not depend on the framerate. | 
| 185 |  | 
| 186 | 	If you only have one character in the scene, or if you can guarantee your characters will never overlap, then you do not need to call this function. | 
| 187 |  | 
| 188 | 	\note Releasing the manager will automatically release all the associated obstacle contexts. | 
| 189 |  | 
| 190 | 	\param[in] elapsedTime	Elapsed time since last call | 
| 191 | 	\param[in] cctFilterCb	Filtering callback for CCT-vs-CCT interactions | 
| 192 | 	*/ | 
| 193 | 	virtual	void				computeInteractions(PxF32 elapsedTime, PxControllerFilterCallback* cctFilterCb=NULL) = 0; | 
| 194 |  | 
| 195 | 	/** | 
| 196 | 	\brief Enables or disables runtime tessellation. | 
| 197 |  | 
| 198 | 	Large triangles can create accuracy issues in the sweep code, which in turn can lead to characters not sliding smoothly | 
| 199 | 	against geometries, or even penetrating them. This feature allows one to reduce those issues by tessellating large | 
| 200 | 	triangles at runtime, before performing sweeps against them. The amount of tessellation is controlled by the 'maxEdgeLength' parameter. | 
| 201 | 	Any triangle with at least one edge length greater than the maxEdgeLength will get recursively tessellated, until resulting triangles are small enough. | 
| 202 |  | 
| 203 | 	This features only applies to triangle meshes, convex meshes, heightfields and boxes. | 
| 204 |  | 
| 205 | 	\param[in] flag				True/false to enable/disable runtime tessellation. | 
| 206 | 	\param[in] maxEdgeLength	Max edge length allowed before tessellation kicks in. | 
| 207 | 	*/ | 
| 208 | 	virtual	void				setTessellation(bool flag, float maxEdgeLength) = 0; | 
| 209 |  | 
| 210 | 	/** | 
| 211 | 	\brief Enables or disables the overlap recovery module. | 
| 212 |  | 
| 213 | 	The overlap recovery module can be used to depenetrate CCTs from static objects when an overlap is detected. This can happen | 
| 214 | 	in three main cases: | 
| 215 | 		- when the CCT is directly spawned or teleported in another object | 
| 216 | 		- when the CCT algorithm fails due to limited FPU accuracy | 
| 217 | 		- when the "up vector" is modified, making the rotated CCT shape overlap surrounding objects | 
| 218 |  | 
| 219 | 	When activated, the CCT module will automatically try to resolve the penetration, and move the CCT to a safe place where it does | 
| 220 | 	not overlap other objects anymore. This only concerns static objects, dynamic objects are ignored by the recovery module. | 
| 221 |  | 
| 222 | 	When the recovery module is not activated, it is possible for the CCTs to go through static objects. By default, the recovery | 
| 223 | 	module is enabled. | 
| 224 |  | 
| 225 | 	The recovery module currently works with all geometries except heightfields. | 
| 226 |  | 
| 227 | 	\param[in] flag				True/false to enable/disable overlap recovery module. | 
| 228 | 	*/ | 
| 229 | 	virtual	void				setOverlapRecoveryModule(bool flag) = 0; | 
| 230 |  | 
| 231 | 	/** | 
| 232 | 	\brief Enables or disables the precise sweeps. | 
| 233 |  | 
| 234 | 	Precise sweeps are more accurate, but also potentially slower than regular sweeps. | 
| 235 |  | 
| 236 | 	By default, precise sweeps are enabled. | 
| 237 |  | 
| 238 | 	\param[in] flag				True/false to enable/disable precise sweeps. | 
| 239 | 	*/ | 
| 240 | 	virtual	void				setPreciseSweeps(bool flag) = 0; | 
| 241 |  | 
| 242 | 	/** | 
| 243 | 	\brief Enables or disables vertical sliding against ceilings. | 
| 244 |  | 
| 245 | 	Geometry is seen as "ceilings" when the following condition is met: | 
| 246 |  | 
| 247 | 		dot product(contact normal, up direction)<0.0f | 
| 248 |  | 
| 249 | 	This flag controls whether characters should slide vertically along the geometry in that case. | 
| 250 |  | 
| 251 | 	By default, sliding is allowed. | 
| 252 |  | 
| 253 | 	\param[in] flag				True/false to enable/disable sliding. | 
| 254 | 	*/ | 
| 255 | 	virtual	void				setPreventVerticalSlidingAgainstCeiling(bool flag) = 0; | 
| 256 |  | 
| 257 | 	/** | 
| 258 | 	\brief Shift the origin of the character controllers and obstacle objects by the specified vector. | 
| 259 |  | 
| 260 | 	The positions of all character controllers, obstacle objects and the corresponding data structures will get adjusted to reflect the shifted origin location | 
| 261 | 	(the shift vector will get subtracted from all character controller and obstacle object positions). | 
| 262 |  | 
| 263 | 	\note It is the user's responsibility to keep track of the summed total origin shift and adjust all input/output to/from PhysXCharacterKinematic accordingly. | 
| 264 |  | 
| 265 | 	\note This call will not automatically shift the PhysX scene and its objects. You need to call PxScene::shiftOrigin() seperately to keep the systems in sync. | 
| 266 |  | 
| 267 | 	\param[in] shift Translation vector to shift the origin by. | 
| 268 | 	*/ | 
| 269 | 	virtual	void				shiftOrigin(const PxVec3& shift) = 0; | 
| 270 |  | 
| 271 | protected: | 
| 272 | 	PxControllerManager() {} | 
| 273 | 	virtual ~PxControllerManager() {} | 
| 274 | }; | 
| 275 |  | 
| 276 | #if !PX_DOXYGEN | 
| 277 | } // namespace physx | 
| 278 | #endif | 
| 279 |  | 
| 280 | 	/** | 
| 281 | 	\brief Creates the controller manager. | 
| 282 |  | 
| 283 | 	\param[in] scene PhysX scene. | 
| 284 | 	\param[in] lockingEnabled Enables/disables internal locking. | 
| 285 |  | 
| 286 | 	The character controller is informed by #PxDeletionListener::onRelease() when actors or shapes are released, and updates its internal | 
| 287 | 	caches accordingly. If character controller movement or a call to #PxControllerManager::shiftOrigin() may overlap with actor/shape releases, | 
| 288 | 	internal data structures must be guarded against concurrent access. | 
| 289 |  | 
| 290 | 	Locking guarantees thread safety in such scenarios. | 
| 291 |  | 
| 292 | 	\note locking may result in significant slowdown for release of actors or shapes. | 
| 293 |  | 
| 294 | 	By default, locking is disabled. | 
| 295 | 	*/ | 
| 296 | PX_C_EXPORT physx::PxControllerManager* PX_CALL_CONV PxCreateControllerManager(physx::PxScene& scene, bool lockingEnabled = false); | 
| 297 |  | 
| 298 | /** @} */ | 
| 299 | #endif //PX_PHYSICS_CCT_MANAGER | 
| 300 |  |