j3d.org Code

org.j3d.geom.particle
Class BaseEmitter

java.lang.Object
  extended by org.j3d.geom.particle.BaseEmitter
All Implemented Interfaces:
ParticleInitializer
Direct Known Subclasses:
ExplosionPointEmitter, MaxAgePointEmitter, MaxAgePointForceEmitter, MaxTimePointEmitter, PointEmitter, PolylineEmitter

public abstract class BaseEmitter
extends java.lang.Object
implements ParticleInitializer

Common base class that implements the ParticleInitializer interface for all emitters.

Mass and surface area are initialised to be zero. Lifetime variation is always set to zero, unless changed by the user.

Internationalisation Resource Names

Version:
$Revision: 2.1 $
Author:
Justin Couch

Field Summary
protected  float[] color
          Initial colour to make all particles
protected  float initialMass
          Initial mass that is imparted to all particles
protected  int lifetime
          Base lifetime in milliseconds
protected  float lifetimeVariation
          The amount of lifetime variation permitted
protected  int particleCount
          The maximum number of particles to generate
protected  java.util.Random randomiser
          Random number generator for sign values
protected  float speed
          The initial speed of the particles.
protected  float surfaceArea
          Initial surface area given to all particles
protected  float variation
          Amount of variation on the randomness
 
Constructor Summary
protected BaseEmitter()
          Construct a new default emitter, with everything initialized to zeroes, except colour, which is white.
protected BaseEmitter(int maxTime, int maxParticleCount, float[] color, float speed, float variation)
          Construct a new emitter instance for a point emitter.
 
Method Summary
 void getColor(float[] val)
          Get the value of the initial colour that particles are set to.
 float getLifetimeVariation()
          Get the amount of variation in the lifetime of the particles generated.
 float getMass()
          Get the current mass assigned to each particle.
 int getMaxParticleCount()
          Fetch the current value of the maximum particle count.
 int getParticleLifetime()
          Get the current maximum lifetime of the particles.
 float getParticleVariation()
          Get the amount of variation currently permitted in the particles.
 float getSpeed()
          Get the current speed that particles are initialised with.
 float getSurfaceArea()
          Get the current surface area assigned to particles.
 void setColor(float r, float g, float b, float alpha)
          Set the initial color that that the particle is given.
 void setLifetimeVariation(float variation)
          Change the variation factor for the emitted particles.
 void setMass(float mass)
          Change the mass of the particle.
 void setMaxParticleCount(int maxCount)
          Adjust the maximum number of particles that this initializer is going to work with.
 void setParticleLifetime(int time)
          Change the maximum lifetime of the particles.
 void setParticleVariation(float variation)
          Change the variation factor for the emitted particles.
 void setSpeed(float speed)
          Change the initial speed that the particles are endowed with.
 void setSurfaceArea(float area)
          Change the apparent surface area.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.j3d.geom.particle.ParticleInitializer
initialize, numParticlesToCreate
 

Field Detail

lifetime

protected int lifetime
Base lifetime in milliseconds


particleCount

protected int particleCount
The maximum number of particles to generate


color

protected float[] color
Initial colour to make all particles


speed

protected float speed
The initial speed of the particles. Should be >= 0


variation

protected float variation
Amount of variation on the randomness


lifetimeVariation

protected float lifetimeVariation
The amount of lifetime variation permitted


initialMass

protected float initialMass
Initial mass that is imparted to all particles


surfaceArea

protected float surfaceArea
Initial surface area given to all particles


randomiser

protected java.util.Random randomiser
Random number generator for sign values

Constructor Detail

BaseEmitter

protected BaseEmitter()
Construct a new default emitter, with everything initialized to zeroes, except colour, which is white.


BaseEmitter

protected BaseEmitter(int maxTime,
                      int maxParticleCount,
                      float[] color,
                      float speed,
                      float variation)
Construct a new emitter instance for a point emitter. The number of particles to create each frame is driven from the maximum particle count divided by the average lifetime.

Parameters:
maxTime - The time length of the particles to exist in milliseconds
maxParticleCount - The maximum number of particles to manage
color - The initial color of particles (4 component)
speed - The speed of the particls to start with
variation - The amount of variance for the initial values
Method Detail

setMaxParticleCount

public void setMaxParticleCount(int maxCount)
Adjust the maximum number of particles that this initializer is going to work with. This should not normally be called by the end user. The particle system that this initializer is registered with will call this method when it's corresponding method is called.

