Class SpotLight

java.lang.Object
com.jme3.light.Light
com.jme3.light.SpotLight
All Implemented Interfaces:
Savable, Cloneable

public class SpotLight extends Light
Represents a spotlight. A spotlight emits a cone of light from a position and in a direction. It can be used to fake torch lights or car's lights.

In addition to a position and a direction, spotlights also have a range which can be used to attenuate the influence of the light depending on the distance between the light and the affected object. Also, the angle of the cone can be tweaked by changing the spot inner angle and the spot outer angle. The spot inner angle determines the cone where light has full influence. The spot outer angle determines the global cone of light. The light intensity slowly decreases from the inner cone to the outer cone.

  • Field Details

    • position

      protected Vector3f position
    • direction

      protected Vector3f direction
    • spotInnerAngle

      protected float spotInnerAngle
    • spotOuterAngle

      protected float spotOuterAngle
    • spotRange

      protected float spotRange
    • invSpotRange

      protected float invSpotRange
    • packedAngleCos

      protected float packedAngleCos
    • outerAngleCosSqr

      protected float outerAngleCosSqr
    • outerAngleSinSqr

      protected float outerAngleSinSqr
    • outerAngleSinRcp

      protected float outerAngleSinRcp
    • outerAngleSin

      protected float outerAngleSin
    • outerAngleCos

      protected float outerAngleCos
  • Constructor Details

    • SpotLight

      public SpotLight()
      Creates a SpotLight.
    • SpotLight

      public SpotLight(Vector3f position, Vector3f direction)
      Creates a SpotLight at the given position and with the given direction.
      Parameters:
      position - the position in world space.
      direction - the direction of the light.
    • SpotLight

      public SpotLight(Vector3f position, Vector3f direction, float range)
      Creates a SpotLight at the given position, with the given direction, and the given range.
      Parameters:
      position - the position in world space.
      direction - the direction of the light.
      range - the spotlight range
    • SpotLight

      public SpotLight(Vector3f position, Vector3f direction, ColorRGBA color)
      Creates a SpotLight at the given position, with the given direction and the given color.
      Parameters:
      position - the position in world space.
      direction - the direction of the light.
      color - the light's color.
    • SpotLight

      public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color)
      Creates a SpotLight at the given position, with the given direction, the given range and the given color.
      Parameters:
      position - the position in world space.
      direction - the direction of the light.
      range - the spotlight range
      color - the light's color.
    • SpotLight

      public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color, float innerAngle, float outerAngle)
      Creates a SpotLight at the given position, with the given direction, the given color and the given inner and outer angles (controls the falloff of the light)
      Parameters:
      position - the position in world space.
      direction - the direction of the light.
      range - the spotlight range
      color - the light's color.
      innerAngle - the inner angle of the spotlight.
      outerAngle - the outer angle of the spotlight.
      See Also:
  • Method Details

    • intersectsBox

      public boolean intersectsBox(BoundingBox box, TempVars vars)
      Description copied from class: Light
      Determines if the light intersects with the given bounding box.

      For non-local lights, such as directional lights, ambient lights, or point lights without influence radius, this method should always return true.

      Specified by:
      intersectsBox in class Light
      Parameters:
      box - The box to check intersection against.
      vars - TempVars in case it is needed.
      Returns:
      True if the light intersects the box, false otherwise.
    • intersectsSphere

      public boolean intersectsSphere(BoundingSphere sphere, TempVars vars)
      Description copied from class: Light
      Determines if the light intersects with the given bounding sphere.

      For non-local lights, such as directional lights, ambient lights, or point lights without influence radius, this method should always return true.

      Specified by:
      intersectsSphere in class Light
      Parameters:
      sphere - The sphere to check intersection against.
      vars - TempVars in case it is needed.
      Returns:
      True if the light intersects the sphere, false otherwise.
    • intersectsFrustum

      public boolean intersectsFrustum(Camera cam, TempVars vars)
      Description copied from class: Light
      Determines if the light intersects with the given camera frustum. For non-local lights, such as directional lights, ambient lights, or point lights without influence radius, this method should always return true.
      Specified by:
      intersectsFrustum in class Light
      Parameters:
      cam - The camera frustum to check intersection against.
      vars - TempVars in case it is needed.
      Returns:
      True if the light intersects the frustum, false otherwise.
    • computeLastDistance

      protected void computeLastDistance(Spatial owner)
      Description copied from class: Light
      Used internally to compute the last distance value.
      Specified by:
      computeLastDistance in class Light
      Parameters:
      owner - the Spatial whose distance is to be determined
    • getType

      public Light.Type getType()
      Description copied from class: Light
      Returns the light type
      Specified by:
      getType in class Light
      Returns:
      the light type
      See Also:
    • getDirection

      public Vector3f getDirection()
    • setDirection

      public final void setDirection(Vector3f direction)
    • getPosition

      public Vector3f getPosition()
    • setPosition

      public final void setPosition(Vector3f position)
    • getSpotRange

      public float getSpotRange()
    • setSpotRange

      public void setSpotRange(float spotRange)
      Set the range of the light influence.

      Setting a non-zero range indicates the light should use attenuation. If a pixel's distance to this light's position is greater than the light's range, then the pixel will not be affected by this light, if the distance is less than the range, then the magnitude of the influence is equal to distance / range.

      Parameters:
      spotRange - the range of the light influence.
      Throws:
      IllegalArgumentException - If spotRange is negative
    • getInvSpotRange

      public float getInvSpotRange()
      for internal use only
      Returns:
      the inverse of the spot range
    • getSpotInnerAngle

      public float getSpotInnerAngle()
      returns the spot inner angle
      Returns:
      the spot inner angle
    • setSpotInnerAngle

      public void setSpotInnerAngle(float spotInnerAngle)
      Sets the inner angle of the cone of influence.

      Must be between 0 and pi/2.

      This angle is the angle between the spot direction axis and the inner border of the cone of influence.

      Parameters:
      spotInnerAngle - the desired angle (in radians, ≥0, ≤Pi/2)
    • getSpotOuterAngle

      public float getSpotOuterAngle()
      returns the spot outer angle
      Returns:
      the spot outer angle
    • setSpotOuterAngle

      public void setSpotOuterAngle(float spotOuterAngle)
      Sets the outer angle of the cone of influence.

      Must be between 0 and pi/2.

      This angle is the angle between the spot direction axis and the outer border of the cone of influence. this should be greater than the inner angle or the result will be unexpected.

      Parameters:
      spotOuterAngle - the desired angle (in radians, ≥0, ≤Pi/2)
    • getPackedAngleCos

      public float getPackedAngleCos()
      for internal use only
      Returns:
      the cosines of the inner and outer angle packed in a float
    • write

      public void write(JmeExporter ex) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class Light
      Throws:
      IOException
    • read

      public void read(JmeImporter im) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class Light
      Throws:
      IOException
    • clone

      public SpotLight clone()
      Overrides:
      clone in class Light