pslib
Class GenericEmitter

java.lang.Object
  extended by pslib.GenericParticle
      extended by pslib.DynamicParticle
          extended by pslib.GenericEmitter
All Implemented Interfaces:
PSConstants
Direct Known Subclasses:
TargetEmitter

public class GenericEmitter
extends DynamicParticle
implements PSConstants

GenericEmitter Class

The GenericEmitter class extends the functionality of the DynamicParticle class by allowing further DynamicParticles to be attached. Attached particles may then be subjected to a random initial velocity and any attached PSForce objects or PSBehaviour objects.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.


Field Summary
 
Fields inherited from interface pslib.PSConstants
CAM2D_LOOK, CAM2D_RIGHT, CAM2D_UP, CORNER, INVERSE, INVERSE_TRIANGULAR, LEADING, LINEAR, MIDPOINT, NONE, STATIC, TRAILING, TRIANGULAR
 
Constructor Summary
GenericEmitter(int b)
          Create a new object instance with the specified buffer size
GenericEmitter(int b, int d)
          Create a new object instance with the specified buffer size and decay time
 
Method Summary
 boolean attach(DynamicParticle p)
          Attach a particle to the emitter
 int attach(DynamicParticle[] pa)
          Attach an array of particles to the emitter
 int attachedParticles()
          Return the current particle count
 void clear()
          Clear all attached particles
 void clearForces()
          Remove all attached forces
 GenericEmitter copy()
          Return a copy of this emitter
 void debug(processing.opengl.PGraphicsOpenGL pgl)
          Render the emitter location to the specified OpenGL renderer
 void debug(processing.opengl.PGraphicsOpenGL pgl, PSVector cpv, PSVector ctv, PSVector cuv)
          Render the emitter location to the specified OpenGL renderer
 int getBufferSize()
          Return the emitter buffer size
 PSVector getDimensionScalars()
          Return a reference to the emitter dimension scalar vector
protected  PSVector getEmissionVector(PSVector d, float s)
           
protected  PSVector getRadialVector()
           
 boolean isDead()
          Return true if this and all attached particles are dead
 void map(GenericEmitter e)
          Map the properties of this e to that specified preserving references
 boolean remove(DynamicParticle p)
          Remove the specified particle from the emitter
 void render(processing.opengl.PGraphicsOpenGL pgl)
          Render all attached particles to the specified OpenGL renderer
 void render(processing.opengl.PGraphicsOpenGL pgl, PSVector cpv, PSVector ctv, PSVector cuv)
          Render all attached particles to the specified OpenGL renderer
 void setAlpha(float a)
          Set the alpha value of all attached particles
 void setBufferSize(int s)
          Set the emitter buffer size
 void setColour(PSColour c)
          Set the colour of all attached particles
 void setColour(PSColour c, int t)
          Set the colour of all attached particles with the specified fade time
 void setColour(WeightedList<PSColour> c)
          Set the colour of all attached particles
 void setColour(WeightedList<PSColour> c, int t)
          Set the colour of all attached particles with the specified fade time
 void setDimensionScalars(PSVector v)
          Set the emitter dimension scalars
 void setDirection(PSVector d)
          Set the particle emission direction
 void setDirectionMode(int m)
          Set the direction mode - STATIC, LEADING, TRAILING
 void setForces(PSForce f)
          Attach a force to the emitter
 void setForces(PSForce[] f)
          Attach an array of forces to the emitter
 void setInitialVelocity(float v)
          Set the initial velocity scalar for attached particles
 void setInitialVelocity(float min, float max)
          Set the initial velocity scalar range for attached particles
 void setMaxVelocity(float v)
          Set the maximum velocity for all attached particles
 void setParticleStealing(boolean b)
          Enable/disable particle stealing
 void setRadius(float r)
          Set the particle creation radius
 void setRadius(float min, float max)
          Set the particle creation radius range
 void setSpeed(float s)
          Set the particle speed multiplier
 void setSpread(float s)
          Set the particle emission spread
 DynamicParticle[] toArray()
          Return all attached particles as an array
 void update()
          Update this all attached particles
protected  void updateParticle(DynamicParticle p)
          Update the specified particle
 
