Class GeneralLight


  • public class GeneralLight
    extends java.lang.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 m_bEnabled
      General properties which can be shared by all lights types.
      private boolean m_bFixTarget
      Properties shared by directional and spot lights.
      private float m_fAttenuationC0
      Attenuation factor red channel.
      private float m_fAttenuationC1
      Attenuation factor green channel.
      private float m_fAttenuationC2
      Attenuation factor blue channel.
      private float m_fIntensity
      Light intensity scale factor.
      private float m_fShininess
      Shinness factor, exponential power value for Phong type shading model.
      private float m_fSizeMax
      Maximum coordinate scale factor for real positions.
      private float m_fSizeX
      Scale factors for placing [-1,+1] normalized positions and targets into real world space with dimensions.
      private float m_fSizeY
      float Y coordinate scale factor for real positions.
      private float m_fSizeZ
      float Y coordinate scale factor for real positions.
      private float m_fSpotAngle
      Properties for spot lights only.
      private float m_fSpotExponent
      Spot light exponential factor.
      private int m_iType
      Type of light and limit for available light types which can be selected.
      private int m_iTypeMask
      Light type mask.
      private java.lang.String m_kDescription
      Description associated with this light.
      private javax.vecmath.Vector3f m_kDirection
      Light direction.
      private java.awt.Color m_kLightColor
      Light color.
      private javax.vecmath.Point3f m_kPosition
      Properties shared by point and spot lights.
      private javax.vecmath.Point3f m_kTarget
      Light shooting target position.
      static int MASK_ALL
      All light types mask
      static int MASK_AMBIENT
      Bit mask used to identify light types in combination.
      static int MASK_DIRECTIONAL
      Directional light mask
      static int MASK_POINT
      Point light mask.
      static int MASK_SPOT
      Spot light mask.
      private static java.lang.String[] sakTypeName
      Light constant types array.
      private static int TYPE_AMBIENT
      Ambient light constant.
      private static int TYPE_DIRECTIONAL
      Directinal light constant.
      private static int TYPE_POINT
      Point light constant.
      private static int TYPE_SPOT
      Spot light constant.
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canSetTypeAmbient()
      Query if light can be set to the ambient type.
      boolean canSetTypeDirectional()
      Query if light can be set to the directional type.
      boolean canSetTypeNonAmbient()
      Query if light can be set to any non-ambient type.
      boolean canSetTypePoint()
      Query if light can be set to the point type.
      boolean canSetTypeSpot()
      Query if light can be set to the spot type.
      javax.media.j3d.Light createJava3dLight()
      Access Java3D light instance based on current type.
      javax.vecmath.Vector3f createJava3dLightDirection()
      Create an instance which contains the normalized real space coordinates of the direction vector of the (Java3D) Light.
      javax.vecmath.Point3f createJava3dLightPosition()
      Create an instance which contains the normalized real space coordinates for the position of the (Java3D) Light.
      private SoftwareLight createSoftwareLight​(javax.vecmath.Point3f kPosition, javax.vecmath.Vector3f kDirection)
      Access software light instance based on current type.
      SoftwareLight createSoftwareLightModel()
      Access current software light based on type.
      SoftwareLight createSoftwareLightWorld()
      Access current software light based on type.
      WildMagic.LibGraphics.Rendering.Light createWMLight()
      Access Java3D light instance based on current type.
      void enable​(boolean bEnable)
      Set whether light is enabled.
      java.awt.Color getColor()
      Query the current based color of the light.
      java.lang.String getDescription()
      Get description associated with this light.
      javax.vecmath.Vector3f getDirection()
      Query the current direction of the light.
      javax.vecmath.Color3f getIntensifiedColor()
      Get the light color scaled with the intensity factor.
      float getIntensity()
      Query the current light intensity.
      javax.vecmath.Point3f getPosition()
      Query the current position of the light.
      javax.vecmath.Point3f getTarget()
      Query the current target of the light.
      java.lang.String getTypeString()
      Return a string which describes the type of light.
      boolean isDirectionFixed()
      Query if updates to direction affect the target while keeping the direction fixed.
      boolean isEnabled()
      Query if light is currently enabled.
      boolean isTargetFixed()
      Query if updates to position affect direction while keeping the target fixed.
      boolean isTypeAmbient()
      Query if current light type is ambient.
      boolean isTypeDirectional()
      Query if current light type is directional.
      boolean isTypePoint()
      Query if current light type is point.
      boolean isTypeSpot()
      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.
      void setColor​(java.awt.Color kColor)
      Set the base color for the light.
      void setDescription​(java.lang.String description)
      Set description associated with this light.
      void setDirection​(float fX, float fY, float fZ)
      Set the current direction of the light.
      void setDirection​(javax.vecmath.Vector3f kDir)
      Set the current direction of the light.
      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.
      void setPosition​(float fX, float fY, float fZ)
      Set the current position of the light.
      void setPosition​(javax.vecmath.Point3f kPosition)
      Set the current position of the light.
      void setTarget​(float fX, float fY, float fZ)
      Set the current target of the light.
      void setTarget​(javax.vecmath.Point3f kPosition)
      Set the current target of the light.
      void setTypeAmbient()
      Set the current light type to ambient.
      void setTypeDirectional()
      Set the current light type to directional.
      void setTypePoint()
      Set the current light type to point.
      void setTypeSpot()
      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 Detail

      • TYPE_AMBIENT

        private static final int TYPE_AMBIENT
        Ambient light constant.
        See Also:
        Constant Field Values
      • TYPE_DIRECTIONAL

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

        private static final java.lang.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:
        Constant Field Values
      • MASK_DIRECTIONAL

        public static final int MASK_DIRECTIONAL
        Directional light mask
        See Also:
        Constant Field Values
      • 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 java.lang.String m_kDescription
        Description associated with this light.
      • m_kDirection

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

        private java.awt.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 Detail

      • 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 Detail

      • 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 java.awt.Color getColor()
        Query the current based color of the light.
        Returns:
        Color Base color of the light.
      • getDescription

        public final java.lang.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 java.lang.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​(java.awt.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​(java.lang.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.