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_ACTOR |
15 | #define PX_PHYSICS_NX_ACTOR |
16 | |
17 | /** \addtogroup physics |
18 | @{ |
19 | */ |
20 | |
21 | #include "PxPhysXConfig.h" |
22 | #include "foundation/PxBounds3.h" |
23 | #include "PxClient.h" |
24 | #include "common/PxBase.h" |
25 | |
26 | #ifndef PX_DOXYGEN |
27 | namespace physx |
28 | { |
29 | #endif |
30 | |
31 | class PxRigidActor; |
32 | class PxRigidBody; |
33 | class PxRigidStatic; |
34 | class PxRigidDynamic; |
35 | class PxParticleBase; |
36 | class PxParticleSystem; |
37 | class PxParticleFluid; |
38 | class PxArticulation; |
39 | class PxArticulationLink; |
40 | |
41 | |
42 | /** Group index which allows to specify 1- or 2-way interaction */ |
43 | typedef PxU8 PxDominanceGroup; // Must be < 32, PxU8. |
44 | |
45 | /** |
46 | \brief Flags which control the behavior of an actor. |
47 | |
48 | @see PxActorFlags PxActor PxActor.setActorFlag() PxActor.getActorFlags() |
49 | */ |
50 | struct PxActorFlag |
51 | { |
52 | enum Enum |
53 | { |
54 | /** |
55 | \brief Enable debug renderer for this actor |
56 | |
57 | @see PxScene.getRenderBuffer() PxRenderBuffer PxVisualizationParameter |
58 | */ |
59 | eVISUALIZATION = (1<<0), |
60 | |
61 | /** |
62 | \brief Disables scene gravity for this actor |
63 | */ |
64 | eDISABLE_GRAVITY = (1<<1), |
65 | |
66 | /** |
67 | \brief Enables the sending of PxSimulationEventCallback::onWake() and PxSimulationEventCallback::onSleep() notify events |
68 | |
69 | @see PxSimulationEventCallback::onWake() PxSimulationEventCallback::onSleep() |
70 | */ |
71 | eSEND_SLEEP_NOTIFIES = (1<<2), |
72 | |
73 | /** |
74 | \brief Disables simulation for the actor. |
75 | |
76 | \note This is only supported by PxRigidStatic and PxRigidDynamic actors and can be used to reduce the memory footprint when rigid actors are |
77 | used for scene queries only. |
78 | |
79 | \note Setting this flag will remove all constraints attached to the actor from the scene. |
80 | |
81 | \note If this flag is set, the following calls are forbidden: |
82 | \li PxRigidBody: setLinearVelocity(), setAngularVelocity(), addForce(), addTorque(), clearForce(), clearTorque() |
83 | \li PxRigidDynamic: setKinematicTarget(), setWakeCounter(), wakeUp(), putToSleep() |
84 | |
85 | \par <b>Sleeping:</b> |
86 | Raising this flag will set all velocities and the wake counter to 0, clear all forces, clear the kinematic target, put the actor |
87 | to sleep and wake up all touching actors from the previous frame. |
88 | */ |
89 | eDISABLE_SIMULATION = (1<<3) |
90 | |
91 | }; |
92 | }; |
93 | |
94 | /** |
95 | \brief collection of set bits defined in PxActorFlag. |
96 | |
97 | @see PxActorFlag |
98 | */ |
99 | typedef PxFlags<PxActorFlag::Enum,PxU16> PxActorFlags; |
100 | PX_FLAGS_OPERATORS(PxActorFlag::Enum,PxU16) |
101 | |
102 | /** |
103 | \brief Identifies each type of actor. |
104 | @see PxActor |
105 | */ |
106 | struct PxActorType |
107 | { |
108 | enum Enum |
109 | { |
110 | /** |
111 | \brief A static rigid body |
112 | @see PxRigidStatic |
113 | */ |
114 | eRIGID_STATIC, |
115 | |
116 | /** |
117 | \brief A dynamic rigid body |
118 | @see PxRigidDynamic |
119 | */ |
120 | eRIGID_DYNAMIC, |
121 | |
122 | #if PX_USE_PARTICLE_SYSTEM_API |
123 | /** |
124 | \brief A particle system |
125 | @see PxParticleSystem |
126 | */ |
127 | ePARTICLE_SYSTEM, |
128 | |
129 | /** |
130 | \brief A particle fluid |
131 | @see PxParticleFluid |
132 | */ |
133 | ePARTICLE_FLUID, |
134 | #endif |
135 | |
136 | /** |
137 | \brief An articulation link |
138 | @see PxArticulationLink |
139 | */ |
140 | eARTICULATION_LINK, |
141 | |
142 | #if PX_USE_CLOTH_API |
143 | /** |
144 | \brief A cloth |
145 | @see PxCloth |
146 | */ |
147 | eCLOTH, |
148 | #endif |
149 | |
150 | //brief internal use only! |
151 | eACTOR_COUNT, |
152 | |
153 | eACTOR_FORCE_DWORD = 0x7fffffff |
154 | }; |
155 | }; |
156 | |
157 | /** |
158 | \brief PxActor is the base class for the main simulation objects in the physics SDK. |
159 | |
160 | The actor is owned by and contained in a PxScene. |
161 | |
162 | */ |
163 | class PxActor : public PxBase |
164 | { |
165 | public: |
166 | /** |
167 | \brief Deletes the actor. |
168 | |
169 | Do not keep a reference to the deleted instance. |
170 | |
171 | If the actor belongs to a #PxAggregate object, it is automatically removed from the aggregate. |
172 | |
173 | @see PxBase.release(), PxAggregate |
174 | */ |
175 | virtual void release() = 0; |
176 | |
177 | /** |
178 | \brief Retrieves the type of actor. |
179 | |
180 | \return The actor type of the actor. |
181 | |
182 | @see PxActorType |
183 | */ |
184 | virtual PxActorType::Enum getType() const = 0; |
185 | |
186 | |
187 | /** |
188 | \deprecated |
189 | \brief Attempts to cast to specific actor type. |
190 | |
191 | \return NULL if the actor is not of the appropriate type. Otherwise a pointer to the specific actor type. |
192 | |
193 | \note Since PxParticleFluid inherits from PxParticleSystem, calling isParticleSystem() on a PxParticleFluid instance will |
194 | succeed and return the upcast to PxParticleSystem. |
195 | |
196 | @see PxActorType PxRigidActor PxRigidBody PxRigidStatic PxRigidDynamic PxParticleBase PxParticleSystem PxParticleFluid |
197 | */ |
198 | PX_DEPRECATED PX_INLINE PxRigidStatic* isRigidStatic(); |
199 | PX_DEPRECATED PX_INLINE const PxRigidStatic* isRigidStatic() const; |
200 | PX_DEPRECATED PX_INLINE PxRigidDynamic* isRigidDynamic(); |
201 | PX_DEPRECATED PX_INLINE const PxRigidDynamic* isRigidDynamic() const; |
202 | PX_DEPRECATED PX_INLINE PxParticleSystem* isParticleSystem(); |
203 | PX_DEPRECATED PX_INLINE const PxParticleSystem* isParticleSystem() const; |
204 | PX_DEPRECATED PX_INLINE PxParticleFluid* isParticleFluid(); |
205 | PX_DEPRECATED PX_INLINE const PxParticleFluid* isParticleFluid() const; |
206 | PX_DEPRECATED PX_INLINE PxArticulationLink* isArticulationLink(); |
207 | PX_DEPRECATED PX_INLINE const PxArticulationLink* isArticulationLink() const; |
208 | PX_DEPRECATED PX_INLINE PxCloth* isCloth(); |
209 | PX_DEPRECATED PX_INLINE const PxCloth* isCloth() const; |
210 | |
211 | PX_DEPRECATED PX_INLINE PxRigidActor* isRigidActor(); |
212 | PX_DEPRECATED PX_INLINE const PxRigidActor* isRigidActor() const; |
213 | PX_DEPRECATED PX_INLINE PxRigidBody* isRigidBody(); |
214 | PX_DEPRECATED PX_INLINE const PxRigidBody* isRigidBody() const; |
215 | PX_DEPRECATED PX_INLINE PxParticleBase* isParticleBase(); |
216 | PX_DEPRECATED PX_INLINE const PxParticleBase* isParticleBase() const; |
217 | |
218 | /** |
219 | \brief Retrieves the scene which this actor belongs to. |
220 | |
221 | \return Owner Scene. NULL if not part of a scene. |
222 | |
223 | @see PxScene |
224 | */ |
225 | virtual PxScene* getScene() const = 0; |
226 | |
227 | // Runtime modifications |
228 | |
229 | /** |
230 | \brief Sets a name string for the object that can be retrieved with getName(). |
231 | |
232 | This is for debugging and is not used by the SDK. The string is not copied by the SDK, |
233 | only the pointer is stored. |
234 | |
235 | \param[in] name String to set the objects name to. |
236 | |
237 | <b>Default:</b> NULL |
238 | |
239 | @see getName() |
240 | */ |
241 | virtual void setName(const char* name) = 0; |
242 | |
243 | /** |
244 | \brief Retrieves the name string set with setName(). |
245 | |
246 | \return Name string associated with object. |
247 | |
248 | @see setName() |
249 | */ |
250 | virtual const char* getName() const = 0; |
251 | |
252 | /** |
253 | \brief Retrieves the axis aligned bounding box enclosing the actor. |
254 | |
255 | \param[in] inflation Scale factor for computed world bounds. Box extents are multiplied by this value. |
256 | |
257 | \return The actor's bounding box. |
258 | |
259 | @see PxBounds3 |
260 | */ |
261 | virtual PxBounds3 getWorldBounds(float inflation=1.01f) const = 0; |
262 | |
263 | /** |
264 | \brief Raises or clears a particular actor flag. |
265 | |
266 | See the list of flags #PxActorFlag |
267 | |
268 | <b>Sleeping:</b> Does <b>NOT</b> wake the actor up automatically. |
269 | |
270 | \param[in] flag The PxActor flag to raise(set) or clear. See #PxActorFlag. |
271 | \param[in] value The boolean value to assign to the flag. |
272 | |
273 | <b>Default:</b> PxActorFlag::eVISUALIZATION |
274 | |
275 | @see PxActorFlag getActorFlags() |
276 | */ |
277 | virtual void setActorFlag(PxActorFlag::Enum flag, bool value) = 0; |
278 | /** |
279 | \brief sets the actor flags |
280 | |
281 | See the list of flags #PxActorFlag |
282 | @see PxActorFlag setActorFlag() |
283 | */ |
284 | virtual void setActorFlags( PxActorFlags inFlags ) = 0; |
285 | |
286 | /** |
287 | \brief Reads the PxActor flags. |
288 | |
289 | See the list of flags #PxActorFlag |
290 | |
291 | \return The values of the PxActor flags. |
292 | |
293 | @see PxActorFlag setActorFlag() |
294 | */ |
295 | virtual PxActorFlags getActorFlags() const = 0; |
296 | |
297 | /** |
298 | \brief Assigns dynamic actors a dominance group identifier. |
299 | |
300 | PxDominanceGroup is a 5 bit group identifier (legal range from 0 to 31). |
301 | |
302 | The PxScene::setDominanceGroupPair() lets you set certain behaviors for pairs of dominance groups. |
303 | By default every dynamic actor is created in group 0. |
304 | |
305 | <b>Default:</b> 0 |
306 | |
307 | <b>Sleeping:</b> Changing the dominance group does <b>NOT</b> wake the actor up automatically. |
308 | |
309 | \param[in] dominanceGroup The dominance group identifier. <b>Range:</b> [0..31] |
310 | |
311 | @see getDominanceGroup() PxDominanceGroup PxScene::setDominanceGroupPair() |
312 | */ |
313 | virtual void setDominanceGroup(PxDominanceGroup dominanceGroup) = 0; |
314 | |
315 | /** |
316 | \brief Retrieves the value set with setDominanceGroup(). |
317 | |
318 | \return The dominance group of this actor. |
319 | |
320 | @see setDominanceGroup() PxDominanceGroup PxScene::setDominanceGroupPair() |
321 | */ |
322 | virtual PxDominanceGroup getDominanceGroup() const = 0; |
323 | |
324 | |
325 | /** |
326 | \brief Sets the owner client of an actor. |
327 | |
328 | This cannot be done once the actor has been placed into a scene. |
329 | |
330 | <b>Default:</b> PX_DEFAULT_CLIENT |
331 | |
332 | @see PxClientID PxScene::createClient() |
333 | */ |
334 | virtual void setOwnerClient( PxClientID inClient ) = 0; |
335 | |
336 | /** |
337 | \brief Returns the owner client that was specified with at creation time. |
338 | |
339 | This value cannot be changed once the object is placed into the scene. |
340 | |
341 | @see PxClientID PxScene::createClient() |
342 | */ |
343 | virtual PxClientID getOwnerClient() const = 0; |
344 | |
345 | /** |
346 | \brief Sets the behavior bits of the actor. |
347 | |
348 | The behavior bits determine which types of events the actor will broadcast to foreign clients. |
349 | The actor will always send notice for all possible events to its own owner client. By default |
350 | it will not send any events to any other clients. If the user however raises a bit flag for |
351 | any event type using this function, that event will then be sent also to any other clients which |
352 | are programmed to listed to foreign actor events of that type. |
353 | |
354 | <b>Default:</b> 0 |
355 | |
356 | @see PxClientID PxActorClientBehaviorFlag PxScene::setClientBehaviorFlags() |
357 | */ |
358 | virtual void setClientBehaviorFlags(PxActorClientBehaviorFlags) = 0; |
359 | |
360 | /** |
361 | \brief Retrieves the behavior bits of the actor. |
362 | |
363 | The behavior bits determine which types of events the actor will broadcast to foreign clients. |
364 | |
365 | @see PxActorClientBehaviorFlag setClientBehaviorFlags() |
366 | */ |
367 | virtual PxActorClientBehaviorFlags getClientBehaviorFlags() const = 0; |
368 | |
369 | /** |
370 | \brief Retrieves the aggregate the actor might be a part of. |
371 | |
372 | \return The aggregate the actor is a part of, or NULL if the actor does not belong to an aggregate. |
373 | |
374 | @see PxAggregate |
375 | */ |
376 | virtual PxAggregate* getAggregate() const = 0; |
377 | |
378 | //public variables: |
379 | void* userData; //!< user can assign this to whatever, usually to create a 1:1 relationship with a user object. |
380 | |
381 | |
382 | protected: |
383 | PX_INLINE PxActor(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags), userData(NULL) {} |
384 | PX_INLINE PxActor(PxBaseFlags baseFlags) : PxBase(baseFlags) {} |
385 | virtual ~PxActor() {} |
386 | virtual bool isKindOf(const char* name) const { return !strcmp("PxActor" , name) || PxBase::isKindOf(name); } |
387 | |
388 | |
389 | }; |
390 | |
391 | #ifndef PX_DOXYGEN |
392 | } // namespace physx |
393 | #endif |
394 | |
395 | /** @} */ |
396 | #endif |
397 | |