Methods inherited from class pslib.DynamicParticle
clearBehaviour, getBehaviour, getDecay, getDecayTime, getInitialDecayTime, getMass, getRenderAlpha, getRenderSize, getSnapshot, isDynamic, map, setAlphaEnvelope, setBehaviour, setBehaviour, setDecayTime, setMass, setSizeEnvelope
 
Methods inherited from class pslib.GenericParticle
getAlpha, getColour, getPosition, getSize, getVelocity, setPosition, setSize, setVelocity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericEmitter

public GenericEmitter(int b)
Create a new object instance with the specified buffer size

Parameters:
b - buffer size

GenericEmitter

public GenericEmitter(int b,
                      int d)
Create a new object instance with the specified buffer size and decay time

Parameters:
b - buffer size
d - decay (ms)
Method Detail

setColour

public void setColour(PSColour c)
Set the colour of all attached particles

Overrides:
setColour in class GenericParticle
Parameters:
c - colour

setColour

public void setColour(PSColour c,
                      int t)
Set the colour of all attached particles with the specified fade time

Overrides:
setColour in class GenericParticle
Parameters:
c - colour
t - fade time (ms)

setColour

public void setColour(WeightedList<PSColour> c)
Set the colour of all attached particles

Particle colour will be assigned at random from the specified WeightedList

Parameters:
c - colour list

setColour

public void setColour(WeightedList<PSColour> c,
                      int t)
Set the colour of all attached particles with the specified fade time

Particle colour will be assigned at random from the specified WeightedList

Parameters:
c - colour list
t - fade time (ms)

setAlpha

public void setAlpha(float a)
Set the alpha value of all attached particles

Overrides:
setAlpha in class GenericParticle
Parameters:
a - alpha

setSpeed

public final void setSpeed(float s)
Set the particle speed multiplier

Parameters:
s - speed multiplier

setInitialVelocity

public final void setInitialVelocity(float v)
Set the initial velocity scalar for attached particles

Initial particle velocity is calculated as the inverse of the parent velocity multiplied by the specified values.

Default: 1.0

Parameters:
v - scalar

setInitialVelocity

public final void setInitialVelocity(float min,
                                     float max)
Set the initial velocity scalar range for attached particles

Initial particle velocity is calculated as the inverse of the parent velocity multiplied by a random value between the specified limits.

Default: 1.0, 2.0

Parameters:
min -
max -

setRadius

public final void setRadius(float r)
Set the particle creation radius

The particle creation radius specifies the distance from the emitter at which particles will be created.

Default: 0.0

Parameters:
r - radius

setRadius

public final void setRadius(float min,
                            float max)
Set the particle creation radius range

The particle creation radius range specifies the minimum and maximum distances from the emitter at which particles will be created.

Default: 0.0, 0.0

Parameters:
min - minimum
max - maximum

setDirection

public final void setDirection(PSVector d)
Set the particle emission direction

Default: (0.0, -1.0, 0.0)

Parameters:
d - direction vector

setSpread

public final void setSpread(float s)
Set the particle emission spread

The particle emission spread specifies the emission cone for the emitter. A value of 1.0 will result in spherical emission, while a value of 0.0 will result in emission along the direction vector.

Default: 1.0

Parameters:
s - spread

setMaxVelocity

public final void setMaxVelocity(float v)
Set the maximum velocity for all attached particles

Default: 5.0

Parameters:
v - maximum velocity

setDirectionMode

public final void setDirectionMode(int m)
Set the direction mode - STATIC, LEADING, TRAILING

The direction mode allows the particle emission direction to be modified based on the emitter velocity. The STATIC mode will result in particle emission along the direction vector, while LEADING and TRAILING will result in particle emission along the velocity vector and inverse velocity vector respectively.

Default: STATIC

Parameters:
m - mode

setDimensionScalars

public final void setDimensionScalars(PSVector v)
Set the emitter dimension scalars

The dimension scalar vector defines the dimensionality of the emitter. For example, a dimension scalar vector of (1.0, 1.0, 0.0) result in all attached particles being emitted only on the two dimensional xy plane.

All attached forces and targets will also be assigned the dimension scalar vector of their parent emitter.

Parameters:
v -

getDimensionScalars

public final PSVector getDimensionScalars()
Return a reference to the emitter dimension scalar vector

