com.jmex.effects.particles
Class Particle

java.lang.Object
  extended by com.jmex.effects.particles.Particle
All Implemented Interfaces:
Savable

public class Particle
extends java.lang.Object
implements Savable

Particle defines a single Particle of a Particle system. Generally, you would not interact with this class directly.

Version:
$Id: Particle.java 4133 2009-03-19 20:40:11Z blaine.dev $
Author:
Joshua Slack

Nested Class Summary
static class Particle.Status
           
 
Field Summary
(package private) static int VAL_CURRENT_MASS
           
(package private) static int VAL_CURRENT_SIZE
           
(package private) static int VAL_CURRENT_SPIN
           
 
Constructor Summary
Particle()
          Empty constructor - mostly for use with Savable interface
Particle(ParticleSystem parent)
          Normal use constructor.
 
Method Summary
 java.lang.Class<? extends Particle> getClassTag()
           
 int getCurrentAge()
           
 ColorRGBA getCurrentColor()
           
 float getInvMass()
           
 float getMass()
           
 Vector3f getPosition()
           
 int getStartIndex()
           
 Particle.Status getStatus()
           
 Triangle getTriangleModel()
           
 Vector3f getVelocity()
           
 void init()
          Cause this particle to reset it's lifespan, velocity, color, age and size per the parent's settings.
 void init(Vector3f velocity, Vector3f position, float lifeSpan)
          Cause this particle to reset it's color, age and size per the parent's settings.
 void killParticle()
           
 void read(JMEImporter e)
           
 void recreateParticle(float lifeSpan)
          Reset particle conditions.
 void resetAge()
          Resets current age to 0
 void setPosition(Vector3f position)
          Set the position of the particle in space.
 void setStartIndex(int index)
          Set the starting index where this particle is represented in its parent's geometry data
 void setStatus(Particle.Status status)
          Set the status of this particle.
 void setTriangleModel(Triangle t)
          Sets a triangle model to use for particle calculations when using particle type ParticleType.GeomMesh.
 void setVelocity(Vector3f velocity)
          Set the current velocity of this particle
 boolean updateAndCheck(float secondsPassed)
           update position (using current position and velocity), color (interpolating between start and end color), size (interpolating between start and end size), spin (using parent's spin speed) and current age of particle.
 void updateVerts(Camera cam)
          Update the vertices for this particle, taking size, spin and viewer into consideration.
 void write(JMEExporter e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VAL_CURRENT_SIZE

static final int VAL_CURRENT_SIZE
See Also:
Constant Field Values

VAL_CURRENT_SPIN

static final int VAL_CURRENT_SPIN
See Also:
Constant Field Values

VAL_CURRENT_MASS

static final int VAL_CURRENT_MASS
See Also:
Constant Field Values
Constructor Detail

Particle

public Particle()
Empty constructor - mostly for use with Savable interface


Particle

public Particle(ParticleSystem parent)
Normal use constructor. Sets up the parent and particle type for this particle.

Parameters:
parent - the particle collection this particle belongs to
Method Detail

init

public void init()
Cause this particle to reset it's lifespan, velocity, color, age and size per the parent's settings. status is set to Status.Available and location is set to 0,0,0. Actual geometry data is not affected by this call, only particle params.


init

public void init(Vector3f velocity,
                 Vector3f position,
                 float lifeSpan)
Cause this particle to reset it's color, age and size per the parent's settings. status is set to Status.Available. Location, velocity and lifespan are set as given. Actual geometry data is not affected by this call, only particle params.

Parameters:
velocity - new initial particle velocity
position - new initial particle position
lifeSpan - new particle lifespan in ms

recreateParticle

public void recreateParticle(float lifeSpan)
Reset particle conditions. Besides the passed lifespan, we also reset color, size, and spin angle to their starting values (as given by parent.) Status is set to Status.Available.

Parameters:
lifeSpan - the recreated particle's new lifespan

updateVerts

public void updateVerts(Camera cam)
Update the vertices for this particle, taking size, spin and viewer into consideration. In the case of particle type ParticleType.GeomMesh, the original triangle normal is maintained rather than rotating it to face the camera or parent vectors.

Parameters:
cam - Camera to use in determining viewer aspect. If null, or if parent is not set to camera facing, parent's left and up vectors are used.

updateAndCheck

public boolean updateAndCheck(float secondsPassed)

update position (using current position and velocity), color (interpolating between start and end color), size (interpolating between start and end size), spin (using parent's spin speed) and current age of particle. If this particle's age is greater than its lifespan, it is set to status DEAD.

Note that this only changes the parameters of the Particle, not the geometry the particle is associated with.

Parameters:
secondsPassed - number of seconds passed since last update.
Returns:
true if this particle is not ALIVE (in other words, if it is ready to be reused.)

killParticle

public void killParticle()

resetAge

public void resetAge()
Resets current age to 0


getCurrentAge

public int getCurrentAge()
Returns:
the current age of the particle in ms

getPosition

public Vector3f getPosition()
Returns:
the current position of the particle in space

setPosition

public void setPosition(Vector3f position)
Set the position of the particle in space.

Parameters:
position - the new position in world coordinates

getStatus

public Particle.Status getStatus()
Returns:
the current status of this particle.
See Also:
Particle.Status

setStatus

public void setStatus(Particle.Status status)
Set the status of this particle.

Parameters:
status - new status of this particle
See Also:
Particle.Status

getVelocity

public Vector3f getVelocity()
Returns:
the current velocity of this particle

setVelocity

public void setVelocity(Vector3f velocity)
Set the current velocity of this particle

Parameters:
velocity - the new velocity

getCurrentColor

public ColorRGBA getCurrentColor()
Returns:
the current color applied to this particle

getStartIndex

public int getStartIndex()
Returns:
the start index of this particle in relation to where it exists in its parent's geometry data.

setStartIndex

public void setStartIndex(int index)
Set the starting index where this particle is represented in its parent's geometry data

Parameters:
index -

getMass

public float getMass()
Returns:
the mass of this particle. Only used by ParticleInfluences such as drag.

getInvMass

public float getInvMass()
Returns:
the inverse mass of this particle. Often useful for skipping constant division by mass calculations. If the mass is 0, the inverse mass is considered to be positive infinity. Conversely, if the mass is positive infinity, the inverse is 0. The inverse of negative infinity is considered to be -0.

setTriangleModel

public void setTriangleModel(Triangle t)
Sets a triangle model to use for particle calculations when using particle type ParticleType.GeomMesh. The particle will maintain the triangle's ratio and plane of orientation. It will spin (if applicable) around the triangle's normal axis. The triangle should already have its center and normal fields calculated before calling this method.

Parameters:
t - the triangle to model this particle after.

getTriangleModel

public Triangle getTriangleModel()
Returns:
the triangle model used by this particle
See Also:
setTriangleModel(Triangle)

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Throws:
java.io.IOException

getClassTag

public java.lang.Class<? extends Particle> getClassTag()
Specified by:
getClassTag in interface Savable