com.jme.effects
Class ParticleManager

java.lang.Object
  extended bycom.jme.scene.Controller
      extended bycom.jme.effects.ParticleManager
All Implemented Interfaces:
java.io.Serializable

public class ParticleManager
extends Controller

ParticleManager Example usage: ParticleManager manager = new ParticleManager(300, display.getRenderer().getCamera()); manager.getParticles().addController(manager); someNode.attachChild(manager.getParticles()); See the method comments for more usage information. note: The idea of using one TriMesh to control particles and much of the code related to picking starting angles was kindly donated by Java Cool Dude.

Version:
$Id: ParticleManager.java,v 1.23 2005/03/28 17:56:02 renanse Exp $ TODO Points and Lines (not just quads) TODO Particles stretched based on historical path TODO Particle motion models
Author:
Joshua Slack
See Also:
Serialized Form

Field Summary
static int GS_LINE
           
static int GS_MESH
           
static int GS_POINT
           
static int GS_RECTANGLE
           
 
Fields inherited from class com.jme.scene.Controller
RT_CLAMP, RT_CYCLE, RT_WRAP
 
Constructor Summary
ParticleManager(int noParticles, Camera cam)
          ParticleManager constructor
 
Method Summary
 java.lang.Object clone()
          Clones every aspect of this manager into a new manager
 void forceRespawn()
          Force all dead particles back to life.
 Camera getCamera()
          Get the currently set Camera used for billboad calcs.
 boolean getControlFlow()
          Does this manager regulate the particle flow?
 Vector3f getEmissionDirection()
          getEmissionDirection returns the emission direction.
 float getEmissionMaximumAngle()
          getEmissionMaximumAngle returns the maximum emission angle.
 ColorRGBA getEndColor()
          getEndColor returns the ending color.
 float getEndSize()
          getEndSize returns the end size.
 Geometry getGeoMesh()
          getGeoMesh returns the currently set geometry mesh.
 int getGeometry()
          Get which Geometry method is being used by the underlying system.
 Vector3f getGravityForce()
          getGravityForce returns the gravity force.
 float getInitialVelocity()
          Get the acceleration set in this manager.
 int getIterations()
          Return the number this manager has warmed up
 Line getLine()
          getLine returns the currently set line segment.
 Particle[] getParticleArray()
           
 TriMesh getParticles()
          Get the TriMesh that holds all of the particle information for display.
 float getParticlesMinimumLifeTime()
          getParticlesMinimumLifeTime returns the minimum life time of a particle.
 int getParticlesNumber()
          Get the number of particles managed by this manager.
 Vector3f getParticlesOrigin()
          Get the origin point set in this manager.
 float getParticleSpinSpeed()
          getParticleSpinSpeed returns the current spin speed of particles.
 float getPrecision()
          Get how soon after the last update the manager will send updates to the particles.
 float getRandomMod()
          getRandomFactor returns the current randomness of particles.
 Rectangle getRectangle()
          getRectangle returns the currently set rectangle segment.
 int getReleaseRate()
          Get the number of particles the manager should release per second.
 float getReleaseVariance()
          Get the variance possible on the release rate.
 ColorRGBA getStartColor()
          getStartColor returns the starting color.
 float getStartSize()
          getStartSize returns the start size.
 void setCamera(Camera cam)
          Set the Camera whose position should be used to determine billboard facing direction.
 void setControlFlow(boolean regulate)
          Set the regulate flow property on the manager.
 void setEmissionDirection(Vector3f direction)
          Set the general direction that particles are emitted in.
 void setEmissionMaximumAngle(float f)
          Set the maximum angle (in radians) that particles can be emitted away from the emission direction.
 void setEndColor(ColorRGBA color)
          Set the end color for particles.
 void setEndSize(float size)
          Set the size particles will approach as they age.
 void setGeometry(Geometry mesh)
          Set a Geometry's verts to be the random emission points
 void setGeometry(int type)
          Set which Geometry method is being used by the underlying system.
 void setGeometry(Line line)
          Set a line segment to be used as the "emittor".
 void setGeometry(Rectangle rect)
          Set a rectangular patch to be used as the "emittor".
 void setGravityForce(Vector3f force)
          Set a vector describing the force of gravity on a particle.
 void setInitialVelocity(float velocity)
          Set the acceleration for any new particles created (or recreated) by this manager.
 void setIterations(int iterations)
          Sets the iterations for the warmup and calls warmUp with the number of iterations as the argument
 void setParticlesMinimumLifeTime(float lifeSpan)
          Set the minimum lifespan of new particles (or recreated) managed by this manager.
 void setParticlesOrigin(Vector3f origin)
          Set the origin for any new particles created (or recreated) by this manager.
 void setParticleSpinSpeed(float speed)
          Set the spinSpeed of new particles managed by this manager.
 void setPrecision(float precision)
          Set how soon after the last update the manager will send updates to the particles.
 void setRandomMod(float mod)
          Set the "randomness" modifier.
 void setReleaseRate(int particlesPerSecond)
          Set the number of particles the manager should release per second.
 void setReleaseVariance(float variance)
          Set the variance possible on the release rate.
 void setStartColor(ColorRGBA color)
          Set the start color for particles.
 void setStartSize(float size)
          Set the size of the new particles generated by this manager.
 void update(float secondsPassed)
          Update the particles managed by this manager.
 void updateRotationMatrix()
           
 void warmUp(int iterations)
          Runs the update method of this particle manager for iteration seconds with an update every .1 seconds (IE iterations * 10 update(.1f) calls).
 
