espresso3d.engine.world.sector.particle
Class E3DParticle

java.lang.Object
  extended byespresso3d.engine.base.E3DEngineItem
      extended byespresso3d.engine.renderer.base.E3DRenderable
          extended byespresso3d.engine.renderer.base.E3DTexturedRenderable
              extended byespresso3d.engine.renderer.base.E3DAnimatedTextureRenderable
                  extended byespresso3d.engine.world.sector.base.E3DPortalEnabledAnimatedTextureRenderable
                      extended byespresso3d.engine.world.sector.particle.E3DSprite
                          extended byespresso3d.engine.world.sector.particle.E3DBillboardSprite
                              extended byespresso3d.engine.world.sector.particle.E3DParticle
All Implemented Interfaces:
E3DCollisionDetectableObject, E3DPortalEnabledItem
Direct Known Subclasses:
BluePlasmaParticle, RedPlasmaParticle

public abstract class E3DParticle
extends E3DBillboardSprite

Author:
Curt A particle uses hardware to simulate billboarding. It used to be a type of billboard sprite in older versions, however, it is no longer necessary for it to have built-in billboarding features. The hardware will always make it look at the camera. Therefore, this class now extends e3DSprite instead of E3DBillboardSprite to remove all the billboarding code (slow). If a particle is collideable detectable and a collision occurs during its update, it is NOT moved and the onCollisionDuringUpdate callback is called. This way, collisions can be handled BEFORE they happen, not after they happen and the particle has already moved through the object. Collision detection for particles is based on its bounding quad.

Constructor Summary
E3DParticle(E3DEngine engine, E3DVector3F startPosition, E3DVector3F startMovementDirection, double velocity, double life, double startAlpha, double endAlpha, double size, int loops, double startDelay, E3DAnimatedTextureFrame[] animationFrames, int animationLoops)
           
E3DParticle(E3DEngine engine, E3DVector3F startPosition, E3DVector3F startMovementDirection, double velocity, double life, double startAlpha, double endAlpha, double size, int loops, double startDelay, E3DAnimatedTextureFrame[] animationFrames, int animationLoops, int blendMode)
           
E3DParticle(E3DEngine engine, E3DVector3F startPosition, E3DVector3F startMovementDirection, double velocity, double life, double startAlpha, double endAlpha, double size, int loops, double startDelay, java.lang.String textureName)
          Create a new particle
E3DParticle(E3DEngine engine, E3DVector3F startPosition, E3DVector3F startMovementDirection, double velocity, double life, double startAlpha, double endAlpha, double size, int loops, double startDelay, java.lang.String textureName, int blendMode)
           
E3DParticle(E3DParticle toCopy)
          Copy an existing particle
 
Method Summary
 double getCurrentFrameVelocity()
          This will always return the scaled velocity the particle was last moved at.
 E3DVector3F getCurrentMovementDirection()
          Get the normalised direction the particle is set to move within this life cycle.
 double getEndAlpha()
          Get the alpha the particle is at when its at the end of its loops (between 0 and 1)
 double getLife()
          Get how many seconds the particle will live after the start delay of the life cycle has expired.
 int getLoops()
          Get number of loops the particle lives.
 E3DParticleSystem getParticleSystem()
          Get the particlesystem the particle lives in
 double getStartAlpha()
          Get the alpha the particle starts with (between 0 and 1)
 double getStartDelay()
          Get the delay the particle waits at the beginning of a loop before it begins moving (Seconds).
 E3DVector3F getStartMovementDirection()
          Get the normalised direction the particle should move at the beginning of its life cycle.
 E3DVector3F getStartPosition()
          The position the particle starts at the beginning of a loop
 E3DVector3F getTranslationAmt(double lastFrameTimeSeconds)
          Return the translation vector that will be used to translate the particle this frame with a lastFrameUpdateTime of lastFrameTimeSeconds
 double getVelocity()
          Get the velocity of the particle.
 boolean isAlive()
           
abstract  boolean isCollisionCausedByMovement()
          Set this to true if the particle in the system needs to cause collisions when it moves.
abstract  void onCollisionActor(E3DCollision collision)
          Intercept collision with actor callbacks
