pslib
Class DynamicParticle

java.lang.Object
  extended by pslib.GenericParticle
      extended by pslib.DynamicParticle
All Implemented Interfaces:
PSConstants
Direct Known Subclasses:
AudioParticle, BufferedParticle, GenericEmitter, ImageParticle, ParentParticle, TextParticle

public class DynamicParticle
extends GenericParticle
implements PSConstants

DynamicParticle Class

The DynamicParticle object extends the functionality of the GenericParticle class by permitting dynamic behaviour over a particle life-span defined within the constructor.

Envelopes may be assigned to both particle alpha and size parameters allowing the modulation of variables dependent on the current particle decay. Similarly PSBehaviours may be attached to the particle, permitting per-frame modulation of parameters.

The results of alpha and size modulation envelopes may be obtained through the getRenderAlpha() and getRenderSize() functions. Calls to setAlpha() and setSize() will allow modification of the base value for the modulation envelope, while calls to getAlpha() and getSize() will return this base value.

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
DynamicParticle()
          Create a new static object instance
DynamicParticle(int d)
          Create a new dynamic object instance with the specified decay time
 
Method Summary
 void clearBehaviour()
          Clear the particle behaviours
 DynamicParticle copy()
          Return a copy of this DynamicParticle
 void debug(processing.opengl.PGraphicsOpenGL pgl)
          Render the particle location to the specified OpenGL renderer
 void debug(processing.opengl.PGraphicsOpenGL pgl, PSVector cpv, PSVector ctv, PSVector cuv)
          Render the particle location to the specified OpenGL renderer
protected  PSBehaviour[] getBehaviour()
          Return the attached particle behaviour array
 float getDecay()
          Return the current decay value between 1 and 0
 int getDecayTime()
          Return the remaining decay time in milliseconds
 int getInitialDecayTime()
          Return the decay time specified on particle creation in milliseconds
 float getMass()
          Return the particle mass
 float getRenderAlpha()
          Return the modulated particle alpha value
 float getRenderSize()
          Return the modulated particle size value
 StaticParticle getSnapshot()
          Return a StaticParticle containing the current particle position, colour, modulated alpha, modulated size and remaining decay time.
 boolean isDead()
          Return true if the particle is dead
 boolean isDynamic()
          Return true if the particle is dynamic and is therefore decaying
 void map(DynamicParticle p)
          Map the properties of this particle to that specified preserving references
 void render(processing.opengl.PGraphicsOpenGL pgl)
          Render the particle to the specified OpenGL renderer
 void render(processing.opengl.PGraphicsOpenGL pgl, PSVector cpv, PSVector ctv, PSVector cuv)
          Render the particle to the specified OpenGL renderer
 void setAlphaEnvelope(PSRange e)
          Set the particle alpha modulation envelope for dynamic particles
 void setBehaviour(PSBehaviour b)
          Set the particle behaviour
 void setBehaviour(PSBehaviour[] b)
          Set the particle behaviour
 void setDecayTime(int t)
          Set the particle decay time
 void setMass(float m)
          Set the particle mass
 void setSizeEnvelope(PSRange e)
          Set the particle size modulation envelope for dynamic particles
 void update()
          Update the particle
 
Methods inherited from class pslib.GenericParticle
getAlpha, getColour, getPosition, getSize, getVelocity, setAlpha, setColour, setColour, setPosition, setSize, setVelocity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DynamicParticle

public DynamicParticle()
Create a new static object instance


DynamicParticle

public DynamicParticle(int d)
Create a new dynamic object instance with the specified decay time

Parameters:
d - decay time (ms)
Method Detail

setDecayTime

public void setDecayTime(int t)
Set the particle decay time

Calls to the function will reset the current particle decay curve and begin a new curve of the duration specified.

Parameters:
t - decay time (ms)

getDecay

public float getDecay()
Return the current decay value between 1 and 0

Returns:
the current decay value

getDecayTime

public int getDecayTime()
Return the remaining decay time in milliseconds


getInitialDecayTime

public int getInitialDecayTime()
Return the decay time specified on particle creation in milliseconds

Returns:
the decay time specified on particle creation

isDynamic

public boolean isDynamic()
Return true if the particle is dynamic and is therefore decaying

Returns:
true if the particle is dynamic

isDead

public boolean isDead()
Return true if the particle is dead

Returns:
true if the particle is dead

setMass

public void setMass(float m)
Set the particle mass

Default: 1.0

Parameters:
m - mass

getMass

public float getMass()
Return the particle mass

Returns:
the particle mass

setBehaviour

public void setBehaviour(PSBehaviour b)
Set the particle behaviour

Parameters:
b - behaviour

setBehaviour

public void setBehaviour(PSBehaviour[] b)
Set the particle behaviour

The specified behaviours will be applied in the order in which the exist within the array

Parameters:
b - behaviour

getBehaviour

protected PSBehaviour[] getBehaviour()
Return the attached particle behaviour array

Returns:
the attached particle behaviour array

clearBehaviour

public void clearBehaviour()
Clear the particle behaviours


setAlphaEnvelope

public void setAlphaEnvelope(PSRange e)
Set the particle alpha modulation envelope for dynamic particles

The alpha modulation value is a scalar applied to the particle alpha as specified with setAlpha(). For example, a minimum value of 0.5 and a maximum value of 2.0 with a LINEAR mode and a curve exponent of 1.0 will result in a modulation of particle alpha between half and double its specified value throughout the duration of the particle.

Parameters:
e - envelope

getRenderAlpha

public float getRenderAlpha()
Return the modulated particle alpha value

Returns:
the modulated particle alpha value

setSizeEnvelope

public void setSizeEnvelope(PSRange e)
Set the particle size modulation envelope for dynamic particles

The alpha modulation value is a scalar applied to the particle alpha as specified with setSize(). For example, a minimum value of 0.5 and a maximum value of 2.0 with a LINEAR mode and a curve exponent of 1.0 will result in a modulation of particle size between half and double its specified value throughout the duration of the particle.

Parameters:
e -

getRenderSize

public float getRenderSize()
Return the modulated particle size value

Returns:
the modulated particle size value

getSnapshot

public StaticParticle getSnapshot()
Return a StaticParticle containing the current particle position, colour, modulated alpha, modulated size and remaining decay time.

Returns:
a StaticParticle containing the current particle parameters

update

public void update()
Update the particle


render

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

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

render

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

Overrides:
render in class GenericParticle
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 particle location to the specified OpenGL renderer

The debug method renders the particle as a GenericParticle object discarding any dynamic modifications to particle properties.

Parameters:
pgl - OpenGL renderer

debug

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

The debug method renders the particle as a GenericParticle object discarding any dynamic modifications to particle properties.

Parameters:
pgl - OpenGL renderer
cpv - camera position vector
ctv - camera target vector
cuv - camera up vector

copy

public DynamicParticle copy()
Return a copy of this DynamicParticle

The returned object takes a copy of position, velocity, colour, alpha, size and mass variables, while references to particle alpha envelope, size envelope and attached behaviours are used. This decision was made to facilitate particle templates, which would rarely require independent envelopes or behaviours.

Returns:
a copy of this DynamicParticle

map

public final void map(DynamicParticle p)
Map the properties of this particle to that specified preserving references

The returned object takes a copy of position, velocity, colour, alpha, size and mass variables, while references to particle alpha envelope, size envelope and attached behaviours are used. This decision was made to facilitate particle templates, which would rarely require independent envelopes or behaviours.

Parameters:
p - particle