Methods inherited from class com.jme.scene.Controller
getMaxTime, getMinTime, getRepeatType, getSpeed, isActive, putClone, setActive, setMaxTime, setMinTime, setRepeatType, setSpeed
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GS_POINT

public static final int GS_POINT
See Also:
Constant Field Values

GS_LINE

public static final int GS_LINE
See Also:
Constant Field Values

GS_RECTANGLE

public static final int GS_RECTANGLE
See Also:
Constant Field Values

GS_MESH

public static final int GS_MESH
See Also:
Constant Field Values
Constructor Detail

ParticleManager

public ParticleManager(int noParticles,
                       Camera cam)
ParticleManager constructor

Parameters:
noParticles - Desired number of particles in this system.
cam - The camera to have the billboarded particles face.
Method Detail

update

public void update(float secondsPassed)
Update the particles managed by this manager. If any particles are "dead" recreate them at the origin position (which may be a point, line or rectangle.) See com.jme.scene.Controller.update(float)

Specified by:
update in class Controller
Parameters:
secondsPassed - float

forceRespawn

public void forceRespawn()
Force all dead particles back to life.


updateRotationMatrix

public void updateRotationMatrix()

setParticlesOrigin

public void setParticlesOrigin(Vector3f origin)
Set the origin for any new particles created (or recreated) by this manager. This is applicable only to managers generating from a point (not a line, rectangle, etc..)

Parameters:
origin - new origin position

getParticlesOrigin

public Vector3f getParticlesOrigin()
Get the origin point set in this manager.

Returns:
origin

setInitialVelocity

public void setInitialVelocity(float velocity)
Set the acceleration for any new particles created (or recreated) by this manager.

Parameters:
velocity - particle v0

getInitialVelocity

public float getInitialVelocity()
Get the acceleration set in this manager.

Returns:
The initialVelocity

setStartColor

public void setStartColor(ColorRGBA color)
Set the start color for particles. This is the base color of the quad.

Parameters:
color - The start color.

getStartColor

public ColorRGBA getStartColor()
getStartColor returns the starting color.

Returns:
ColorRGBA The begining color.

setEndColor

public void setEndColor(ColorRGBA color)
Set the end color for particles. The base color of the quad will linearly approach this color from the start color over the lifetime of the particle.

Parameters:
color - ColorRGBA The ending color.

getEndColor

public ColorRGBA getEndColor()
getEndColor returns the ending color.

Returns:
The ending color

setCamera

public void setCamera(Camera cam)
Set the Camera whose position should be used to determine billboard facing direction.

Parameters:
cam - Camera

getCamera

public Camera getCamera()
Get the currently set Camera used for billboad calcs.

Returns:
Camera

setGravityForce

public void setGravityForce(Vector3f force)
Set a vector describing the force of gravity on a particle. Generally, the values should be less than .01f

Parameters:
force - Vector3f

getGravityForce

public Vector3f getGravityForce()
getGravityForce returns the gravity force.

Returns:
The gravity force vector.

setStartSize

public void setStartSize(float size)
Set the size of the new particles generated by this manager. If a value less than zero is given, zero is used.

Parameters:
size - Start size.

getStartSize

public float getStartSize()
getStartSize returns the start size.

Returns:
The start size.

setEndSize

public void setEndSize(float size)
Set the size particles will approach as they age. If a value less than zero is given, zero is used.

Parameters:
size - The ending size.

getEndSize

public float getEndSize()
getEndSize returns the end size.

Returns:
The end size.

setEmissionDirection

public void setEmissionDirection(Vector3f direction)
Set the general direction that particles are emitted in. This will be modified by the emission angle. You need to use a non-zero normalized direction.

Parameters:
direction - Vector3f

getEmissionDirection

public Vector3f getEmissionDirection()
getEmissionDirection returns the emission direction.

Returns:
The emission direction.

setEmissionMaximumAngle

public void setEmissionMaximumAngle(float f)
Set the maximum angle (in radians) that particles can be emitted away from the emission direction. Any angle less than 0 is trimmed to 0.

Parameters:
f - The new emission maximum angle.

getEmissionMaximumAngle