abstract  boolean onCollisionDuringUpdate(E3DCollision collision)
          This callback gets fired when the particle hits something in the world.
abstract  void onCollisionSprite(E3DCollision collision)
          Intercept collision with sprite callbacks
abstract  E3DParticle onGetClone()
           
 void render()
          Render a single particle.
 void rotate(double angle, E3DVector3F upVec)
          Rotate the the direction the particle faces.
 void rotateMovementDirection(double angle, E3DVector3F upVec, boolean permanently)
          Rotate the particle around upVec angle amount.
 void setCurrentMovementDirection(E3DVector3F currentMovementDirection)
          Set the direction the particle should move within this life cycle.
 void setEndAlpha(double endAlpha)
          Set the alpha the particle is at when its at the end of its loops (between 0 and 1)
 void setLife(double life)
          Set how many seconds the particle will live.
 void setLoops(int loops)
          Set number of loops the particle lives.
 void setStartAlpha(double startAlpha)
          Set the alpha the particle begins at (between 0 and 1)
 void setStartDelay(double startDelay)
          Set the delay the particle waits at the beginning of a loop before it begins rendering and moving (Seconds).
 void setStartMovementDirection(E3DVector3F startMovementDirection)
          Set the direction the particle should move at the beginning of its life cycles.
 void setStartPosition(E3DVector3F startPosition)
          Set the position the particle starts at the beginning of a loop
 void setVelocity(double velocity)
          Set the velocity the particle travels at.
 void translate(E3DVector3F translationVec)
          Translate particle geometry and startPosition
 boolean update(E3DActor curActor, double lastFrameTimeSeconds)
          Update the particle - move in direction at the velocity speed.
 
Methods inherited from class espresso3d.engine.world.sector.particle.E3DBillboardSprite
isLockX, isLockY, isLockZ, setLockX, setLockY, setLockZ, update
 
Methods inherited from class espresso3d.engine.world.sector.particle.E3DSprite
getBoundingObject, getKey, getOrientation, getQuad, getSize, getTriangleList, getUniqueVertexPositionList, scale, setBoundingObject, setPosition, setQuad, setRenderMode
 
Methods inherited from class espresso3d.engine.world.sector.base.E3DPortalEnabledAnimatedTextureRenderable
checkSectorChangeDuringMovement, getSector, setSector
 
Methods inherited from class espresso3d.engine.renderer.base.E3DAnimatedTextureRenderable
getAnimatedTexture, setAnimatedTexture, update
 
Methods inherited from class espresso3d.engine.renderer.base.E3DTexturedRenderable
getTexture, getTextureDetail0, getTextureDetail1, isTextureAvailable, isTextureDetail0Available, isTextureDetail1Available, setTexture, setTextureDetail0, setTextureDetail1
 
Methods inherited from class espresso3d.engine.renderer.base.E3DRenderable
getBlendMode, getRenderMode, initCorrectGeometryRenderer, isKeyChanged, setBlendMode, setKeyChanged
 
Methods inherited from class espresso3d.engine.base.E3DEngineItem
getEngine, setEngine
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface espresso3d.engine.collision.base.E3DCollisionDetectableObject
getEngine, getSector, isCollideable
 

Constructor Detail

E3DParticle

public E3DParticle(E3DEngine engine,
                   E3DVector3F startPosition,
                   E3DVector3F startMovementDirection,
                   double velocity,
                   double life,
                   double startAlpha,
                   double endAlpha,
                   double size,
                   int loops,
                   double startDelay,
                   java.lang.String textureName)
Create a new particle

Parameters:
engine - The engine the particle resides in
startPosition - The position the particle starts at
startMovementDirection - The direciton the particle starts moving at the beginning of its life.
velocity - The velocity the particle moves at. This is scaled each frame by the engine
life - The particles lifespan (seconds). This time begins after the start delay of a life cycle has expired.
startAlpha - Alpha value (0.0 - 1.0) of the particle at beginning of life. Currently unimplemented (Always 1)
endAlpha - The alpha value (0.0 - 1.0) of the particle at the end of life. Currently unimplemented (Always 1)
size - The size of the particle
loops - Number times to loop its life cycle (-1 is infinite)
startDelay - Number of seconds to delay before beginning rendering itself and movement at the start of a life cycle. This only delays for the first loop iteration.