Returns:
a reference to the emitter dimension scalar vector

setParticleStealing

public final void setParticleStealing(boolean b)
Enable/disable particle stealing

If particle stealing is enabled and the buffer is full then older particles will be removed to allow for newer ones to be attached.


isDead

public boolean isDead()
Return true if this and all attached particles are dead

Overrides:
isDead in class DynamicParticle
Returns:
true if this and all attached particles are dead

toArray

public final DynamicParticle[] toArray()
Return all attached particles as an array

The function finds all non-null and alive particles within the buffer and copies references to them into the returned array. As such it is not particularly efficient and should not be thought of as a direct reference to the particle buffer.

Returns:
all attached particles as an array

setBufferSize

public final void setBufferSize(int s)
Set the emitter buffer size

The emitter buffer size dictates the maximum total particles that may be attached to the emitter. If the specified size is less than the current buffer size, attached particles will be culled, eldest first.

Parameters:
s - size

getBufferSize

public final int getBufferSize()
Return the emitter buffer size

Returns:
the emitter buffer size

attachedParticles

public final int attachedParticles()
Return the current particle count

Returns:
the current particle count

render

public void render(processing.opengl.PGraphicsOpenGL pgl)
Render all attached particles to the specified OpenGL renderer

Overrides:
render in class DynamicParticle
Parameters:
pgl - OpenGL renderer

render

public void render(processing.opengl.PGraphicsOpenGL pgl,
                   PSVector cpv,
                   PSVector ctv,
                   PSVector cuv)
Render all attached particles to the specified OpenGL renderer

Overrides:
render in class DynamicParticle
Parameters:
pgl - OpenGL renderer
cpv - camera position vector
ctv - camera target vector
cuv - camera up vector

debug

public void debug(processing.opengl.PGraphicsOpenGL pgl)
Render the emitter location to the specified OpenGL renderer

Overrides:
debug in class DynamicParticle
Parameters:
pgl - OpenGL renderer

debug

public void debug(processing.opengl.PGraphicsOpenGL pgl,
                  PSVector cpv,
                  PSVector ctv,
                  PSVector cuv)
Render the emitter location to the specified OpenGL renderer

Overrides:
debug in class DynamicParticle
Parameters:
pgl - OpenGL renderer
cpv - camera position vector
ctv - camera target vector
cuv - camera up vector

update

public void update()
Update this all attached particles

Overrides:
update in class DynamicParticle

updateParticle

protected void updateParticle(DynamicParticle p)
Update the specified particle

Parameters:
p - particle

attach

public final boolean attach(DynamicParticle p)
Attach a particle to the emitter

When a particle is attached to the emitter, the particle position and velocity vectors will be modified to reflect the behaviour of the emitter. References to both vectors will, however, be preserved.

Parameters:
p - particle
Returns:
true if the particle was successfully attached

attach

public final int attach(DynamicParticle[] pa)
Attach an array of particles to the emitter

Parameters:
pa - particle array
Returns:
the amount of particles attached

remove

public final boolean remove(DynamicParticle p)
Remove the specified particle from the emitter

If multiple references to the particle exist, they will all be removed

Parameters:
p - particle
Returns:
true if the specified particle was found and removed

clear

public final void clear()
Clear all attached particles


setForces

public final void setForces(PSForce f)
Attach a force to the emitter

Parameters:
f - force

setForces

public final void setForces(PSForce[] f)
Attach an array of forces to the emitter

Parameters:
f - force array

clearForces

public final void clearForces()
Remove all attached forces


copy

public GenericEmitter copy()
Return a copy of this emitter

The returned copy will contain an empty buffer the same size as that of the source particle and will adhere to the rules defined in the map() function of this object.

Overrides:
copy in class DynamicParticle
Returns:
a copy of this emitter

map

public final void map(GenericEmitter e)
Map the properties of this e to that specified preserving references

The returned object takes a copy of all emitter variables, with the exception for the dimension scalar vector for which a reference is used. DynamicParticle variables are mapped based on the rules defined in the DynamicParticle map() function.

Parameters:
e - emitter
See Also:
DynamicParticle

getRadialVector

protected PSVector getRadialVector()

getEmissionVector

protected PSVector getEmissionVector(PSVector d,
                                     float s)