public float getEmissionMaximumAngle()
getEmissionMaximumAngle returns the maximum emission angle.

Returns:
The maximum emission angle.

setParticlesMinimumLifeTime

public void setParticlesMinimumLifeTime(float lifeSpan)
Set the minimum lifespan of new particles (or recreated) managed by this manager. if a value less than zero is given, 1.0f is used.

Parameters:
lifeSpan - float

getParticlesMinimumLifeTime

public float getParticlesMinimumLifeTime()
getParticlesMinimumLifeTime returns the minimum life time of a particle.

Returns:
The current minimum life time.

setParticleSpinSpeed

public void setParticleSpinSpeed(float speed)
Set the spinSpeed of new particles managed by this manager. Setting it to 0 means no spin.

Parameters:
speed - float

getParticleSpinSpeed

public float getParticleSpinSpeed()
getParticleSpinSpeed returns the current spin speed of particles.

Returns:
current spin speed of particles.

setRandomMod

public void setRandomMod(float mod)
Set the "randomness" modifier. 0 = not random

Parameters:
mod - The new randomness of particle information.

getRandomMod

public float getRandomMod()
getRandomFactor returns the current randomness of particles.

Returns:
float The current randomness.

getParticlesNumber

public int getParticlesNumber()
Get the number of particles managed by this manager.

Returns:
The number of particles managed by this manager.

getReleaseRate

public int getReleaseRate()
Get the number of particles the manager should release per second.

Returns:
The number of particles that should be released per second.

setReleaseRate

public void setReleaseRate(int particlesPerSecond)
Set the number of particles the manager should release per second.

Parameters:
particlesPerSecond - number of particles per second

getPrecision

public float getPrecision()
Get how soon after the last update the manager will send updates to the particles.

Returns:
The precision.

setPrecision

public void setPrecision(float precision)
Set how soon after the last update the manager will send updates to the particles. Defaults to .01f (10ms)

This means that if an update is called every 2ms (e.g. running at 500 FPS) the particles position and stats will be updated every fifth frame with the elapsed time (in this case, 10ms) since previous update.

Parameters:
precision - in seconds

getReleaseVariance

public float getReleaseVariance()
Get the variance possible on the release rate. 0.0f = no variance 0.5f = between releaseRate / 2f and 1.5f * releaseRate

Returns:
release variance as a percent.

setReleaseVariance

public void setReleaseVariance(float variance)
Set the variance possible on the release rate.

Parameters:
variance - release rate +/- variance as a percent (eg. .5 = 50%)

getControlFlow

public boolean getControlFlow()
Does this manager regulate the particle flow?

Returns:
true if this manager regulates how many particles per sec are emitted.

setControlFlow

public void setControlFlow(boolean regulate)
Set the regulate flow property on the manager.

Parameters:
regulate - regulate particle flow.

getParticles

public TriMesh getParticles()
Get the TriMesh that holds all of the particle information for display.

Returns:
TriMesh holding particle information.

getGeometry

public int getGeometry()
Get which Geometry method is being used by the underlying system. 0 = point 1 = line 2 = rectangle 3 = trimesh

Returns:
An int representing hte current geometry method being used.

setGeometry

public void setGeometry(int type)
Set which Geometry method is being used by the underlying system. This is already done by setGeometry(Line) and setGeometry(Rectangle) You should not need to use this method unless you are switching between geometry already set by those methods.

Parameters:
type - Geometry type to use

setGeometry

public void setGeometry(Line line)
Set a line segment to be used as the "emittor".

Parameters:
line - New emittor line segment.

setGeometry

public void setGeometry(Rectangle rect)
Set a rectangular patch to be used as the "emittor".

Parameters:
rect - New rectangular patch.

setGeometry

public void setGeometry(Geometry mesh)
Set a Geometry's verts to be the random emission points

Parameters:
mesh - The new geometry random verts.

getLine

public Line getLine()
getLine returns the currently set line segment.

Returns:
Current line segment.

getRectangle

public Rectangle getRectangle()
getRectangle returns the currently set rectangle segment.

Returns:
Current rectangle segment.

getGeoMesh

public Geometry getGeoMesh()
getGeoMesh returns the currently set geometry mesh.

Returns:
Current geometry mesh.

getIterations

public int getIterations()
Return the number this manager has warmed up

Returns:
int

setIterations

public void setIterations(int iterations)
Sets the iterations for the warmup and calls warmUp with the number of iterations as the argument

Parameters:
iterations -

warmUp

public void warmUp(int iterations)
Runs the update method of this particle manager for iteration seconds with an update every .1 seconds (IE iterations * 10 update(.1f) calls). This is used to "warm up" and get the particle manager going.

Parameters:
iterations - The number of iterations to warm up.

clone

public java.lang.Object clone()
Clones every aspect of this manager into a new manager


getParticleArray

public Particle[] getParticleArray()