aboutsummaryrefslogtreecommitdiff
path: root/PhysX_3.4/Include/particles/PxParticleBase.h
blob: 29f87567817b7be26b977f8a9ab2d22518eab902 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  


#ifndef PX_PHYSICS_PX_PARTICLEBASE
#define PX_PHYSICS_PX_PARTICLEBASE

/** \defgroup particles particles (deprecated)*/

/** \addtogroup particles
  @{
*/

#include "PxPhysXConfig.h"
#include "foundation/PxBounds3.h"
#include "PxFiltering.h"
#include "particles/PxParticleBaseFlag.h"
#include "PxActor.h"
#include "particles/PxParticleCreationData.h"
#include "particles/PxParticleReadData.h"
#include "PxForceMode.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

/**
\brief The particle base class represents the shared module for particle based simulation. This class can't be instantiated. (deprecated)

The particle base class manages a set of particles.  Particles can be created, released and updated directly through the API.
When a particle is created the user gets an index for it which can be used to address the particle until it is released again.

Particles collide with static and dynamic shapes.  They are also affected by the scene gravity and a user force, 
as well as global velocity damping.  When a particle collides, a particle flag is raised corresponding to the type of 
actor, static or dynamic, it collided with.  Additionally a shape can be flagged as a drain (See PxShapeFlag), in order to get a corresponding 
particle flag raised when a collision occurs.  This information can be used to delete particles.

\deprecated The PhysX particle feature has been deprecated in PhysX version 3.4

@see PxParticleCreationData, PxParticleReadData, PxShapeFlag, PxParticleSystem, PxParticleFluid
*/
class PX_DEPRECATED PxParticleBase : public PxActor
{

	public:

/************************************************************************************************/

/** @name Particle Access and Manipulation
*/
//@{

	/**
	\brief Locks the particle data and provides the data descriptor for accessing the particles.
	After reading from the buffers the application needs to call PxParticleReadData::unlock() before any 
	SDK operation can access the buffers. Particularly the buffers need to be unlocked before calling 
	PxParticleBase::lockParticleReadData(), PxParticleBase::createParticles(), PxParticleBase::releaseParticles(),
	PxScene::fetchResults().

	\param flags If PxDataAccessFlag::eDEVICE is specified for GPU particles then pointers to GPU memory will be returned otherwise it will be ignored.
	\note PxDataAccessFlag::eWRITEABLE is not supported and will be ignored
	\note If using PxDataAccessFlag::eDEVICE, newly created particles will not become visible in the GPU buffers until a subsequent simulation step has completed
	@see PxParticleReadData
	*/
	virtual		PxParticleReadData*			lockParticleReadData(PxDataAccessFlags flags) = 0;

	/** 
	\brief Locks the particle read data and provides the data descriptor for accessing the particles
	\note This method does the same as lockParticleReadData(PxDataAccessFlags::eREADABLE)
	@see PxParticleReadData
	*/
	virtual		PxParticleReadData*			lockParticleReadData() = 0;

	/**
	\brief Creates new particles.
	
	The PxParticleCreationData descriptor is used to create new particles based on the provided PxParticleCreationData. 
	Providing particle indices and positions is mandatory.  Indices need to be consistent with the available particle slots within 
	the range [0, maxParticles-1].  The new particles can be immediately read from the application readable 
	particle data, PxParticleReadData. 
	
	\param creationData specifies particle attributes for the particles to be created. (all buffers set have to be consistent with numParticles). 
	\return whether the operation was successful.

	@see PxParticleCreationData, PxParticleReadData, PxParticlesExt.IndexPool
	*/
	virtual		bool						createParticles(const PxParticleCreationData& creationData)										= 0;

	/**
	\brief Releases particles.
	
	Particles corresponding to passed indices are released. Releasing a particle will immediately mark the particle in the 
	application readable particle data, PxParticleReadData, as being invalid, removing PxParticleFlag::eVALID.
	Passing duplicate indices is not allowed.

	\param numParticles Number of particles to be released.
	\param indexBuffer Structure describing indices of particles that should be deleted. (Has to be consistent with numParticles).

	@see PxParticleReadData
	*/
	virtual		void						releaseParticles(PxU32 numParticles, const PxStrideIterator<const PxU32>& indexBuffer)					= 0;

	/**
	\brief Releases all particles.

	Application readable particle data is updated accordingly.
	*/
	virtual		void						releaseParticles()																						= 0;

	/**
	\brief Sets particle positions.

	Directly sets the positions of particles. The supplied positions are used to change particles in the order of
	the indices listed in the index buffer. Duplicate indices are allowed. A position buffer of stride zero is allowed.
	Application readable particle data is updated accordingly.
	
	\param numParticles Number of particle updates.
	\param indexBuffer Structure describing indices of particles that should be updated. (Has to be consistent with numParticles).
	\param positionBuffer Structure describing positions for position updates. (Has to be consistent with numParticles).
	*/
	virtual		void						setPositions(PxU32 numParticles, const PxStrideIterator<const PxU32>& indexBuffer,
														 const PxStrideIterator<const PxVec3>& positionBuffer)										= 0;

