Class GeneralLight

java.lang.Object
gov.nih.mipav.view.renderer.J3D.GeneralLight

public class GeneralLight extends Object
This class maintains an instance of a SoftwareLight and a (Java3D) Light where these instances are of the same type:

- ambient (SoftwareLightAmbient, AmbientLight) - directional (SoftwareLightDirectional, DirectionalLight) - point (SoftwareLightPoint, PointLight) - spot (SoftwareLightSpot, SpotLight)

An instance of this class can switch between any of these four types in which case a new pair of SoftwareLight and (Java) Light instances are now referenced. Any changes to light properties are set for both types of lights and any properties which are set which do not apply to a light of a particular type are maintained so that when the light type is switched, the properties can be applied to that light if applicable and any properties of the light being switched from are automatically set for the new type of light.

The following is a list of the properties which can be set:

- enable (on/off) - color (RGB) - intensity (scales color by factor in range [0,1]) - position (normalized to [-1,1] range) - direction (unit length) - target for direction (equal to position + direction) - type

Note that setting the direction or target causes subsequent updates to position to change the target or direction, or vice versa.

When an instance is created, a bit mask is specified which identifies which of the possible types of lights this instances can be switched to. The initial type of light is one of the types for which this instance is enabled starting with ambient, then directional, then point, and then spot.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
    General properties which can be shared by all lights types.
    private boolean
    Properties shared by directional and spot lights.
    private float
    Attenuation factor red channel.
    private float
    Attenuation factor green channel.
    private float
    Attenuation factor blue channel.
    private float
    Light intensity scale factor.
    private float
    Shinness factor, exponential power value for Phong type shading model.
    private final float
    Maximum coordinate scale factor for real positions.
    private final float
    Scale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions.
    private final float
    float Y coordinate scale factor for real positions.
    private final float
    float Y coordinate scale factor for real positions.
    private float
    Properties for spot lights only.
    private float
    Spot light exponential factor.
    private int
    Type of light and limit for available light types which can be selected.
    private final int
    Light type mask.
    private String
    Description associated with this light.
    private javax.vecmath.Vector3f
    Light direction.
    private Color
    Light color.
    private javax.vecmath.Point3f
    Properties shared by point and spot lights.
    private javax.vecmath.Point3f
    Light shooting target position.
    static final int
    All light types mask
    static final int
    Bit mask used to identify light types in combination.
    static final int
    Directional light mask
    static final int
    Point light mask.
    static final int
    Spot light mask.
    private static final String[]
    Light constant types array.
    private static final int
    Ambient light constant.
    private static final int
    Directinal light constant.
    private static final int
    Point light constant.
    private static final int
    Spot light constant.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GeneralLight(int iTypeMask, float fSizeX, float fSizeY, float fSizeZ)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Query if light can be set to the ambient type.
    final boolean
    Query if light can be set to the directional type.
    final boolean
    Query if light can be set to any non-ambient type.
    final boolean
    Query if light can be set to the point type.
    final boolean
    Query if light can be set to the spot type.
    javax.media.j3d.Light
    Access Java3D light instance based on current type.
    final javax.vecmath.Vector3f
    Create an instance which contains the normalized real space coordinates of the direction vector of the (Java3D) Light.
    final javax.vecmath.Point3f
    Create an instance which contains the normalized real space coordinates for the position of the (Java3D) Light.
    createSoftwareLight(javax.vecmath.Point3f kPosition, javax.vecmath.Vector3f kDirection)
    Access software light instance based on current type.
    Access current software light based on type.
    Access current software light based on type.
    WildMagic.LibGraphics.Rendering.Light
    Access Java3D light instance based on current type.
    final void
    enable(boolean bEnable)
    Set whether light is enabled.
    final Color
    Query the current based color of the light.
    final String
    Get description associated with this light.
    final javax.vecmath.Vector3f
    Query the current direction of the light.
    final javax.vecmath.Color3f
    Get the light color scaled with the intensity factor.
    final float
    Query the current light intensity.
    final javax.vecmath.Point3f
    Query the current position of the light.
    final javax.vecmath.Point3f
    Query the current target of the light.
    final String
    Return a string which describes the type of light.
    final boolean
    Query if updates to direction affect the target while keeping the direction fixed.
    final boolean
    Query if light is currently enabled.
    final boolean
    Query if updates to position affect direction while keeping the target fixed.
    boolean
    Query if current light type is ambient.
    final boolean
    Query if current light type is directional.
    final boolean
    Query if current light type is point.
    final boolean
    Query if current light type is spot.
    private float
    normalize(javax.vecmath.Vector3f kV)
    Replace a vector by a unit-length vector in the same direction.
    final void
    setColor(Color kColor)
    Set the base color for the light.
    final void
    setDescription(String description)
    Set description associated with this light.
    final void
    setDirection(float fX, float fY, float fZ)
    Set the current direction of the light.
    final void
    setDirection(javax.vecmath.Vector3f kDir)
    Set the current direction of the light.
    final void
    setIntensity(float fIntensity)
    Set the intensity of the light which sets the actual color of the light to this factor times the base color of the light.
    final void
    setPosition(float fX, float fY, float fZ)
    Set the current position of the light.
    final void
    setPosition(javax.vecmath.Point3f kPosition)
    Set the current position of the light.
    final void
    setTarget(float fX, float fY, float fZ)
    Set the current target of the light.
    final void
    setTarget(javax.vecmath.Point3f kPosition)
    Set the current target of the light.
    final void
    Set the current light type to ambient.
    final void
    Set the current light type to directional.
    final void
    Set the current light type to point.
    final void
    Set the current light type to spot.
    private void
    updateDirection(float fX, float fY, float fZ)
    Set the current direction of the light.
    private void
    updateTarget(float fX, float fY, float fZ)
    Set the current target of the light.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TYPE_AMBIENT

      private static final int TYPE_AMBIENT
      Ambient light constant.
      See Also:
    • TYPE_SPOT

      private static final int TYPE_SPOT
      Spot light constant.
      See Also:
    • TYPE_POINT

      private static final int TYPE_POINT
      Point light constant.
      See Also:
    • TYPE_DIRECTIONAL

      private static final int TYPE_DIRECTIONAL
      Directinal light constant.
      See Also:
    • sakTypeName

      private static final String[] sakTypeName
      Light constant types array.
    • MASK_AMBIENT

      public static final int MASK_AMBIENT
      Bit mask used to identify light types in combination.
      See Also:
    • MASK_SPOT

      public static final int MASK_SPOT
      Spot light mask.
      See Also:
    • MASK_POINT

      public static final int MASK_POINT
      Point light mask.
      See Also:
    • MASK_DIRECTIONAL

      public static final int MASK_DIRECTIONAL
      Directional light mask
      See Also:
    • MASK_ALL

      public static final int MASK_ALL
      All light types mask
      See Also:
    • m_bEnabled

      private boolean m_bEnabled
      General properties which can be shared by all lights types.
    • m_bFixTarget

      private boolean m_bFixTarget
      Properties shared by directional and spot lights. If this flag is true, then updates to position change the direction based on the current target. Otherwise, updates to position change the target based on the current direction. This flag is changed when the target or direction are explicitly set.
    • m_fAttenuationC0

      private float m_fAttenuationC0
      Attenuation factor red channel.
    • m_fAttenuationC1

      private float m_fAttenuationC1
      Attenuation factor green channel.
    • m_fAttenuationC2

      private float m_fAttenuationC2
      Attenuation factor blue channel.
    • m_fIntensity

      private float m_fIntensity
      Light intensity scale factor.
    • m_fShininess

      private float m_fShininess
      Shinness factor, exponential power value for Phong type shading model.
    • m_fSizeMax

      private final float m_fSizeMax
      Maximum coordinate scale factor for real positions.
    • m_fSizeX

      private final float m_fSizeX
      Scale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions.
    • m_fSizeY

      private final float m_fSizeY
      float Y coordinate scale factor for real positions.
    • m_fSizeZ

      private final float m_fSizeZ
      float Y coordinate scale factor for real positions.
    • m_fSpotAngle

      private float m_fSpotAngle
      Properties for spot lights only.
    • m_fSpotExponent

      private float m_fSpotExponent
      Spot light exponential factor.
    • m_iType

      private int m_iType
      Type of light and limit for available light types which can be selected.
    • m_iTypeMask

      private final int m_iTypeMask
      Light type mask.
    • m_kDescription

      private String m_kDescription
      Description associated with this light.
    • m_kDirection

      private javax.vecmath.Vector3f m_kDirection
      Light direction.
    • m_kLightColor

      private Color m_kLightColor
      Light color.
    • m_kPosition

      private javax.vecmath.Point3f m_kPosition
      Properties shared by point and spot lights.
    • m_kTarget

      private javax.vecmath.Point3f m_kTarget
      Light shooting target position.
  • Constructor Details

    • GeneralLight

      public GeneralLight(int iTypeMask, float fSizeX, float fSizeY, float fSizeZ)
      Constructor. Note that the scale factors may be negative.
      Parameters:
      iTypeMask - int Bit mask which limits the types of lights which can be selected for this instance.
      fSizeX - float X coordinate scale factor for real positions.
      fSizeY - float Y coordinate scale factor for real positions.
      fSizeZ - float Z coordinate scale factor for real positions. after normalizations.
  • Method Details

    • canSetTypeAmbient

      public final boolean canSetTypeAmbient()
      Query if light can be set to the ambient type.
      Returns:
      boolean True if light type can be set to ambient.
    • canSetTypeDirectional

      public final boolean canSetTypeDirectional()
      Query if light can be set to the directional type.
      Returns:
      boolean True if light type can be set to directional.
    • canSetTypeNonAmbient

      public final boolean canSetTypeNonAmbient()
      Query if light can be set to any non-ambient type.
      Returns:
      boolean True if light type can be set to any non-ambient type.
    • canSetTypePoint

      public final boolean canSetTypePoint()
      Query if light can be set to the point type.
      Returns:
      boolean True if light type can be set to point.
    • canSetTypeSpot

      public final boolean canSetTypeSpot()
      Query if light can be set to the spot type.
      Returns:
      boolean True if light type can be set to spot.
    • createJava3dLight

      public javax.media.j3d.Light createJava3dLight()
      Access Java3D light instance based on current type.
      Returns:
      Light Java3D light instance based on current type.
    • createWMLight

      public WildMagic.LibGraphics.Rendering.Light createWMLight()
      Access Java3D light instance based on current type.
      Returns:
      Light Java3D light instance based on current type.
    • createJava3dLightDirection

      public final javax.vecmath.Vector3f createJava3dLightDirection()
      Create an instance which contains the normalized real space coordinates of the direction vector of the (Java3D) Light.
      Returns:
      Vector3f New instance created with direction vector.
    • createJava3dLightPosition

      public final javax.vecmath.Point3f createJava3dLightPosition()
      Create an instance which contains the normalized real space coordinates for the position of the (Java3D) Light.
      Returns:
      Point3f New instance created with the position.
    • createSoftwareLightModel

      public final SoftwareLight createSoftwareLightModel()
      Access current software light based on type. Coordinates and direction are appropriate for software rendering for a light located in the "model" space of the objects being rendered.
      Returns:
      SoftwareLight Software light instance based on current type.
    • createSoftwareLightWorld

      public final SoftwareLight createSoftwareLightWorld()
      Access current software light based on type. Coordinates and direction are appropriate for software rendering for a light located in the "world" relative to objects being rendered.
      Returns:
      SoftwareLight Software light instance based on current type.
    • enable

      public final void enable(boolean bEnable)
      Set whether light is enabled.
      Parameters:
      bEnable - boolean True if light is to be enabled.
    • getColor

      public final Color getColor()
      Query the current based color of the light.
      Returns:
      Color Base color of the light.
    • getDescription

      public final String getDescription()
      Get description associated with this light.
      Returns:
      String Text description for light.
    • getDirection

      public final javax.vecmath.Vector3f getDirection()
      Query the current direction of the light.
      Returns:
      Vector3f Normalized direction vector for the light.
    • getIntensifiedColor

      public final javax.vecmath.Color3f getIntensifiedColor()
      Get the light color scaled with the intensity factor.
      Returns:
      Light color!
    • getIntensity

      public final float getIntensity()
      Query the current light intensity.
      Returns:
      float Light color scale factor in range [0,1].
    • getPosition

      public final javax.vecmath.Point3f getPosition()
      Query the current position of the light.
      Returns:
      Point3f Position of the light where the coordinates are normalized to the [-1,+1] range.
    • getTarget

      public final javax.vecmath.Point3f getTarget()
      Query the current target of the light.
      Returns:
      Point3f Target position of the light where the coordinates are normalized to the [-1,+1] range.
    • getTypeString

      public final String getTypeString()
      Return a string which describes the type of light.
      Returns:
      String
    • isDirectionFixed

      public final boolean isDirectionFixed()
      Query if updates to direction affect the target while keeping the direction fixed.
      Returns:
      boolean True if the direction is to remain fixed.
    • isEnabled

      public final boolean isEnabled()
      Query if light is currently enabled.
      Returns:
      boolean True if light is currently enabled.
    • isTargetFixed

      public final boolean isTargetFixed()
      Query if updates to position affect direction while keeping the target fixed.
      Returns:
      boolean True if the target is to remain fixed.
    • isTypeAmbient

      public boolean isTypeAmbient()
      Query if current light type is ambient.
      Returns:
      boolean True if current light type is ambient.
    • isTypeDirectional

      public final boolean isTypeDirectional()
      Query if current light type is directional.
      Returns:
      boolean True if current light type is directional.
    • isTypePoint

      public final boolean isTypePoint()
      Query if current light type is point.
      Returns:
      boolean True if current light type is point.
    • isTypeSpot

      public final boolean isTypeSpot()
      Query if current light type is spot.
      Returns:
      boolean True if current light type is spot.
    • setColor

      public final void setColor(Color kColor)
      Set the base color for the light. Actual color of light is the base color multiplied by the light intensity.
      Parameters:
      kColor - Color Base color for the light.
    • setDescription

      public final void setDescription(String description)
      Set description associated with this light.
      Parameters:
      description - String Text description for light.
    • setDirection

      public final void setDirection(javax.vecmath.Vector3f kDir)
      Set the current direction of the light.
      Parameters:
      kDir - Vector3f Normalized direction vector for the light.
    • setDirection

      public final void setDirection(float fX, float fY, float fZ)
      Set the current direction of the light.
      Parameters:
      fX - float X coordinate of light direction vector.
      fY - float Y coordinate of light direction vector.
      fZ - float Z coordinate of light direction vector.
    • setIntensity

      public final void setIntensity(float fIntensity)
      Set the intensity of the light which sets the actual color of the light to this factor times the base color of the light.
      Parameters:
      fIntensity - float Normalized light color scale factor in range [0,1].
    • setPosition

      public final void setPosition(javax.vecmath.Point3f kPosition)
      Set the current position of the light.
      Parameters:
      kPosition - Point3f Position of light where the coordinates are normalized to the [-1,+1] range.
    • setPosition

      public final void setPosition(float fX, float fY, float fZ)
      Set the current position of the light.
      Parameters:
      fX - float X coordinate position of light in [-1,+1] range.
      fY - float Y coordinate position of light in [-1,+1] range.
      fZ - float Z coordinate position of light in [-1,+1] range.
    • setTarget

      public final void setTarget(javax.vecmath.Point3f kPosition)
      Set the current target of the light.
      Parameters:
      kPosition - Point3f Target position of light where the coordinates are normalized to the [-1,+1] range.
    • setTarget

      public final void setTarget(float fX, float fY, float fZ)
      Set the current target of the light.
      Parameters:
      fX - float X coordinate target position of light in [-1,+1] range.
      fY - float Y coordinate target position of light in [-1,+1] range.
      fZ - float Z coordinate target position of light in [-1,+1] range.
    • setTypeAmbient

      public final void setTypeAmbient()
      Set the current light type to ambient.
    • setTypeDirectional

      public final void setTypeDirectional()
      Set the current light type to directional.
    • setTypePoint

      public final void setTypePoint()
      Set the current light type to point.
    • setTypeSpot

      public final void setTypeSpot()
      Set the current light type to spot.
    • createSoftwareLight

      private SoftwareLight createSoftwareLight(javax.vecmath.Point3f kPosition, javax.vecmath.Vector3f kDirection)
      Access software light instance based on current type.
      Parameters:
      kPosition - Point3f Input position of light.
      kDirection - Vector3f Input (normalized) direction vector of light.
      Returns:
      SoftwareLight Software light instance based on current type.
    • normalize

      private float normalize(javax.vecmath.Vector3f kV)
      Replace a vector by a unit-length vector in the same direction. If the input vector is (nearly) the zero vector, the replacement vector is the zero vector.
      Parameters:
      kV - the vector to be normalized
      Returns:
      the length of the input vector
    • updateDirection

      private void updateDirection(float fX, float fY, float fZ)
      Set the current direction of the light.
      Parameters:
      fX - float X coordinate of light direction vector.
      fY - float Y coordinate of light direction vector.
      fZ - float Z coordinate of light direction vector.
    • updateTarget

      private void updateTarget(float fX, float fY, float fZ)
      Set the current target of the light.
      Parameters:
      fX - float X coordinate target position of light in [-1,+1] range.
      fY - float Y coordinate target position of light in [-1,+1] range.
      fZ - float Z coordinate target position of light in [-1,+1] range.