//add particle to PhysX System
bool ParticleEmitter::AddPhysXParticle(int particleIndex)
{

	//set up the data
	//set up the buffers
	PxU32 myIndexBuffer[] = {particleIndex};
	PxVec3 startPos = m_position;
	PxVec3 startVel(0,0,0);
	//randomize starting velocity.
	float fT = (rand() % (RAND_MAX + 1)) / (float)RAND_MAX;
	startVel.x += m_minVelocity.x + (fT * (m_maxVelocity.x - m_minVelocity.x));
	fT = (rand() % (RAND_MAX + 1)) / (float)RAND_MAX;
	startVel.y += m_minVelocity.y + (fT * (m_maxVelocity.y - m_minVelocity.y));
	fT = (rand() % (RAND_MAX + 1)) / (float)RAND_MAX;
	startVel.z += m_minVelocity.z + (fT * (m_maxVelocity.z - m_minVelocity.z));

	//we can change starting position tos get different emitter shapes
	PxVec3 myPositionBuffer[] = {startPos};
	PxVec3 myVelocityBuffer[] =  {startVel};

	//reserve space for data
	PxParticleCreationData particleCreationData;
	particleCreationData.numParticles = 1;  //spawn one particle at a time,  this is inefficient and we could improve this by passing in the list of particles.
	particleCreationData.indexBuffer = PxStrideIterator<const PxU32>(myIndexBuffer);
	particleCreationData.positionBuffer = PxStrideIterator<const PxVec3>(myPositionBuffer);
	particleCreationData.velocityBuffer = PxStrideIterator<const PxVec3>(myVelocityBuffer);
	// create particles in *PxParticleSystem* ps
	return m_ps->createParticles(particleCreationData);
}
Exemplo n.º 2
0
// Add particle to PhysX System
bool ParticleEmitter::AddPhysXParticle(int _particleIndex) {
	PxParticleCreationData particleCreationData;
	
	// Spawn one particle at a time.
	// Note(Manny): This is inefficient and we could improve this by passing in the list of particles.
	particleCreationData.numParticles = 1;
	// Set up the buffers
	PxU32 myIndexBuffer[] = { _particleIndex };
	PxVec3 startPos = PxVec3(this->transform->position.x, 
							 this->transform->position.y, 
							 this->transform->position.z);
	
	PxVec3 startVel((float)(rand() % (int)m_maxVelocity.x + (int)m_minVelocity.x), 
					(float)(rand() % (int)m_maxVelocity.y + (int)m_minVelocity.y), 
					(float)(rand() % (int)m_maxVelocity.z + (int)m_minVelocity.z));

	// Randomize starting velocity.
	float fT = (rand() % (RAND_MAX + 1)) / (float)RAND_MAX;
	startVel.x += m_minVelocity.x + (fT * (m_maxVelocity.x - m_minVelocity.x));
	fT = (rand() % (RAND_MAX + 1)) / (float)RAND_MAX;
	startVel.y += m_minVelocity.y + (fT * (m_maxVelocity.y - m_minVelocity.y));
	fT = (rand() % (RAND_MAX + 1)) / (float)RAND_MAX;
	startVel.z += m_minVelocity.z + (fT * (m_maxVelocity.z - m_minVelocity.z));

	// We can change starting position tos get different emitter shapes
	PxVec3 myPositionBuffer[] = { startPos };
	PxVec3 myVelocityBuffer[] = { startVel };

	particleCreationData.indexBuffer = PxStrideIterator<const PxU32>(myIndexBuffer);
	particleCreationData.positionBuffer = PxStrideIterator<const PxVec3>(myPositionBuffer);
	particleCreationData.velocityBuffer = PxStrideIterator<const PxVec3>(myVelocityBuffer);
	// Create particles in *PxParticleSystem* ps
	return particleFluid->createParticles(particleCreationData);
}
Exemplo n.º 3
0
void GridEmitter::update( double relative_time, ParticleArray *particles )
{
    // Saving up particles until there are enough saved up to emit in the grid:
    const double possible_particles = (relative_time - last_emit_time) * p_rate + left_over;

    if ( possible_particles >= p_N
         && (particles->getMaxLength() - particles->getLength()) >= p_N )
    {
        // Set the last emit time, and compensate for the "residue particle(s)".
        last_emit_time = relative_time - ( possible_particles - p_N ) / p_rate;
        left_over = 0;

        // Emit:
        for ( int p = 0; p < p_N; p++ )
        {
            const Vector2d pos = startPos( p );
            const Vector2d vel = startVel( p );

            if ( channel->outsideBox( pos ) == P_INSIDE )
                particles->add( Particle( pos, vel ) );
            else
                left_over++;
        }
    }
}
Exemplo n.º 4
0
void GridEmitter::init( ParticleArray *particles )
{
    for ( int p = 0; p < p_N; p++ )
    {
        const Vector2d pos = startPos( p );
        const Vector2d vel = startVel( p );

        if ( channel->outsideBox( pos ) == P_INSIDE )
            particles->add( Particle( pos, vel ) );
        else
            left_over++;
    }
}
Exemplo n.º 5
0
////////////////////////////////////////
// Init, Update (public), Reset is default
void GridOnceEmitter::init( ParticleArray *particles )
{
    for ( int p = 0; p < p_N; p++ )
        particles->add( startPos( p ), startVel( p ), 0 );
}