예제 #1
0
	void ParticleSystem::add()
	{
		/*for(int i = 0; i < m_particleCount; ++i)
		{
			if(!m_particleList[i].enabled)
			{
				resetParticle(i);
				return;
			}
		}*/

		if(m_inactiveParticleListTopIndex > 0)
		{
			resetParticle(m_inactiveParticleList[m_inactiveParticleListTopIndex]);

			m_inactiveParticleListTopIndex--;

			return;
		}

		if(m_particleCount < m_maxParticleCount)
		{
			resetParticle(m_particleCount);
			m_particleCount++;
		}
		else
		{
			m_particleList[rand() % m_particleCount].quickFade = 1;
		}
	}
예제 #2
0
//-------------------------------------------------------------- update
void ofxVBO::update() {

	ofSetWindowTitle(ofToString(ofGetFrameRate()));

	// Camera
	tran += (tranv-tran) * 0.2;
	rot  += (rotv-rot) * 0.002;



	for(int i=0; i<NUM_PARTICLES; i++) {

		// update the postion via velocity
		pnts[i].x += vel[i].x;
		pnts[i].y += vel[i].y;
		pnts[i].z += vel[i].z;

		color[i].a -= 0.0002;


		// if we are at zero alpha
		// then reset the particle
		//if(color[i].a <= 0.0) {
		//	resetParticle(i);
		//}


		// Particle Wrapping
		/*if(pnts[i].x > boxSize || pnts[i].x < -boxSize ||
		 pnts[i].y > boxSize || pnts[i].y < -boxSize ||
		 pnts[i].z > boxSize || pnts[i].z < -boxSize) {
		 resetParticle(i);
		 }
		 */

		if(pnts[i].x > vboW)  resetParticle(i);
		if(pnts[i].x < 0)  resetParticle(i);
		//if(pnts[i].y < 0)			  resetParticle(i);
		//if(pnts[i].y > ofGetHeight()) resetParticle(i);
		if(pnts[i].z < 0)			  resetParticle(i);
		if(pnts[i].z > vboH) resetParticle(i);


	}

	// draw


}
예제 #3
0
  void update(sf::Time elapsed)
  {
    srand(time(NULL));
    for (std::size_t i = 0; i < m_particles.size(); ++i)
      {
	// update the particle lifetime
	Particle& p = m_particles[i];
	p.lifetime -= elapsed;

	// if the particle is dead, respawn it
	if (p.lifetime <= sf::Time::Zero)
	  resetParticle(i);

	// update the position of the corresponding vertex
	float time = elapsed.asSeconds();
	m_vertices[i].position.x += p.velocity.x * time;
	m_vertices[i].position.y += p.velocity.y * time + 1000.0*9.8*pow(time,2);
	
	if( m_vertices[i].position.x <= 0.0 )
	  p.velocity.x = -p.velocity.x;
	if( m_vertices[i].position.x >= 800.0 )
	  p.velocity.x = -p.velocity.x;
	if( m_vertices[i].position.y <= 0.0 )
	  p.velocity.y = -p.velocity.y;
	if( m_vertices[i].position.y >= 800.0 )
	  p.velocity.y = -p.velocity.y;

	// update the alpha (transparency) of the particle according to its lifetime
	float ratio = p.lifetime.asSeconds() / m_lifetime.asSeconds();
	//	m_vertices[i].color.a = static_cast<sf::Uint8>(ratio * 255);
	m_vertices[i].color = sf::Color(rand()%255, rand()%255, rand()%255, ratio*255 );
      }
  }
	void update(sf::Time elapsed)
	{
		for (std::size_t i = 0; i < m_particles.size(); i += 4)
		{
			// update the particle lifetime

			m_particles[i].velocity.y += m_particles[i].gravity.y * elapsed.asSeconds();
			Particle& p = m_particles[i];
			p.lifetime -= elapsed;

			// if the particle is dead, respawn it
			if (p.lifetime <= sf::Time::Zero)
				resetParticle(i);

			// update the position of the corresponding vertex
			m_vertices[i].position += (p.velocity)  * elapsed.asSeconds();
			p.location = m_vertices[i].position;

			m_vertices[i + 1].position = m_vertices[i].position + sf::Vector2f(25, 0);
			m_vertices[i + 2].position = m_vertices[i].position + sf::Vector2f(25, 25);
			m_vertices[i + 3].position = m_vertices[i].position + sf::Vector2f(0, 25);

			//update texture position
			m_vertices[i].texCoords = sf::Vector2f(0, 0);
			m_vertices[i + 1].texCoords = sf::Vector2f(200, 0);
			m_vertices[i + 2].texCoords = sf::Vector2f(200, 112.5);
			m_vertices[i + 3].texCoords = sf::Vector2f(0, 112.5);

			// update the alpha (transparency) of the particle according to its lifetime
			float ratio = p.lifetime.asSeconds() / m_lifetime.asSeconds();
			m_vertices[i].color.a = static_cast<sf::Uint8>(ratio * 255);
		}
	}