	/**
	\brief Sets particle velocities.

	Directly sets the velocities of particles. The supplied velocities are used to change particles in the order of
	the indices listed in the index buffer. Duplicate indices are allowed. A velocity buffer of stride zero is allowed.
	Application readable particle data is updated accordingly.
	
	\param numParticles Number of particle updates.
	\param indexBuffer Structure describing indices of particles that should be updated. (Has to be consistent with numParticles).
	\param velocityBuffer Structure describing velocities for velocity updates. (Has to be consistent with numParticles).
	*/
	virtual		void						setVelocities(PxU32 numParticles, const PxStrideIterator<const PxU32>& indexBuffer,
														  const PxStrideIterator<const PxVec3>& velocityBuffer)										= 0;

	/**
	\brief Sets particle rest offsets.

	Directly sets the rest offsets of particles. The supplied rest offsets are used to change particles in the order of
	the indices listed in the index buffer. The provided offsets need to be in the range [0.0f, restOffset].
	Duplicate indices are allowed. A rest offset buffer of stride zero is allowed.
	Application readable particle data is updated accordingly.
	
	\param numParticles Number of particle updates.
	\param indexBuffer Structure describing indices of particles that should be updated. (Has to be consistent with numParticles).
	\param restOffsetBuffer Structure describing rest offsets for rest offset updates. (Has to be consistent with numParticles).
	
	@see PxParticleBaseFlag.ePER_PARTICLE_REST_OFFSET
	*/
	virtual		void						setRestOffsets(PxU32 numParticles, const PxStrideIterator<const PxU32>& indexBuffer,
														   const PxStrideIterator<const PxF32>& restOffsetBuffer)									= 0;


	/**
	\brief Set forces to be applied to the particles when the simulation starts.

	This call is ignored on particle system that aren't assigned to a scene.
	
	\param numParticles Number of particle updates.
	\param indexBuffer Structure describing indices of particles that should be updated. (Has to be consistent with numParticles).
	\param forceBuffer Structure describing values for particle updates depending on forceMode. (Has to be consistent with numParticles).
	\param forceMode Describes type of update.
	*/
	virtual		void						addForces(PxU32 numParticles, const PxStrideIterator<const PxU32>& indexBuffer,
													  const PxStrideIterator<const PxVec3>& forceBuffer, PxForceMode::Enum forceMode)				= 0;

//@}
/************************************************************************************************/

/** @name ParticleBase Parameters
*/
//@{

	/**
	\brief Returns the particle system damping.

	\return The particle system damping.
	*/
	virtual		PxReal						getDamping()												const	= 0;

	/**
	\brief Sets the particle system damping (must be nonnegative).

	\param damp The new particle system damping.
	*/
	virtual		void 						setDamping(PxReal damp)												= 0;

	/**
	\brief Returns the external acceleration applied to each particle at each time step.

	\return The external acceleration applied to particles.
	*/
	virtual		PxVec3						getExternalAcceleration()									const	= 0;

	/**
	\brief Sets the external acceleration applied to each particle at each time step.

	\param acceleration External acceleration to apply to particles.

	@see getExternalAcceleration()
	*/
	virtual		void 						setExternalAcceleration(const PxVec3&acceleration)					= 0;

	/**
	\brief Returns the plane the particles are projected to.

	\param[out] normal Particle projection plane normal
	\param[out] distance Particle projection plane constant term
	*/
	virtual		void						getProjectionPlane(PxVec3& normal, PxReal& distance)		const	= 0;

	/**
	\brief Sets the plane the particles are projected to.

	Points p on the plane have to fulfill the equation:
	
	(normal.x * p.x)  +  (normal.y * p.y)  +  (normal.z * p.z)  +  d = 0

	\param[in] normal Particle projection plane normal
	\param[in] distance Particle projection plane constant term
	*/
	virtual		void 						setProjectionPlane(const PxVec3& normal, PxReal distance)			= 0;
//@}
/************************************************************************************************/

/** @name Collisions
*/
//@{

	/**
	\brief Returns the mass of a particle. 

	\return Particle mass.
	*/
	virtual		PxReal						getParticleMass()											const	= 0;

	/**
	\brief Sets the mass of a particle. 

	\param mass The particle mass.
	*/
	virtual		void						setParticleMass(PxReal mass)										= 0;

	/**
	\brief Returns the restitution used for collision with shapes.

	\return The restitution.
	*/
	virtual		PxReal						getRestitution()											const	= 0;

	/**
	\brief Sets the restitution used for collision with shapes.
	
	Must be between 0 and 1.

	\param rest The new restitution.
	*/
	virtual		void 						setRestitution(PxReal rest)											= 0;

	/**
	\brief Returns the dynamic friction used for collision with shapes.

	\return The dynamic friction.
	*/
	virtual		PxReal						getDynamicFriction()										const	= 0;

