public class SpotLight extends Light
In addition to a position and a direction, spot lights 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 of light where light has full influence. the spot outer angle determines the cone global cone of light of the spot light. the light intensity slowly decreases between the inner cone and the outer cone.
Light.Type
Modifier and Type | Field and Description |
---|---|
protected Vector3f |
direction |
protected float |
invSpotRange |
protected float |
outerAngleCos |
protected float |
outerAngleCosSqr |
protected float |
outerAngleSin |
protected float |
outerAngleSinRcp |
protected float |
outerAngleSinSqr |
protected float |
packedAngleCos |
protected Vector3f |
position |
protected float |
spotInnerAngle |
protected float |
spotOuterAngle |
protected float |
spotRange |
color, enabled, lastDistance, name
Constructor and Description |
---|
SpotLight()
Creates a SpotLight.
|
SpotLight(Vector3f position,
Vector3f direction)
Creates a SpotLight at the given position and with the given direction.
|
SpotLight(Vector3f position,
Vector3f direction,
ColorRGBA color)
Creates a SpotLight at the given position, with the given direction and
the given color.
|
SpotLight(Vector3f position,
Vector3f direction,
float range)
Creates a SpotLight at the given position, with the given direction, and the
given range.
|
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.
|
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)
|
Modifier and Type | Method and Description |
---|---|
SpotLight |
clone() |
protected void |
computeLastDistance(Spatial owner)
Used internally to compute the last distance value.
|
Vector3f |
getDirection() |
float |
getInvSpotRange()
for internal use only
|
float |
getPackedAngleCos()
for internal use only
|
Vector3f |
getPosition() |
float |
getSpotInnerAngle()
returns the spot inner angle
|
float |
getSpotOuterAngle()
returns the spot outer angle
|
float |
getSpotRange() |
Light.Type |
getType()
Returns the light type
|
boolean |
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) |
void |
setDirection(Vector3f direction) |
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) |
getColor, getName, isEnabled, isFrustumCheckNeeded, isIntersectsFrustum, setColor, setEnabled, setFrustumCheckNeeded, setIntersectsFrustum, setName
protected Vector3f position
protected Vector3f direction
protected float spotInnerAngle
protected float spotOuterAngle
protected float spotRange
protected float invSpotRange
protected float packedAngleCos
protected float outerAngleCosSqr
protected float outerAngleSinSqr
protected float outerAngleSinRcp
protected float outerAngleSin
protected float outerAngleCos
public SpotLight()
public SpotLight(Vector3f position, Vector3f direction)
position
- the position in world space.direction
- the direction of the light.public SpotLight(Vector3f position, Vector3f direction, float range)
position
- the position in world space.direction
- the direction of the light.range
- the spot light rangepublic SpotLight(Vector3f position, Vector3f direction, ColorRGBA color)
position
- the position in world space.direction
- the direction of the light.color
- the light's color.public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color)
position
- the position in world space.direction
- the direction of the light.range
- the spot light rangecolor
- the light's color.public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color, float innerAngle, float outerAngle)
position
- the position in world space.direction
- the direction of the light.range
- the spot light rangecolor
- the light's color.innerAngle
- the inner angle of the spot light.outerAngle
- the outer angle of the spot light.setSpotInnerAngle(float)
,
setSpotOuterAngle(float)
public boolean intersectsBox(BoundingBox box, TempVars vars)
Light
For non-local lights, such as directional lights
,
ambient lights
, or point lights
without influence radius, this method should always return true.
intersectsBox
in class Light
box
- The box to check intersection against.vars
- TempVars in case it is needed.public boolean intersectsSphere(BoundingSphere sphere, TempVars vars)
Light
For non-local lights, such as directional lights
,
ambient lights
, or point lights
without influence radius, this method should always return true.
intersectsSphere
in class Light
sphere
- The sphere to check intersection against.vars
- TempVars in case it is needed.public boolean intersectsFrustum(Camera cam, TempVars vars)
Light
directional lights
,
ambient lights
, or point lights
without influence radius, this method should always return true.intersectsFrustum
in class Light
cam
- The camera frustum to check intersection against.vars
- TempVars in case it is needed.protected void computeLastDistance(Spatial owner)
Light
computeLastDistance
in class Light
public Light.Type getType()
Light
getType
in class Light
Light.Type
public Vector3f getDirection()
public final void setDirection(Vector3f direction)
public Vector3f getPosition()
public final void setPosition(Vector3f position)
public float getSpotRange()
public void setSpotRange(float spotRange)
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.
spotRange
- the range of the light influence.java.lang.IllegalArgumentException
- If spotRange is negativepublic float getInvSpotRange()
public float getSpotInnerAngle()
public void setSpotInnerAngle(float spotInnerAngle)
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.
spotInnerAngle
- public float getSpotOuterAngle()
public void setSpotOuterAngle(float spotOuterAngle)
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.
spotOuterAngle
- public float getPackedAngleCos()
public void write(JmeExporter ex) throws java.io.IOException
public void read(JmeImporter im) throws java.io.IOException