M3G 1.1 -- Jun 22, 2005

javax.microedition.m3g
Class Fog

java.lang.Object
  extended byjavax.microedition.m3g.Object3D
      extended byjavax.microedition.m3g.Fog

public class Fog
extends Object3D

An Appearance component encapsulating attributes for fogging.

Implementation guidelines

Fogging is done according to the OpenGL 1.3 specification, section 3.10, with the exception that the EXP2 mode is not supported. The same approximations in fog computation are allowed as in OpenGL: Firstly, the fog function may be evaluated at vertices and then interpolated to obtain the per-fragment values, and secondly, the distance from the camera to the fragment center may be approximated with the fragment's Z coordinate.

See Also:
Binary format

Field Summary
static int EXPONENTIAL
          A parameter to setMode, specifying exponential fog.
static int LINEAR
          A parameter to setMode, specifying linear fog.
 
Constructor Summary
Fog()
          Constructs a new Fog object with default values.
 
Method Summary
 int getColor()
          Retrieves the current color of this Fog.
 float getDensity()
          Retrieves the fog density of exponential fog.
 float getFarDistance()
          Retrieves the linear fog far distance.
 int getMode()
          Retrieves the current fog mode.
 float getNearDistance()
          Retrieves the linear fog near distance.
 void setColor(int RGB)
          Sets the color of this Fog.
 void setDensity(float density)
          Sets the fog density for exponential fog.
 void setLinear(float near, float far)
          Sets the near and far distances for linear fog.
 void setMode(int mode)
          Sets the fog mode to either linear or exponential.
 
Methods inherited from class javax.microedition.m3g.Object3D
addAnimationTrack, animate, duplicate, find, getAnimationTrack, getAnimationTrackCount, getReferences, getUserID, getUserObject, removeAnimationTrack, setUserID, setUserObject
   

Field Detail

EXPONENTIAL

public static final int EXPONENTIAL

A parameter to setMode, specifying exponential fog. The fog blending factor f is calculated according to the formula:

where z is the distance, in camera coordinates, from the camera origin to the fragment center, and d is the fog density set in setDensity. The result is clamped to the [0, 1] range.

See Also:
Constant Field Values

LINEAR

public static final int LINEAR

A parameter to setMode, specifying linear fog. The fog blending factor f is calculated according to the formula:

where z is the distance, in camera coordinates, from the camera origin to the fragment center, and near and far are the distances set in setLinear. The result is clamped to the [0, 1] range. If far == near, that is, the far and near distances are equal, the result is undefined.

The smaller the fog blending factor is, the more of the fog color is blended in to the rasterized fragment. The blending factor reaches its minimum at the far plane, and the maximum at the near plane.

See Also:
Constant Field Values
Constructor Detail

Fog

public Fog()

Constructs a new Fog object with default values. The default values are:

Method Detail

setMode

public void setMode(int mode)

Sets the fog mode to either linear or exponential.

Parameters:
mode - the fog mode to set; one of the symbolic constants listed above
Throws:
java.lang.IllegalArgumentException - if mode is not LINEAR or EXPONENTIAL
See Also:
getMode

getMode

public int getMode()

Retrieves the current fog mode.

Returns:
the current fog mode; one of the symbolic constants listed above
See Also:
setMode

setLinear

public void setLinear(float near,
                      float far)

Sets the near and far distances for linear fog. Note that the near distance does not have to be smaller than the far distance, although that is usually the case.

Note that this setting has no effect on rendering unless the type of this Fog is (or is later set to) LINEAR.

Parameters:
near - distance to the linear fog near plane
far - distance to the linear fog far plane

getNearDistance

public float getNearDistance()

Retrieves the linear fog near distance.

Returns:
the current distance to the linear fog near plane
See Also:
setLinear

getFarDistance

public float getFarDistance()

Retrieves the linear fog far distance.

Returns:
the current distance to the linear fog far plane
See Also:
setLinear

setDensity

public void setDensity(float density)

Sets the fog density for exponential fog.

Note that this setting has no effect on rendering unless the type of this Fog is (or is later set to) EXPONENTIAL.

Parameters:
density - the density to set for this Fog
Throws:
java.lang.IllegalArgumentException - if density < 0
See Also:
getDensity

getDensity

public float getDensity()

Retrieves the fog density of exponential fog.

Returns:
the current density of this Fog
See Also:
setDensity

setColor

public void setColor(int RGB)

Sets the color of this Fog. The high order byte of the color value (that is, the alpha component) is ignored.

Parameters:
RGB - the color to set for this Fog in 0x00RRGGBB format
See Also:
getColor

getColor

public int getColor()

Retrieves the current color of this Fog. The high order byte of the color value (that is, the alpha component) is guaranteed to be zero.

Returns:
the current color of this Fog in 0x00RRGGBB format
See Also:
setColor

M3G 1.1 -- Jun 22, 2005

Copyright © 2005 Nokia Corporation. See the Copyright Notice for details.