예제 #5
0
void ParticleEmitter::draw(Graphics *g) {
//    GLint min, mag;
//    glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &min);
//    glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &mag);
//    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    g->setupTexture("particle");
    glDepthMask(false);
    glDisable(GL_LIGHTING);
    g->enableBlend();
    glDisable(GL_CULL_FACE);

    float m[16];
    glGetFloatv(GL_MODELVIEW_MATRIX, m);
    Vector3 dx = Vector3(m[0], m[4], m[8]); // left-right
    Vector3 dy = Vector3(m[1], m[5], m[9]); // up-down
    Vector3 dz = Vector3(m[2], m[6], m[10]); // front-back

    glBegin(GL_QUADS);
    for (unsigned i = 0; i < m_maxParticles; i++) {
        Particle &p = m_particles[i];
        if (!p.active && m_toggle) {
            p.active = true;
            resetParticle(i);
        }

        if (p.active) {
            p.p = p.p + p.d * .017;
            p.d = p.d + p.f * .017;
            p.life = p.life - p.decay;

            if (p.life < 0) {
                p.active = false;
            }

            glColor4f(p.c.x, p.c.y, p.c.z, sqrt(p.life));
            float scale = m_scale * (p.life * p.life + .2);
            Vector3 ddx = dx * scale;
            Vector3 ddy = dy * scale;

            glTexCoord2f(0,1);
            glVertex3fv((p.p-ddx+ddy).xyz);
            glTexCoord2f(1,1);
            glVertex3fv((p.p+ddx+ddy).xyz);
            glTexCoord2f(1,0);
            glVertex3fv((p.p+ddx-ddy).xyz);
            glTexCoord2f(0,0);
            glVertex3fv((p.p-ddx-ddy).xyz);
        }
    }
    glEnd();

    glEnable(GL_CULL_FACE);
    g->disableBlend();
    glEnable(GL_LIGHTING);
    glDepthMask(true);
    g->teardownTexture();
}
예제 #6
0
void EntityManager::StarsEmitter::onParticleUpdated(ParticleSystem::Particle& particle, float) const
{
	if (particle.position.x < 0)
	{
		resetParticle(particle);
		particle.position.x = EntityManager::getInstance().getWidth();
	}
}
예제 #7
0
//重新设定系统中每个粒子的属性
void PSystem::reset ()
{
	std::list <Attribute>::iterator i;
	for(i=_particles.begin ();i!=_particles.end ();i++)
	{
		resetParticle(&(*i)); //这个函数是抽象函数,强制要求在子类中实现
	}
}
void DropParticles::reset()
{
	for( int i = 0; i < particles.size(); i++)
	{
		resetParticle(&particles[i]);
	}
	
}
예제 #9
0
	void onParticleUpdated(ParticleSystem::Particle& particle, float) const override
	{
		if (particle.position.x < 0)
		{
			resetParticle(particle);
			particle.position.x = 800;
		}
	}
