//simple routine to render our particles void ParticleFluidEmitter::renderParticles() { // lock SDK buffers of *PxParticleSystem* ps for reading PxParticleFluidReadData * fd = m_pf->lockParticleFluidReadData(); // access particle data from PxParticleReadData float minX =1000,maxX = -1000,minZ = 1000,maxZ = -1000,minY = 1000,maxY = -1000; if (fd) { PxStrideIterator<const PxParticleFlags> flagsIt(fd->flagsBuffer); PxStrideIterator<const PxVec3> positionIt(fd->positionBuffer); PxStrideIterator<const PxF32> densityIt(fd->densityBuffer); for (unsigned i = 0; i < fd->validParticleRange; ++i, ++flagsIt, ++positionIt,++densityIt) { if (*flagsIt & PxParticleFlag::eVALID) { //density tells us how many neighbours a particle has. //If it has a density of 0 it has no neighbours, 1 is maximum neighbouts //we can use this to decide if the particle is seperate or part of a larger body of fluid glm::vec3 pos(positionIt->x,positionIt->y,positionIt->z); //glm::vec4 colournoise = glm::vec4(((float)(rand() % 100)) / 100, ((float)(rand() % 100)) / 100, ((float)(rand() % 100)) / 100, 1); glm::vec4 colour = glm::vec4(0.196f, 0.518f, 0.749f, 1.0f); //colour.a = 1; Gizmos::addAABBFilled(pos, glm::vec3(.12, .12, .12), colour); //Gizmos::addDisk(pos, 0.1f, 6, glm::vec4(1, 0, 1, 1)); } } // return ownership of the buffers back to the SDK fd->unlock(); } }
//simple routine to render our particles void ParticleFluidEmitter::renderParticles() { // lock SDK buffers of *PxParticleSystem* ps for reading PxParticleFluidReadData * fd = m_pf->lockParticleFluidReadData(); // access particle data from PxParticleReadData float minX =1000,maxX = -1000,minZ = 1000,maxZ = -1000,minY = 1000,maxY = -1000; if (fd) { PxStrideIterator<const PxParticleFlags> flagsIt(fd->flagsBuffer); PxStrideIterator<const PxVec3> positionIt(fd->positionBuffer); PxStrideIterator<const PxF32> densityIt(fd->densityBuffer); for (unsigned i = 0; i < fd->validParticleRange; ++i, ++flagsIt, ++positionIt,++densityIt) { if (*flagsIt & PxParticleFlag::eVALID) { //density tells us how many neighbours a particle has. //If it has a density of 0 it has no neighbours, 1 is maximum neighbouts //we can use this to decide if the particle is seperate or part of a larger body of fluid glm::vec3 pos(positionIt->x,positionIt->y,positionIt->z); Gizmos::addAABBFilled(pos, m_size, m_colour, nullptr, false); } } // return ownership of the buffers back to the SDK fd->unlock(); } }
void ParticleEmitter::Draw(RenderingEngine& _renderer) { // Lock SDK buffers of *PxParticleSystem* ps for reading PxParticleFluidReadData * fd = particleFluid->lockParticleFluidReadData(); // Access particle data from PxParticleReadData float minX = 1000, maxX = -1000, minZ = 1000, maxZ = -1000, minY = 1000, maxY = -1000; if (fd) { PxStrideIterator<const PxParticleFlags> flagsIt(fd->flagsBuffer); PxStrideIterator<const PxVec3> positionIt(fd->positionBuffer); PxStrideIterator<const PxF32> densityIt(fd->densityBuffer); for (unsigned i = 0; i < fd->validParticleRange; ++i, ++flagsIt, ++positionIt, ++densityIt) { if (*flagsIt & PxParticleFlag::eVALID) { // Density tells us how many neighbours a particle has. // If it has a density of 0 it has no neighbours, 1 is maximum neighbours // We can use this to decide if the particle is seperate or part of a larger body of fluid vec3 position(positionIt->x, positionIt->y, positionIt->z); Gizmos::AddSphere(position, restParticleDistance * 0.5f, 4, 4, vec4(1, 0, 1, 1)); } } // return ownership of the buffers back to the SDK fd->unlock(); } Gizmos::AddTransform(this->transform->worldMatrix); }