E3DParticle

public E3DParticle(E3DEngine engine,
                   E3DVector3F startPosition,
                   E3DVector3F startMovementDirection,
                   double velocity,
                   double life,
                   double startAlpha,
                   double endAlpha,
                   double size,
                   int loops,
                   double startDelay,
                   E3DAnimatedTextureFrame[] animationFrames,
                   int animationLoops)

E3DParticle

public E3DParticle(E3DEngine engine,
                   E3DVector3F startPosition,
                   E3DVector3F startMovementDirection,
                   double velocity,
                   double life,
                   double startAlpha,
                   double endAlpha,
                   double size,
                   int loops,
                   double startDelay,
                   java.lang.String textureName,
                   int blendMode)

E3DParticle

public E3DParticle(E3DEngine engine,
                   E3DVector3F startPosition,
                   E3DVector3F startMovementDirection,
                   double velocity,
                   double life,
                   double startAlpha,
                   double endAlpha,
                   double size,
                   int loops,
                   double startDelay,
                   E3DAnimatedTextureFrame[] animationFrames,
                   int animationLoops,
                   int blendMode)

E3DParticle

public E3DParticle(E3DParticle toCopy)
Copy an existing particle

Parameters:
toCopy -
Method Detail

getTranslationAmt

public E3DVector3F getTranslationAmt(double lastFrameTimeSeconds)
Return the translation vector that will be used to translate the particle this frame with a lastFrameUpdateTime of lastFrameTimeSeconds

Returns:

update

public boolean update(E3DActor curActor,
                      double lastFrameTimeSeconds)
Update the particle - move in direction at the velocity speed. Also apply the gravity vector if its not null. This is an engine speed based movement, so it should move at a constant speed no matter how fast or slow the engine is currently running.

Overrides:
update in class E3DSprite
Parameters:
lastFrameTimeSeconds - Pass in the last engine's frame time to use as a scalar for the movement velocity of hte particle (so its the same speed on fast or slow systems Returns false if it needs to be removed from the particlesystem (its dead)
Returns:
Returns false if the sprite should be removed from the engine lookAtActor is ignored and only used for classes that extend this

isAlive

public boolean isAlive()

render

public void render()
Render a single particle. This is handled by the engine but available here for debuggin

Overrides:
render in class E3DSprite

getLife

public double getLife()
Get how many seconds the particle will live after the start delay of the life cycle has expired.

Returns:

setLife

public void setLife(double life)
Set how many seconds the particle will live. This time begins after the start delay of a life cycle has expired.

Parameters:
life -

getVelocity

public double getVelocity()
Get the velocity of the particle.

Returns:

setVelocity

public void setVelocity(double velocity)
Set the velocity the particle travels at. This gets scaled by the speed the engine is running automatically

Parameters:
velocity -

getLoops

public int getLoops()
Get number of loops the particle lives. -1 is infinity

Returns:

setLoops

public void setLoops(int loops)
Set number of loops the particle lives. -1 is infinity

Returns:

getStartPosition

public E3DVector3F getStartPosition()
The position the particle starts at the beginning of a loop

Returns:

setStartPosition

public void setStartPosition(E3DVector3F startPosition)
Set the position the particle starts at the beginning of a loop

Parameters:
startPosition -

getEndAlpha

public double getEndAlpha()
Get the alpha the particle is at when its at the end of its loops (between 0 and 1)

Returns:
Value between 0 and 1, 1 being opaque TODO: Implement alpha. This is currently not supported in particles

setEndAlpha

public void setEndAlpha(double endAlpha)
Set the alpha the particle is at when its at the end of its loops (between 0 and 1)


getStartAlpha

public double getStartAlpha()
Get the alpha the particle starts with (between 0 and 1)

Returns:
Value between 0 and 1, 1 being opaque TODO: Implement alpha. This is currently not supported in particles

setStartAlpha

public void setStartAlpha(double startAlpha)
Set the alpha the particle begins at (between 0 and 1)

Parameters:
startAlpha - Value between 0 and 1, 1 being opaque TODO: Implement alpha. This is currently not supported in particles