	/**
	\brief Sets the dynamic friction used for collision with shapes.
	
	Must be between 0 and 1.

	\param friction The new dynamic friction
	*/
	virtual		void 						setDynamicFriction(PxReal friction)									= 0;

	/**
	\brief Returns the static friction used for collision with shapes.

	\return The static friction.
	*/
	virtual		PxReal						getStaticFriction()											const	= 0;

	/**
	\brief Sets the static friction used for collision with shapes.
	
	Must be non-negative.
	
	\param friction The new static friction
	*/
	virtual		void 						setStaticFriction(PxReal friction)									= 0;

//@}
/************************************************************************************************/

/** @name Collision Filtering
*/
//@{

	/**
	\brief Sets the user definable collision filter data.

	@see getSimulationFilterData()
	*/
	virtual		void						setSimulationFilterData(const PxFilterData& data)					= 0;

	/**
	\brief Retrieves the object's collision filter data.

	@see setSimulationFilterData()
	*/
	virtual		PxFilterData				getSimulationFilterData()									const	= 0;

//@}
/************************************************************************************************/

	/**
	\brief Sets particle system flags.

	\param flag Member of #PxParticleBaseFlag.
	\param val New flag value.
	*/
	virtual		void						setParticleBaseFlag(PxParticleBaseFlag::Enum flag, bool val)	= 0;

	/**
	\brief Returns particle system flags.

	\return The current flag values.
	*/
	virtual		PxParticleBaseFlags			getParticleBaseFlags()									const	= 0;

/************************************************************************************************/

/** @name ParticleSystem Property Read Back
*/
//@{

	/**
	\brief Returns the maximum number of particles for this particle system.

	\return Max number of particles for this particle system.
	*/
	virtual		PxU32 						getMaxParticles()										const	= 0;

	/**
	\brief Returns the maximal motion distance (the particle can move the maximal distance of 
	getMaxMotionDistance() during one timestep).

	\return maximum motion distance.
	*/
	virtual		PxReal						getMaxMotionDistance()									const	= 0;

	/**
	\brief Sets the maximal motion distance (the particle can move the maximal distance 
	 during one timestep). Immutable when the particle system is part of a scene.

	\param distance New Max motionDistance value.
	*/
	virtual		void						setMaxMotionDistance(PxReal distance)							= 0;

	/**
	\brief Returns the distance between particles and collision geometry, which is maintained during simulation.

	\return rest offset.
	*/
	virtual		PxReal						getRestOffset()											const	= 0;

	/**
	\brief Sets the distance between particles and collision geometry, which is maintained during simulation.
	If per particle restOffsets are used, they need to be in the range [0.0f, restOffset]. Immutable when the
	particle system is part of a scene.
	\param restOffset New restOffset value.
	*/
	virtual		void						setRestOffset(PxReal restOffset)								= 0;

	/**
	\brief Returns the distance at which contacts are generated between particles and collision geometry.

	\return contact offset.
	*/
	virtual		PxReal						getContactOffset()										const	= 0;

	/**
	\brief Sets the distance at which contacts are generated between particles and collision geometry.
	Immutable when the particle system is part of a scene.

	\param contactOffset New contactOffset value.
	*/
	virtual		void						setContactOffset(PxReal contactOffset)							= 0;

	/**
	\brief Returns the particle grid size used for internal spatial data structures.

	The actual grid size used might differ from the grid size set in the setGridSize(). 

	\return The grid size.
	*/
	virtual		PxReal						getGridSize()											const	= 0;

	/**
	\brief Sets the particle grid size used for internal spatial data structures.
	Immutable when the particle system is part of a scene.
	The actual grid size used might differ from the grid size set in the setGridSize(). 

	\param gridSize New gridSize value.
	*/
	virtual		void						setGridSize(PxReal gridSize)									= 0;

	/**
	\brief Returns particle read data flags.
	\return The particle read data flags.
	@see PxParticleReadDataFlags
	*/
	virtual		PxParticleReadDataFlags		getParticleReadDataFlags()								const	= 0;

	/**
	\brief Sets particle read data flags.
	\param flag Member of PxParticleReadDataFlag.
	\param val New flag value.
	@see PxParticleReadDataFlags
	*/
	virtual		void						setParticleReadDataFlag(PxParticleReadDataFlag::Enum flag, bool val)= 0;

protected:
	PX_INLINE								PxParticleBase(PxType concreteType, PxBaseFlags baseFlags) : PxActor(concreteType, baseFlags) {}
	PX_INLINE								PxParticleBase(PxBaseFlags baseFlags) : PxActor(baseFlags) {}
	virtual									~PxParticleBase() {}
	virtual		bool						isKindOf(const char* name) const { return !::strcmp("PxParticleBase", name) || PxActor::isKindOf(name); }

//@}
/************************************************************************************************/
};

#if !PX_DOXYGEN
} // namespace physx
#endif

/** @} */
#endif