Class Light

  • All Implemented Interfaces:
    java.io.Serializable, StreamInterface

    public class Light
    extends GraphicsObject
    implements StreamInterface, java.io.Serializable
    If the Light class were to have no data, or just ambient color and intensity, you could use a standard class hierarchy: class Light [ambient, intensity] class AmbientLight : public Light [no additional data] class DirectionalLight : public Light [direction, diffuse, specular] class PointLight : public Light [position, diffuse, specular, attenuation] class SpotLight : public PointLight [cone axis, cone angle, spot exponent] The renderer holds onto lights via the base class Light. The consequences of a standard class hierarchy are that the renderer must use dynamic casting to determine the type of a light in order to set shader program constants in the Renderer::SetConstantLightFOOBAR calls. This is an expense I wish to avoid. An alternative is to allow Light to store all the data in public scope, but to derive the specific light classes using a protected Light base class. Thus, Renderer has access to all the data it needs without having to dynamically cast and the derived-class objects have functions to access only the data relevant to them. Unfortunately, you run into problems with access rights to Object items (such as increment and decrement of reference counts for smart pointers). In the end, I chose to make the Light class a generic class that stores everything needed by the various light types.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Light.LightType
      Light types.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      ColorRGB Ambient
      The Ambient color of the light. default: ColorRGB(0,0,0)
      float Angle
      Parameters for spot lights.
      float Constant
      Attenuation is typically specified as a modulator m = 1/(C + L*d + Q*d*d) where C is the constant coefficient, L is the linear coefficient, Q is the quadratic coefficient, and d is the distance from the light position to the vertex position.
      float CosAngle  
      ColorRGB Diffuse
      The Diffuse color of the light. default: ColorRGB(0,0,0)
      Vector3f DVector  
      float Exponent  
      float Intensity  
      float Linear  
      boolean On
      Turn the light on or off
      Vector3f Position
      Although the standard directional and spot lights need only a direction vector, to allow for new types of derived-class lights that would use a full coordinate frame, Light provides storage for such a frame.
      float Quadratic  
      Vector3f RVector  
      private static long serialVersionUID  
      float SinAngle  
      ColorRGB Specular
      The Specular color of the light. default: ColorRGB(0,0,0)
      Light.LightType Type
      Type default: LT_AMBIENT
      Vector3f UVector  
    • Constructor Summary

      Constructors 
      Constructor Description
      Light()
      Default light constructor, type defaults to ambient light.
      Light​(Light kLight)
      Copy constructor
      Light​(Light.LightType eType)
      Light constructor, creates a light of the given type.
    • Field Detail

      • On

        public boolean On
        Turn the light on or off
      • Ambient

        public ColorRGB Ambient
        The Ambient color of the light. default: ColorRGB(0,0,0)
      • Diffuse

        public ColorRGB Diffuse
        The Diffuse color of the light. default: ColorRGB(0,0,0)
      • Specular

        public ColorRGB Specular
        The Specular color of the light. default: ColorRGB(0,0,0)
      • Constant

        public float Constant
        Attenuation is typically specified as a modulator m = 1/(C + L*d + Q*d*d) where C is the constant coefficient, L is the linear coefficient, Q is the quadratic coefficient, and d is the distance from the light position to the vertex position. To allow for a linear adjustment of intensity, my choice is to use instead m = I/(C + L*d + Q*d*d) where I is an "intensity" factor.
      • Linear

        public float Linear
      • Quadratic

        public float Quadratic
      • Intensity

        public float Intensity
      • Angle

        public float Angle
        Parameters for spot lights. The cone angle must be in radians and should satisfy 0
        • CosAngle

          public float CosAngle
        • SinAngle

          public float SinAngle
        • Exponent

          public float Exponent
        • Position

          public Vector3f Position
          Although the standard directional and spot lights need only a direction vector, to allow for new types of derived-class lights that would use a full coordinate frame, Light provides storage for such a frame. The light frame is always in world coordinates. default position P = (0,0,0) default direction D = (0,0,-1) default up U = (0,1,0) default right R = (1,0,0) The set {D,U,R} must be a right-handed orthonormal set. That is, each vector is unit length, the vectors are mutually perpendicular, and R = Cross(D,U).
        • Constructor Detail

          • Light

            public Light()
            Default light constructor, type defaults to ambient light.
          • Light

            public Light​(Light.LightType eType)
            Light constructor, creates a light of the given type.
            Parameters:
            eType - type of light to create.
          • Light

            public Light​(Light kLight)
            Copy constructor
        • Method Detail

          • GetDiskUsed

            public int GetDiskUsed​(StreamVersion rkVersion)
            Returns the size of this object and it's children on disk for the current StreamVersion parameter.
            Specified by:
            GetDiskUsed in interface StreamInterface
            Overrides:
            GetDiskUsed in class GraphicsObject
            Parameters:
            rkVersion - the current version of the Stream file being created.
            Returns:
            the size of this object on disk.
          • IsValidFrame

            public boolean IsValidFrame()
            This is for debug mode to allow you to check if the coordinate frame vectors form a right-handed orthonormal set.
            Returns:
            true if valid frame.
          • Load

            public void Load​(Stream rkStream,
                             Stream.Link pkLink)
            Loads this object from the input parameter rkStream, using the input Stream.Link to store the IDs of children objects of this object for linking after all objects are loaded from the Stream.
            Specified by:
            Load in interface StreamInterface
            Overrides:
            Load in class GraphicsObject
            Parameters:
            rkStream - the Stream from which this object is being read.
            pkLink - the Link class for storing the IDs of this object's children objects.
          • Save

            public void Save​(Stream rkStream)
            Write this object and all it's children to the Stream.
            Specified by:
            Save in interface StreamInterface
            Overrides:
            Save in class GraphicsObject
            Parameters:
            rkStream - the Stream where the child objects are stored.
          • SaveStrings

            public StringTree SaveStrings​(java.lang.String acTitle)
            Write this object into a StringTree for the scene-graph visualization.
            Specified by:
            SaveStrings in interface StreamInterface
            Overrides:
            SaveStrings in class GraphicsObject
            Parameters:
            acTitle - the header for this object in the StringTree.
            Returns:
            StringTree containing a String-based representation of this object and it's children.
          • SetAngle

            public void SetAngle​(float fAngle)
            A helper function that lets you set Angle and have CosAngle and SinAngle computed for you.
            Parameters:
            fAngle - set the angle value.
          • SetDirection

            public void SetDirection​(Vector3f rkDirection)
            A helper function that lets you set the direction vector and computes the up and right vectors automatically.
            Parameters:
            rkDirection - sets the direction vector.