Esempio n. 1
0
void ParticleSystemProxy::generateParticlesFromSphereEmitter(scene::IParticleSphereEmitter *emitter)
{
	ParticleData *particles = new ParticleData[count], *initialvalue = new ParticleData[count];

	for (unsigned i = 0; i < count; i++) {
		// Random distance from center
		const f32 distance = os::Randomizer::frand() * emitter->getRadius();

		// Random direction from center
		vector3df pos = emitter->getCenter() + distance;
		pos.rotateXYBy(os::Randomizer::frand() * 360.f, emitter->getCenter());
		pos.rotateYZBy(os::Randomizer::frand() * 360.f, emitter->getCenter());
		pos.rotateXZBy(os::Randomizer::frand() * 360.f, emitter->getCenter());

		particles[i].PositionX = pos.X;
		particles[i].PositionY = pos.Y;
		particles[i].PositionZ = pos.Z;
		// Initial lifetime is > 1
		particles[i].Lifetime = 2.;

		memcpy(&(initialvalue[i].PositionX), &(particles[i].PositionX), 3 * sizeof(float));
		generateLifetimeSizeDirection(emitter, initialvalue[i].Lifetime, initialvalue[i].Size,
			initialvalue[i].DirectionX, initialvalue[i].DirectionY, initialvalue[i].DirectionZ);
		memcpy(&(particles[i].DirectionX), &(initialvalue[i].DirectionX), 4 * sizeof(float));
	}
	glBindBuffer(GL_ARRAY_BUFFER, initial_values_buffer);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), initialvalue, GL_STREAM_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[0]);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), particles, GL_STREAM_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[1]);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), 0, GL_STREAM_DRAW);
	delete[] particles;
	delete[] initialvalue;
}
Esempio n. 2
0
void ParticleSystemProxy::generateParticlesFromBoxEmitter(scene::IParticleBoxEmitter *emitter)
{
	ParticleData *particles = new ParticleData[count], *initialvalue = new ParticleData[count];

	const core::vector3df& extent = emitter->getBox().getExtent();

	for (unsigned i = 0; i < count; i++) {
		particles[i].PositionX = emitter->getBox().MinEdge.X + os::Randomizer::frand() * extent.X;
		particles[i].PositionY = emitter->getBox().MinEdge.Y + os::Randomizer::frand() * extent.Y;
		particles[i].PositionZ = emitter->getBox().MinEdge.Z + os::Randomizer::frand() * extent.Z;
		// Initial lifetime is random
		particles[i].Lifetime = os::Randomizer::frand();

		memcpy(&(initialvalue[i].PositionX), &(particles[i].PositionX), 3 * sizeof(float));
		generateLifetimeSizeDirection(emitter, initialvalue[i].Lifetime, initialvalue[i].Size,
			initialvalue[i].DirectionX, initialvalue[i].DirectionY, initialvalue[i].DirectionZ);
		memcpy(&(particles[i].DirectionX), &(initialvalue[i].DirectionZ), 4 * sizeof(float));
	}
	glBindBuffer(GL_ARRAY_BUFFER, initial_values_buffer);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), initialvalue, GL_STREAM_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[0]);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), particles, GL_STREAM_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[1]);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), 0, GL_STREAM_DRAW);
	delete[] particles;
	delete[] initialvalue;
}
Esempio n. 3
0
void ParticleSystemProxy::generateParticlesFromPointEmitter(scene::IParticlePointEmitter *emitter)
{
	ParticleData *particles = new ParticleData[count], *initialvalue = new ParticleData[count];

	for (unsigned i = 0; i < count; i++) {
		particles[i].PositionX = 0;
		particles[i].PositionY = 0;
		particles[i].PositionZ = 0;
		// Initial lifetime is >1
		particles[i].Lifetime = 2.;

		memcpy(&(initialvalue[i].PositionX), &(particles[i].PositionX), 3 * sizeof(float));

		generateLifetimeSizeDirection(emitter, initialvalue[i].Lifetime, initialvalue[i].Size,
			initialvalue[i].DirectionX, initialvalue[i].DirectionY, initialvalue[i].DirectionZ);

		memcpy(&(particles[i].DirectionX), &(initialvalue[i].DirectionX), 4 * sizeof(float));
	}

	glBindBuffer(GL_ARRAY_BUFFER, initial_values_buffer);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), initialvalue, GL_STREAM_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[0]);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), particles, GL_STREAM_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, tfb_buffers[1]);
	glBufferData(GL_ARRAY_BUFFER, count * sizeof(ParticleData), 0, GL_STREAM_DRAW);
	delete[] particles;
	delete[] initialvalue;
}
Esempio n. 4
0
// ----------------------------------------------------------------------------
void STKParticle::generateParticlesFromSphereEmitter
    (scene::IParticleSphereEmitter *emitter)
{
    m_particles_generating.clear();
    m_initial_particles.clear();
    m_particles_generating.resize(m_max_count);
    m_initial_particles.resize(m_max_count);
    for (unsigned i = 0; i < m_max_count; i++)
    {
        // Random distance from center
        const f32 distance = os::Randomizer::frand() * emitter->getRadius();

        // Random direction from center
        vector3df pos = emitter->getCenter() + distance;
        pos.rotateXYBy(os::Randomizer::frand() * 360.f, emitter->getCenter());
        pos.rotateYZBy(os::Randomizer::frand() * 360.f, emitter->getCenter());
        pos.rotateXZBy(os::Randomizer::frand() * 360.f, emitter->getCenter());

        m_particles_generating[i].m_position = pos;

        // Initial lifetime is > 1
        m_particles_generating[i].m_lifetime = 2.0f;
        m_initial_particles[i].m_position =
            m_particles_generating[i].m_position;

        generateLifetimeSizeDirection(emitter,
            m_initial_particles[i].m_lifetime,
            m_particles_generating[i].m_size,
            m_particles_generating[i].m_direction);

        m_initial_particles[i].m_direction =
            m_particles_generating[i].m_direction;
        m_initial_particles[i].m_size = m_particles_generating[i].m_size;
    }
}   // generateParticlesFromSphereEmitter
Esempio n. 5
0
// ----------------------------------------------------------------------------
void STKParticle::generateParticlesFromBoxEmitter
    (scene::IParticleBoxEmitter *emitter)
{
    m_particles_generating.clear();
    m_initial_particles.clear();
    m_particles_generating.resize(m_max_count);
    m_initial_particles.resize(m_max_count);
    const core::vector3df& extent = emitter->getBox().getExtent();
    for (unsigned i = 0; i < m_max_count; i++)
    {
        m_particles_generating[i].m_position.X =
            emitter->getBox().MinEdge.X + os::Randomizer::frand() * extent.X;
        m_particles_generating[i].m_position.Y =
            emitter->getBox().MinEdge.Y + os::Randomizer::frand() * extent.Y;
        m_particles_generating[i].m_position.Z =
            emitter->getBox().MinEdge.Z + os::Randomizer::frand() * extent.Z;

        // Initial lifetime is random
        m_particles_generating[i].m_lifetime = os::Randomizer::frand();
        if (!m_randomize_initial_y)
        {
            m_particles_generating[i].m_lifetime += 1.0f;
        }
        m_initial_particles[i].m_position =
            m_particles_generating[i].m_position;

        generateLifetimeSizeDirection(emitter,
            m_initial_particles[i].m_lifetime,
            m_particles_generating[i].m_size,
            m_particles_generating[i].m_direction);

        m_initial_particles[i].m_direction =
            m_particles_generating[i].m_direction;
        m_initial_particles[i].m_size = m_particles_generating[i].m_size;

        if (m_randomize_initial_y)
        {
            m_initial_particles[i].m_position.Y =
                os::Randomizer::frand() * 50.0f; // -100.0f;
        }
    }
}   // generateParticlesFromBoxEmitter
Esempio n. 6
0
// ----------------------------------------------------------------------------
void STKParticle::generateParticlesFromPointEmitter
    (scene::IParticlePointEmitter *emitter)
{
    m_particles_generating.clear();
    m_initial_particles.clear();
    m_particles_generating.resize(m_max_count);
    m_initial_particles.resize(m_max_count);
    for (unsigned i = 0; i < m_max_count; i++)
    {
        // Initial lifetime is > 1
        m_particles_generating[i].m_lifetime = 2.0f;

        generateLifetimeSizeDirection(emitter,
            m_initial_particles[i].m_lifetime,
            m_particles_generating[i].m_size,
            m_particles_generating[i].m_direction);

        m_initial_particles[i].m_direction =
            m_particles_generating[i].m_direction;
        m_initial_particles[i].m_size = m_particles_generating[i].m_size;
    }
}   // generateParticlesFromPointEmitter