Specified by:
setMaxParticleCount in interface ParticleInitializer
Parameters:
maxCount - The new maximum particle count to use

getMaxParticleCount

public int getMaxParticleCount()
Fetch the current value of the maximum particle count.

Specified by:
getMaxParticleCount in interface ParticleInitializer
Returns:
A value >= 0

setParticleLifetime

public void setParticleLifetime(int time)
                         throws java.lang.IllegalArgumentException
Change the maximum lifetime of the particles. The lifetime of particles is defined in milliseconds, and must be positive.

Specified by:
setParticleLifetime in interface ParticleInitializer
Parameters:
time - The new lifetime, in milliseconds
Throws:
java.lang.IllegalArgumentException - The lifetime is zero or negative

getParticleLifetime

public int getParticleLifetime()
Get the current maximum lifetime of the particles. Time is represented in milliseconds.

Specified by:
getParticleLifetime in interface ParticleInitializer
Returns:
The current particle lifetime, in milliseconds

setLifetimeVariation

public void setLifetimeVariation(float variation)
                          throws java.lang.IllegalArgumentException
Change the variation factor for the emitted particles. This will only effect particles created after this is set, and not before. Variation values are limited to [0,1].

Specified by:
setLifetimeVariation in interface ParticleInitializer
Parameters:
variation - The new variation amount
Throws:
java.lang.IllegalArgumentException - The variation amount was within [0,1]

getLifetimeVariation

public float getLifetimeVariation()
Get the amount of variation in the lifetime of the particles generated.

Specified by:
getLifetimeVariation in interface ParticleInitializer
Returns:
The current lifetime variation factor in the range [0,1]

setParticleVariation

public void setParticleVariation(float variation)
Change the variation factor for the emitted particles. This will only effect particles created after this is set, and not before. Variation may be negative, but results are unknown if it is. Works best if the variation is limited to [0,1].

Specified by:
setParticleVariation in interface ParticleInitializer
Parameters:
variation - The new variation amount

getParticleVariation

public float getParticleVariation()
Get the amount of variation currently permitted in the particles.

Specified by:
getParticleVariation in interface ParticleInitializer
Returns:
The current particle variation factor

setColor

public void setColor(float r,
                     float g,
                     float b,
                     float alpha)
Set the initial color that that the particle is given. If the emitter does not support the alpha channel, ignore the parameter.

Specified by:
setColor in interface ParticleInitializer
Parameters:
r - The red component of the color
g - The green component of the color
b - The blue component of the color
alpha - The alpha component of the color

getColor

public void getColor(float[] val)
Get the value of the initial colour that particles are set to. The array should be length 4.

Specified by:
getColor in interface ParticleInitializer
Parameters:
val - An array of length 4 to copy the internal values into

setSurfaceArea

public void setSurfaceArea(float area)
                    throws java.lang.IllegalArgumentException
Change the apparent surface area. Surface area is measured in square metres. Surface area must be non-negative otherwise an exception will be generated.

Specified by:
setSurfaceArea in interface ParticleInitializer
Parameters:
area - The new surface area value to use, in metres squared
Throws:
java.lang.IllegalArgumentException - The surface area value was negative

getSurfaceArea

public float getSurfaceArea()
Get the current surface area assigned to particles.

Specified by:
getSurfaceArea in interface ParticleInitializer
Returns:
A value greater than or equal to zero

setMass

public void setMass(float mass)
             throws java.lang.IllegalArgumentException
Change the mass of the particle. Mass is measured in kilograms. Mass must be non-negative otherwise an exception will be generated.

Specified by:
setMass in interface ParticleInitializer
Parameters:
mass - The mass of an individual particle
Throws:
java.lang.IllegalArgumentException - The mass value was negative

getMass

public float getMass()
Get the current mass assigned to each particle.

Specified by:
getMass in interface ParticleInitializer
Returns:
A non-negative value representing the mass

setSpeed

public void setSpeed(float speed)
Change the initial speed that the particles are endowed with. Some emitters may need to have a direction value as well to determine the velocity that the particles are emitted with. Speed may be any value. Negatives are just treated like starting the particles in the opposite direction to those of positive speed. A speed of zero has all particles starting stationary.

Specified by:
setSpeed in interface ParticleInitializer
Parameters:
speed - The magnitude of the speed to use

getSpeed

public float getSpeed()
Get the current speed that particles are initialised with.

Specified by:
getSpeed in interface ParticleInitializer
Returns:
A value of the speed

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org