getStartDelay

public double getStartDelay()
Get the delay the particle waits at the beginning of a loop before it begins moving (Seconds). This only delays for the first loop iteration.

Returns:

setStartDelay

public void setStartDelay(double startDelay)
Set the delay the particle waits at the beginning of a loop before it begins rendering and moving (Seconds). This only delays for the first loop iteration.

Returns:

getParticleSystem

public E3DParticleSystem getParticleSystem()
Get the particlesystem the particle lives in

Returns:

translate

public void translate(E3DVector3F translationVec)
Translate particle geometry and startPosition

Overrides:
translate in class E3DSprite

rotate

public void rotate(double angle,
                   E3DVector3F upVec)
Rotate the the direction the particle faces. This is unnecessary in most cases for a particle since they always billboard. This rotation will be overriden the next frame

Overrides:
rotate in class E3DSprite
Parameters:
angle - Radian angle
upVec - Normalised up vector to use as the rotation axis Calls rotate with permanently set to TRUE

rotateMovementDirection

public void rotateMovementDirection(double angle,
                                    E3DVector3F upVec,
                                    boolean permanently)
Rotate the particle around upVec angle amount. This rotates the movement direction as well as other necessary internal vectors.

Parameters:
angle - Radian angle
upVec - Normalised up vector to use as the rotation axis
permanently - False if the particle should reset to its original movement direction at the end of its life cycle. True if it should retain this orientation for this and the rest of its life cycles

onCollisionActor

public abstract void onCollisionActor(E3DCollision collision)
Intercept collision with actor callbacks

Specified by:
onCollisionActor in interface E3DCollisionDetectableObject
Specified by:
onCollisionActor in class E3DBillboardSprite

onCollisionSprite

public abstract void onCollisionSprite(E3DCollision collision)
Intercept collision with sprite callbacks

Specified by:
onCollisionSprite in interface E3DCollisionDetectableObject
Specified by:
onCollisionSprite in class E3DBillboardSprite

onCollisionDuringUpdate

public abstract boolean onCollisionDuringUpdate(E3DCollision collision)
This callback gets fired when the particle hits something in the world. Actors don't have this callback, but particles do since they're movement is done automatically by the engine

Parameters:
collision -
Returns:
Return true or false. True will make the particle continue with its normal automated movement after a collision, false will stop it from moving during the frames where there is a collision.

onGetClone

public abstract E3DParticle onGetClone()
                                throws java.lang.Exception
Throws:
java.lang.Exception

getCurrentMovementDirection

public E3DVector3F getCurrentMovementDirection()
Get the normalised direction the particle is set to move within this life cycle. This direction resets to startMovementDirection at the end of its life cycle.

Returns:

setCurrentMovementDirection

public void setCurrentMovementDirection(E3DVector3F currentMovementDirection)
Set the direction the particle should move within this life cycle. It will reset to startMovementDirection at the end of the life cycle. This vector will be auto-normalised.

Parameters:
currentMovementDirection -

getStartMovementDirection

public E3DVector3F getStartMovementDirection()
Get the normalised direction the particle should move at the beginning of its life cycle. This will overwrite currentMovementDirection after the end of its life cycle.

Returns:

setStartMovementDirection

public void setStartMovementDirection(E3DVector3F startMovementDirection)
Set the direction the particle should move at the beginning of its life cycles. This will overwrite currentMovementDirection after the end of its life cycle. This vector will be auto-normalised

Parameters:
startMovementDirection -

getCurrentFrameVelocity

public double getCurrentFrameVelocity()
This will always return the scaled velocity the particle was last moved at. Useful in collision detection to figure out when the particle collided with another object

Returns:

isCollisionCausedByMovement

public abstract boolean isCollisionCausedByMovement()
Set this to true if the particle in the system needs to cause collisions when it moves. If set to false, it will not cause any collision callbacks to be hit when it moves. This must also be set to true in the particle's particle system (A false setting in the particle system overrides this setting). This does not automatically make it uncollideable. It just keeps itself from causing collisions with its own movement. Other objects movement can still run into this particle if isCollideable is set to true for the particle and particle system.

Returns: