Class SpotLight
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.jme3.light.Light
Light.Type
-
Field Summary
Modifier and TypeFieldDescriptionprotected Vector3f
protected float
protected float
protected float
protected float
protected float
protected float
protected float
protected Vector3f
protected float
protected float
protected float
Fields inherited from class com.jme3.light.Light
color, enabled, lastDistance, name
-
Constructor Summary
ConstructorDescriptionCreates a SpotLight.Creates a SpotLight at the given position and with the given direction.Creates a SpotLight at the given position, with the given direction, and the given range.Creates a SpotLight at the given position, with the given direction, the given range and the given color.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)Creates a SpotLight at the given position, with the given direction and the given color. -
Method Summary
Modifier and TypeMethodDescriptionclone()
protected void
computeLastDistance
(Spatial owner) Used internally to compute the last distance value.float
for internal use onlyfloat
for internal use onlyfloat
returns the spot inner anglefloat
returns the spot outer anglefloat
getType()
Returns the light typeboolean
intersectsBox
(BoundingBox box, TempVars vars) Determines if the light intersects with the given bounding box.boolean
intersectsFrustum
(Camera cam, TempVars vars) Determines if the light intersects with the given camera frustum.boolean
intersectsSphere
(BoundingSphere sphere, TempVars vars) Determines if the light intersects with the given bounding sphere.void
read
(JmeImporter im) final void
setDirection
(Vector3f direction) final void
setPosition
(Vector3f position) void
setSpotInnerAngle
(float spotInnerAngle) Sets the inner angle of the cone of influence.void
setSpotOuterAngle
(float spotOuterAngle) Sets the outer angle of the cone of influence.void
setSpotRange
(float spotRange) Set the range of the light influence.void
write
(JmeExporter ex) Methods inherited from class com.jme3.light.Light
getColor, getName, isEnabled, isFrustumCheckNeeded, isIntersectsFrustum, setColor, setEnabled, setFrustumCheckNeeded, setIntersectsFrustum, setName
-
Field Details
-
position
-
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
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
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
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
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 rangecolor
- 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 rangecolor
- the light's color.innerAngle
- the inner angle of the spotlight.outerAngle
- the outer angle of the spotlight.- See Also:
-
-
Method Details
-
intersectsBox
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
, orpoint lights
without influence radius, this method should always return true.- Specified by:
intersectsBox
in classLight
- 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
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
, orpoint lights
without influence radius, this method should always return true.- Specified by:
intersectsSphere
in classLight
- 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
Description copied from class:Light
Determines if the light intersects with the given camera frustum. For non-local lights, such asdirectional lights
,ambient lights
, orpoint lights
without influence radius, this method should always return true.- Specified by:
intersectsFrustum
in classLight
- 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
Description copied from class:Light
Used internally to compute the last distance value.- Specified by:
computeLastDistance
in classLight
- Parameters:
owner
- the Spatial whose distance is to be determined
-
getType
Description copied from class:Light
Returns the light type -
getDirection
-
setDirection
-
getPosition
-
setPosition
-
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
- Specified by:
write
in interfaceSavable
- Overrides:
write
in classLight
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Overrides:
read
in classLight
- Throws:
IOException
-
clone
-