예제 #10
0
void DropParticles::turnOnParticle( ga_particle * p, ofPoint pos, float size)
{
	resetParticle(p);
	p->pos		= pos;
	p->size		= size;
	p->alpha	= baseAlpha;
	p->bOn		= true;

}
예제 #11
0
void ParticleEmitter::addParticles(unsigned numParticles)
{
	ParticleAttribute newParticle;
	for (unsigned i = 0; i < numParticles; i++)
	{
		resetParticle(&newParticle);
		_particles.push_back(newParticle);
	}
}
예제 #12
0
void DropParticles::setup(int totalParticles)
{
	ga_particle ptemp;
	resetParticle(&ptemp);
	
	for( int i = 0; i < totalParticles; i++)
	{
		particles.push_back(ptemp);
	}
	
}
예제 #13
0
void Particle::update(sf::Time elapsed)
{
	for (std::size_t i = 0; i < Elems.size(); ++i)
	{
		ParticleElem& p = Elems[i];
		p.lifeTime -= elapsed;
		if (p.lifeTime <= sf::Time::Zero)
			resetParticle(i);
		vertices[i].position += p.velocity * elapsed.asSeconds();
		float ratio = p.lifeTime.asSeconds() / lifeTime.asSeconds();
		vertices[i].color = this->color;
	}
}
예제 #14
0
void Particles::spawnParticles(int numSpawn)
{
	for(size_t i = 0; i < numParticles && numSpawn; i++)
	{
		Particle& particle = particles[i];

		if( particle.alive ) continue;

		resetParticle(particle);
		particle.alive = true;

		numSpawn--;
	}
}
예제 #15
0
void Player::ShieldEmitter::createParticles(size_t count)
{
	// Remove all previous particles
	clearParticles();

	float angle = 2 * math::PI / count;

	for (size_t i = 0; i < count; ++i)
	{
		ParticleSystem::Particle p(*this);
		resetParticle(p);
		p.angle = angle * (i + 1);
		ParticleSystem::getInstance().addParticle(p);
	}
}
예제 #16
0
/**
  * You need to fill this in.
  *
  * Performs one step of the particle simulation. Should perform all physics
  * calculations and maintain the life property of each particle.
  */
void ParticleEmitter::updateParticles()
{

    for(int i = 0; i < m_maxParticles; ++i)
    {
        Particle &particle = m_particles[i];

        // Update particle here.
        particle.pos+= particle.dir*glm::vec3(m_speed);
        particle.dir += particle.force;
        particle.life -= particle.decay;
        //if(particle.life < 0) resetParticle(i);
        if(particle.pos.y < -20) resetParticle((i));
    }
}
예제 #17
0
//--------------------------------------------------------------
void ofxVBO::setup(){
    bDepthTest  =false;

	ofBackground(0, 0, 0);
	ofSetVerticalSync(true);
	fbo.allocate(ofGetWidth(),ofGetHeight(),true);

	// set the camera
	tranv.x = ofGetWidth()/2;
	tranv.y = ofGetHeight()/2;
	tranv.z = -600.0;


	// the world box size
	boxSize = 300.0;

	// Load the particle texture
	ofDisableArbTex();
	ofImage tempImage;
	tempImage.loadImage("images/human.png");
	texture.allocate(tempImage.getWidth(), tempImage.getHeight(), GL_RGBA);
	texture.loadData(tempImage.getPixels(), tempImage.getWidth(), tempImage.getHeight(), GL_RGBA);

	// Load the shader
	shader.loadShader("shaders/VBOShader");



	// Random Points
	for(int i=0; i<NUM_PARTICLES; i++) {
		resetParticle(i);
	}


	// Generate the VBO
	glGenBuffersARB(2, &vbo[0]);

	// VBO for color
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[0]);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, NUM_PARTICLES*4*sizeof(float), color, GL_STREAM_DRAW_ARB);

	// VBO for vertex positions
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo[1]);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, NUM_PARTICLES*3*sizeof(float), pnts, GL_STREAM_DRAW_ARB);
	ofLog(OF_LOG_VERBOSE,"ofxVBO setup done!");


}
예제 #18
0
void DropParticles::createRandomDrop( ofPoint startPos, ofPoint vel, float size )
{
	if( particles.size() < maxParticles )
	{
	ga_particle ptemp;
	resetParticle(&ptemp);
	turnOnParticle( &ptemp, startPos, baseSize);
	
	
	float sVel = baseGravity*.25;
	ptemp.vel.set(vel.x*sVel,vel.y*sVel,vel.z*sVel);
	ptemp.size = size;
	///////////////////x
	particles.push_back(ptemp);
	//cout << "new particle at " << startPos.x << " , " << startPos.y << " , " << startPos.z << endl;
	 
	}
	
}
예제 #19
0
        void update(sf::Time elapsed) {

            for (std::size_t i=0; i<m_particles.size(); ++i) {

                // update the particle lifetime
                m_particles[i].lifetime -= elapsed;

                // if the particle is dead, respawn it
                if (m_particles[i].lifetime <= sf::Time::Zero) resetParticle(i);

                // update the position of the corresponding vertex
                m_vertices[i].position += m_particles[i].velocity * elapsed.asSeconds();

                // update the alpha (transparency) of the particle according to its lifetime
                float ratio = m_particles[i].lifetime.asSeconds() / m_lifetime.asSeconds();

                m_vertices[i].color.a = static_cast<sf::Uint8>(ratio * 255);
            }
        }
