O'Reilly logo

Learning Physics Modeling with PhysX by Krishna Kumar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updating particles

Each particle can be explicitly accessed for updating its position and velocity immediately.

The code snippet for updating the positions of particles is given as follows:

PxVec3 particlePositions[] =  {...};
PxU32 particleIndices[] = {...}; 

PxU32 numParticles = ...;
PxStrideIterator<const PxVec3> newPositionBuff (particlePositions);
PxStrideIterator<const PxU32> indexBuff (particleIndices);

//ps is the instance of PxParticleSystem or PxParticleFluid
ps->setPositions(numParticles, indexBuff, newPositionBuff);

We can also update the forces on the particles by using addForces(), as follows:

PxU32 numParticles = ...; PxStrideIterator<const PxVec3> forceBuffer = ...; PxStrideIterator<const PxU32> indexBuffer = ...; //ps is the instance ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required