Android Open Source - opengl-particles Particle






From Project

Back to project page opengl-particles.

License

The source code is released under:

Apache License

If you think the Android project opengl-particles listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*******************************************************************************
 * Copyright 2014 Kenneth Maffei/*from   w ww  .ja  v  a 2 s  .co  m*/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/

package com.kennethmaffei.particles;

import android.graphics.PointF;

/**
 * An individual particle, with attributes and a quad for rendering
 * @author Kenneth Maffei
 *
 */
public class Particle {
  public Vector3 position = new Vector3();            //Current position
  public Vector3 velocity = new Vector3();            //Current velocity
  public Vector3 acceleration = new Vector3();        //Current acceleration
  public float lifeTime;                              //Total lifetime
  public float life;                                  //Accumulated life at time t
  public PointF size = new PointF();                  //Current size
  public PointF deltaSize = new PointF();             //Change in size per time increment
  
  //Current colors and color changes per time increment
  public float colorR;                                //Current red value
  public float colorG;                                //Current green value
  public float colorB;                                //Current blue value
  public float colorA;                                //Current alpha value
  //deltaColor is used for the special case of fire, but not for the generic particle systems
  public float deltaColorR;                           //Red delta per unit time
  public float deltaColorG;                           //Green delta per unit time
  public float deltaColorB;                           //Blue delta per unit time
  public float deltaColorA;                           //Alpha delta per unit time
  
  public Quad quad;                                   //The rendered quad for the particle
  
  /**
   * Since particles are re-used, we do not need to re-allocate everything
   * If the quad already exists, then perform a reinitialize
   * 
   * @param startSize - the starting size for the particle
   * @param tex - openGL texture
   * @param isFacingParticle - tells the quad what kind we are
   */
  public void initializeQuad(PointF startSize, int tex, boolean isFacingParticle) {
    if(quad == null) {
      quad = new Quad(startSize.x, startSize.y, position);
      quad.setTexture(tex);
      quad.isParticle = true;
      quad.isFacingParticle = isFacingParticle;
    }
    else
      quad.update(startSize.x, startSize.y, position);
    
    quad.r = colorR;
    quad.g = colorG;
    quad.b = colorB;
    quad.a = colorA;
  }
  
  /**
   * Called each frame to update the quad's position
   */
  public void updateQuad() {
    quad.resetSize(size.x, size.y, position);
    quad.r = colorR;
    quad.g = colorG;
    quad.b = colorB;
    quad.a = colorA;
  }
}




Java Source Code List

com.kennethmaffei.particles.BlackSmoke.java
com.kennethmaffei.particles.Fire.java
com.kennethmaffei.particles.GLRenderer.java
com.kennethmaffei.particles.GenericParticleSystem.java
com.kennethmaffei.particles.Globals.java
com.kennethmaffei.particles.MainActivity.java
com.kennethmaffei.particles.ParticleSystem.java
com.kennethmaffei.particles.Particle.java
com.kennethmaffei.particles.Quad.java
com.kennethmaffei.particles.Vector3.java