예제 #20
0
void Particle::update(float frametime)
{
	if (!active)
		return;
	timeAlive += frametime;
	if (timeAlive >= maxTimeAlive)
	{
		resetParticle();
		return;
	}
	// update physics and drawing stuff

	setX(getX() + velocity.x * frametime);
	setY(getY() + velocity.y * frametime);
	rotationValue += frametime;
	if (rotationValue> 2*2.14159) //prevent overrotation
		rotationValue = 0;
	setRadians(rotationValue);

}
예제 #21
0
/**
  * You need to fill this in.
  *
  * Performs one step of the particle simulation. Should perform all physics
  * calculations and maintain the life property of each particle.
  */
void ParticleEmitter::updateParticles()
{
    float minlife = 5.0/0.02;
    if (m_activeParticles < m_maxParticles) m_activeParticles += m_maxParticles/minlife;
    if (m_activeParticles > m_maxParticles) m_activeParticles = m_maxParticles;
    for(unsigned i = 0; i < m_activeParticles; ++i)
    {
        if (!m_particles[i].active) {
            m_particles[i].active = true;
            resetParticle(i);
        } else {
            float wind = 0.1 * m_fuzziness;
            m_particles[i].pos = m_particles[i].pos + m_speed*m_particles[i].dir;
            m_particles[i].dir = m_particles[i].dir + m_particles[i].force;
            m_particles[i].dir += float3(urand(-wind, wind), urand(-wind, wind), urand(-wind, wind));
            m_particles[i].life -= m_particles[i].decay;

            if (m_particles[i].life < 0) {
                m_particles[i].active = false;
            }
        }
    }
}
/**
 * Actualiza las particulas
 * @param elapsedTime Tiempo desde el último frame
 */
void SpriteParticleSystem::update(sf::Time elapsedTime)
{
    //Calculamos el número de particulas a mostrar
    while(m_particles.size() != m_numParticles)
    {
        float particles = m_particles.size() - m_numParticles;
        
        if(m_particles.size() > m_numParticles)
        {
            this->removeParticles(particles);
        }
        else this->addParticles(particles);
    }
    
    //Recorremos todas las particulas ...
    for(SpriteParticleIterator it = m_particles.begin(); it != m_particles.end(); it++)
    {   
        //Disminuimos el tiempo de vida de la particula
        (*it)->lifeTime -= elapsedTime;
        
        //Si la particula muere, generamos una nueva
        if((*it)->lifeTime <= sf::Time::Zero)
        {
            resetParticle(std::distance<std::vector<SpriteParticle*>::const_iterator>(m_particles.begin(), it));       
        }
        
        //Controlamos el cambio de color
        if(m_twoColors)
        {
                m_color = randomColor(m_colorInit, m_colorEnd, (*it)->lifeTime);
                (*it)->sprite.setColor(m_color);
        }
        if(m_dissolve)
        {
            //Actualizamos el alpha (transparencia) de la particula de acuerdo a su tiempo de vida
            (*it)->sprite.setColor(sf::Color((*it)->sprite.getColor().r, (*it)->sprite.getColor().g, (*it)->sprite.getColor().b, static_cast<sf::Uint8>(m_lifeTime.asSeconds() * 255)));
        }

        //Actualizamos la velocidad de las particulas
        if(m_rotateParticle)
        {
            m_rotate = ((std::rand() % 360) * m_particleRotate / 180.f) * (*it)->lifeTime.asSeconds();
            (*it)->sprite.setRotation(m_rotate);
        }
        
        (*it)->velocity.x += m_gravity.x * elapsedTime.asSeconds();
        (*it)->velocity.y += m_gravity.y * elapsedTime.asSeconds();
        
        //Actualizamos el tamaño de las particulas
        if(m_grow)
        {
            m_scale = randomVector2f(m_growScale.x, m_growScale.y, (*it)->lifeTime);
            (*it)->sprite.setScale(m_scale);
        }
        else
        {
            if(m_uniformScale)
            {
                m_scale = randomVector2f(m_scale.x, m_scale.y, (*it)->lifeTime);
                (*it)->sprite.setScale(m_scale);
            }
            else
            {
                (*it)->sprite.setScale(m_scale.x, m_scale.y);
            }
        }
        
        //Actualizamos la posicion del sprite correspondiente
        float getPosX = (*it)->sprite.getPosition().x;
        float getPosY = (*it)->sprite.getPosition().y;
        float posX = getPosX += (*it)->velocity.x * elapsedTime.asSeconds() * m_particleSpeed;
        float posY = getPosY += (*it)->velocity.y * elapsedTime.asSeconds() * m_particleSpeed;
        (*it)->sprite.setPosition(posX, posY);
    }
}
예제 #23
0
void PSystem::addParticle ()
{
	Attribute attribute;
	resetParticle(&attribute);//初始化一下
	_particles.push_back (attribute);//向尾部加入一个元素;
}
예제 #24
0
void ParticleEmitter::resetParticles() {
    for (unsigned i = 0; i < m_maxParticles; i++)
        resetParticle(i);
}
예제 #25
0
void Mutalisk::setParticleBehaviour()
{
	switch (state)
	{
	case IDLE:
		resetParticle();
		break;
	case MOVE:
		resetParticle();
		break;
	case MOVE_ALERT:
		resetParticle();
		break;
	case MOVE_ALERT_TO_ATTACK:
		resetParticle();
		break;
	case ATTACK:
		if (current_animation == &attack_up)
		{
			if (particle != NULL && !attack_up_part.on)
			{
				resetParticle();
			}
			if (!attack_up_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					particle_offset = { 0, -30 };
					particle = app->particle->addParticle(attack_up_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.y = -150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					attack_up_part.on = true;
					timer_particle.start();

				}
				attack_up_part.on = false;
			}
		}

		if (current_animation == &attack_right_up)
		{
			if (particle != NULL && !attack_right_up_part.on)
			{
				resetParticle();
			}

			if (!attack_right_up_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_right_up_part.on = true;
					particle_offset = { 30, -20 };
					particle = app->particle->addParticle(attack_right_up_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.x = 150.0f;
					particle->speed.y = -150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					timer_particle.start();
				}
				attack_right_up_part.on = false;
			}

		}

		if (current_animation == &attack_right)
		{
			if (particle != NULL && !attack_right_part.on)
			{
				resetParticle();

			}

			if (!attack_right_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_right_part.on = true;
					particle_offset = { 30, -10 };
					particle = app->particle->addParticle(attack_right_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.x = 150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					timer_particle.start();
				}
				attack_right_part.on = false;
			}

		}

		if (current_animation == &attack_right_down)
		{
			if (particle != NULL && !attack_right_down_part.on)
			{
				resetParticle();
			}

			if (!attack_right_down_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_right_down_part.on = true;
					particle_offset = { 23, 10 };
					particle = app->particle->addParticle(attack_right_down_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.x = 150.0f;
					particle->speed.y = 150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					timer_particle.start();
				}
				attack_right_down_part.on = false;
			}

		}

		if (current_animation == &attack_down)
		{
			if (particle != NULL && !attack_down_part.on)
			{
				resetParticle();
			}

			if (!attack_down_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_down_part.on = true;
					particle_offset = { 2, 10 };
					particle = app->particle->addParticle(attack_down_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.y = 150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					timer_particle.start();
				}
				attack_down_part.on = false;
			}

		}

		if (current_animation == &attack_left_down)
		{
			if (particle != NULL && !attack_left_down_part.on)
			{
				resetParticle();
			}

			if (!attack_left_down_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_left_down_part.on = true;
					particle_offset = { -17, 15 };
					particle = app->particle->addParticle(attack_left_down_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.x = -150.0f;
					particle->speed.y = 150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					timer_particle.start();
				}
				attack_left_down_part.on = false;
			}
		}

		if (current_animation == &attack_left)
		{
			if (particle != NULL && !attack_left_part.on)
			{
				resetParticle();
			}

			if (!attack_left_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_left_part.on = true;
					particle_offset = { -30, -10 };
					particle = app->particle->addParticle(attack_left_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.x = -150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
								
					timer_particle.start();
				}
				attack_left_part.on = false;
			}

		}

		if (current_animation == &attack_left_up)
		{
			if (particle != NULL && !attack_left_up_part.on)
			{
				resetParticle();
			}

			if (!attack_left_up_part.on)
			{
				if (timer_particle.read() >= particle_frequency)
				{
					attack_left_up_part.on = true;
					particle_offset = { -20, -12 };
					particle = app->particle->addParticle(attack_left_up_part, center.x, center.y, particle_offset.x, particle_offset.y, 0.5f, app->particle->mutalisk_spore);
					particle->speed.x = -150.0f;
					particle->speed.y = -150.0f;
					if (target_to_attack != NULL)
					particle_aux = app->particle->addParticle(mutalisk_hit, target_to_attack->center.x, target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					if (second_target_to_attack != NULL)
						particle_aux2 = app->particle->addParticle(mutalisk_hit, second_target_to_attack->center.x, second_target_to_attack->center.y, 0, 0, 1.0f, app->particle->mutalisk_hit);
					timer_particle.start();
				}
				attack_left_up_part.on = false;
			}
		}
		break;
	case DYING:
		resetParticle();
		break;
	case WAITING_PATH_MOVE:
		resetParticle();
		break;
	case WAITING_PATH_MOVE_ALERT:
		resetParticle();
		break;
	case WAITING_PATH_MOVE_ALERT_TO_ATTACK:
		resetParticle();
		break;
	case SIEGE_MODE_ON:
		resetParticle();
		break;
	case SIEGE_MODE_OFF:
		resetParticle();
		break;
	case IDLE_SIEGE_MODE:
		resetParticle();
		break;
	case ATTACK_SIEGE_MODE:
		resetParticle();
		break;
	}
}
예제 #26
0
/**
  * Resets all particles in this emitter to their initial states
  */
void ParticleEmitter::resetParticles()
{
    for (int i = 0; i < m_maxParticles; i++)
        resetParticle(i);
}
예제 #27
0
void ParticleEditor::OpenConfigFile(QString filename)
{
	QFile sFile(fileName);
	if (sFile.open(QIODevice::ReadOnly | QIODevice::Text)){
		QTextStream in(&sFile);
		QString content = in.readAll();
		QJsonParseError jsonError;
		QJsonDocument document = QJsonDocument::fromJson(content.toLatin1(), &jsonError);
		if (jsonError.error == QJsonParseError::NoError && document.isObject()){
			QJsonObject obj = document.object();
			QJsonArray resList = obj["resList"].toArray();
			QJsonObject particleData = obj["particleData"].toObject();

			resourceView->clearResourceList();
			for (int i = 0; i < resList.size(); i++){
				resourceView->addRes(resList.at(i).toString());
			}

			auto layer = dynamic_cast<C3DLayer*>(g_Layer);
			auto particleSystem = layer->getParticleSystem();
			auto acclerationMin = Vec3(particleData["accleration_min_x"].toDouble(), particleData["accleration_min_y"].toDouble(), particleData["accleration_min_z"].toDouble());
			auto acclerationMax = Vec3(particleData["accleration_max_x"].toDouble(), particleData["accleration_max_y"].toDouble(), particleData["accleration_max_z"].toDouble());
			auto sizeMin = Vec3(particleData["size_min_x"].toDouble(), particleData["size_min_y"].toDouble(), particleData["size_min_z"].toDouble());
			auto sizeMax = Vec3(particleData["size_max_x"].toDouble(), particleData["size_max_y"].toDouble(), particleData["size_max_z"].toDouble());
			auto sizeVelocity = Vec3(particleData["size_velocity_x"].toDouble(), particleData["size_velocity_z"].toDouble(), particleData["size_velocity_z"].toDouble());
			auto velocityMin = Vec3(particleData["velocity_min_x"].toDouble(), particleData["velocity_min_y"].toDouble(), particleData["velocity_min_z"].toDouble());
			auto velocityMax = Vec3(particleData["velocity_max_x"].toDouble(), particleData["velocity_max_y"].toDouble(), particleData["velocity_max_z"].toDouble());
			auto colorMin = Vec3(particleData["color_min_x"].toDouble(), particleData["color_min_y"].toDouble(), particleData["color_min_z"].toDouble());
			auto colorMax = Vec3(particleData["color_max_x"].toDouble(), particleData["color_max_y"].toDouble(), particleData["color_max_z"].toDouble());
			auto colorVelocity = Vec3(particleData["color_velocity_x"].toDouble(), particleData["color_velocity_y"].toDouble(), particleData["color_velocity_z"].toDouble());
			auto life = Vec3(particleData["life_min"].toDouble(), particleData["life_max"].toDouble(), particleData["life_velocity"].toDouble());
			particleSystem->resetParticleAccelerationMin(acclerationMin);
			particleSystem->resetParticleAccelerationMax(acclerationMax);
			particleSystem->resetParticleSizeMin(sizeMin);
			particleSystem->resetParticleSizeMax(sizeMax);
			particleSystem->resetParticleSizeVelocity(sizeVelocity);
			particleSystem->resetParticleVelocityMin(velocityMin); 
			particleSystem->resetParticleVelocityMax(velocityMax);
			particleSystem->resetParticleColorMin(colorMin);
			particleSystem->resetParticleColorMax(colorMax);
			particleSystem->resetParticleColorVelocity(colorVelocity);
			particleSystem->resetParticleLifeMin(life.x);
			particleSystem->resetParticleLifeMax(life.y); 
			particleSystem->resetParticleLife_Velocity(life.z);
			particleSystem->SetTexture(particleData["texture"].toString().toLocal8Bit().data());
			particleSystem->setColor(particleData["m_color_r"].toDouble(), particleData["m_color_g"].toDouble(), particleData["m_color_b"].toDouble(), particleData["m_color_a"].toDouble());
			eParticleType _type;
			switch (particleData["particle_type"].toInt()){
			case 0:
				_type = eParticleType::PT_FIRE;
				break;
			case 1:
				_type = eParticleType::PT_FIREWORK;
				break;
			case 2:
				_type = eParticleType::PT_FOUNTAIN;
				break;
			case 3:
				_type = eParticleType::PT_MAX;
				break;
			}
			layer->resetParticle(particleData["count"].toInt(), _type, { particleData["blendfunc_src"].toInt(), particleData["blendfunc_dst"].toInt() });
			controlView->setTarget(particleSystem);
			controlView->setParticleType(_type);
		}
		else{
			addConsoleInfo("文件错误");
		}
	}
	else{
		addConsoleInfo("读取文件错误");
	}
}