yaarq.sys
Class yrqFlareVisual

java.lang.Object
  |
  +--yaarq.sys.yrqVisual
        |
        +--yaarq.sys.yrqFlareVisual

public class yrqFlareVisual
extends yrqVisual

This class extends the yrqVisual class providing support for optical effects like lensflares, glares and receptor overloading. A flare is attached to a frame producing it. It traces the frame automatically .

A flare features a displacement factor. Flares are artifical effects created by the virtual lens system tracking the scene. A flares position is always on a line connecting its source (e.g. the sun) with the screen center. The displacement factor states where on this line the flare is positioned. A displacement factor of 0 means that the flare appears exactly at the location its parenting frame, a factor of one positions the flare statically in the 2D center of the screen while a factor of 2 positions the flare at the 2D location of the parenting frame mirrored by the 2D center of the screen.

A flare normally fades, to some degree, with its distance from the optical center (the 2D screen center) The amount of this fading can be influcenced using the fade factor. A fade factor of 0 means no fading at all, like for the true source of a light (e.g. sun), a fade factor of 1 denotes full fading, resulting in an invisible flare regardless of screen distance.

The flare class uses 2D sprites seemingly positioned exactly on the 2D screen plane. Normally, such operations would be done in the postRender method of the Java3D canvas, but the update routines used by Java3D have very low performance, so this class creates 3D objects and manipulates them to appear as if they were twodimensional and screen- aligned.

FlareVisuals are internally attached to the viewport transform group to allow for automatic viewport alignment.

To match the location of their source object in the world, flares have to be updated constantly. This is done automatically by the engine, which calls the update method of the flares during its time-based updates.

TODO: When allowing fov changes to viewport, change transform code!


Field Summary
 
Fields inherited from class yaarq.sys.yrqVisual
COLOR_AMBIENT, COLOR_DIFFUSE, COLOR_EMISSIVE, COLOR_SPECULAR, m_parent, MODE_ADD, MODE_BLEND, MODE_NONE, TEXTURE_DOT3BUMP, TEXTURE_LIGHTMAP, TEXTURE_MATERIAL, TEXTURE_REFLECT
 
Constructor Summary
yrqFlareVisual(javax.media.j3d.Texture2D a_texture, yrqFrame a_frame, float a_scale, float a_displacement, float a_fadefactor)
          Constructs a new flarevisual using the passed parameters.
 
Method Summary
 void attach(javax.media.j3d.Group a_group)
          This method attaches the flare to a parent.
 void detach()
          This method detaches the flare to a parent.
 float getDisplacement()
          This method retrieves the displacement of the flare.
 float getFadeFactor()
          This method retrieves the fade factor of a flare in relation to its source.
 float getLuminance()
          This function retrieves the overall luminance for the flare.
 javax.vecmath.Point2d getPosition()
          This function retrieves the current location of the flare in screen coordinates.
 yrqFrame getSourceFrame()
          This function returns the source frame for the flare.
 void setDisplacement(float a_displacement)
          This method sets the displacement of a flare in relation to its source.
 void setFadeFactor(float a_fadefactor)
          This method sets the fade factor of a flare in relation to its source.
 void setLuminance(float a_luminance)
          This method sets the overall luminance for the flare.
 void setSourceFrame(yrqFrame a_frame)
          This method sets the source frame for the flare.
 void setTexture(javax.media.j3d.Texture2D a_texture, float a_scale)
          This method sets the texture to use for the overlay.
 void update(yrqEngine a_engine)
          This method updates the flare position in relation to the world position of its source frame.
 
Methods inherited from class yaarq.sys.yrqVisual
getBaseShape3D, getBumpShape3D, getGeometry, getParent, getTexture, getTransparencyMode, getTransparencyValue, setBrightness, setColor, setGeometry, setShininess, setTexture, setTextureAnimation, setTextureAnimation, setTransparency
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

yrqFlareVisual

public yrqFlareVisual(javax.media.j3d.Texture2D a_texture,
                      yrqFrame a_frame,
                      float a_scale,
                      float a_displacement,
                      float a_fadefactor)
Constructs a new flarevisual using the passed parameters.

Parameters:
a_texture - The texture to use for the overlay
a_frame - The frame which prduces the flare
a_displacement - The displacement of the flare from the source
a_fadefactor - The fading alpha factor of the flare
Method Detail

attach

public void attach(javax.media.j3d.Group a_group)
This method attaches the flare to a parent. Overrides the visuals method to take into account the transform needed for aligning the overlay

Overrides:
attach in class yrqVisual
Parameters:
a_group - The group to which to attach

detach

public void detach()
This method detaches the flare to a parent. Overrides the visuals method to take into account the transform needed for aligning the overlay

Overrides:
detach in class yrqVisual

getDisplacement

public float getDisplacement()
This method retrieves the displacement of the flare. The displacement determines where, on a line running through the sources 2D screen position and the 2D screen center, a flare is positioned. A value of 0 places the flare over the source, 1 places the flare at the screen center, 2 places it opposite to the source.

Returns:
The displacement of the flare, range 0-2

getFadeFactor

public float getFadeFactor()
This method retrieves the fade factor of a flare in relation to its source. The fade factor determines how much brightness a flare looses with increasing distance to the screen center, which is the center for the optical effect.

Returns:
a_fadefactor The fade factor of the flare, 0-1

getLuminance

public float getLuminance()
This function retrieves the overall luminance for the flare. Luminance scales all other considerations, like fade factor or distance to lightsource.

Returns:
the luminance to set, 0-1f

getPosition

public javax.vecmath.Point2d getPosition()
This function retrieves the current location of the flare in screen coordinates. The position cannot be set, it is determined by the source frame and the various parameters set to the instance.

Returns:
Coordinates of the flare in pixel

getSourceFrame

public yrqFrame getSourceFrame()
This function returns the source frame for the flare. The position of the frame in world space is used as a starting point for calculation of the optical effect.

Returns:
a_frame The frame which is the source for the flare

setDisplacement

public void setDisplacement(float a_displacement)
This method sets the displacement of a flare in relation to its source. The displacement determines where, on a line running through the sources 2D screen position and the 2D screen center, a flare is positioned. A value of 0 places the flare over the source, 1 places the flare at the screen center, 2 places it opposite to the source.

Parameters:
a_displacement - The displacement for the flare, 0=none, 1=screen center, 2=opposite to source

setFadeFactor

public void setFadeFactor(float a_fadefactor)
This method sets the fade factor of a flare in relation to its source. The fade factor determines how much brightness a flare looses with increasing distance to the screen center, which is the center for the optical effect.

Parameters:
a_fadefactor - The fade factor of the flare, 0-1

setLuminance

public void setLuminance(float a_luminance)
This method sets the overall luminance for the flare. Luminance scales all other considerations, like fade factor or distance to lightsource.

Parameters:
a_luminance - the luminance to set, 0-1f

setSourceFrame

public void setSourceFrame(yrqFrame a_frame)
This method sets the source frame for the flare. The position of the frame in world space is used as a starting point for calculation of the optical effect.

Parameters:
a_frame - The frame which is the source for the flare

setTexture

public void setTexture(javax.media.j3d.Texture2D a_texture,
                       float a_scale)
This method sets the texture to use for the overlay. Internally, an according geometry is created and set to the visual to match the texture.

Parameters:
a_texture - The texture to use for the overlay
a_scale - The scale (screen coords) to apply to the texture

update

public void update(yrqEngine a_engine)
This method updates the flare position in relation to the world position of its source frame. It is called automatically by the engine.

Parameters:
a_engine - The engine updating the flare