|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright (c) 2009-2012 jMonkeyEngine |
|
|
|
* Copyright (c) 2009-2012, 2015 jMonkeyEngine |
|
|
|
* All rights reserved. |
|
|
|
* All rights reserved. |
|
|
|
* |
|
|
|
* |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
|
* Redistribution and use in source and binary forms, with or without |
|
|
@ -34,6 +34,7 @@ package com.jme3.light; |
|
|
|
import com.jme3.bounding.BoundingBox; |
|
|
|
import com.jme3.bounding.BoundingBox; |
|
|
|
import com.jme3.bounding.BoundingVolume; |
|
|
|
import com.jme3.bounding.BoundingVolume; |
|
|
|
import com.jme3.export.*; |
|
|
|
import com.jme3.export.*; |
|
|
|
|
|
|
|
import com.jme3.math.ColorRGBA; |
|
|
|
import com.jme3.math.FastMath; |
|
|
|
import com.jme3.math.FastMath; |
|
|
|
import com.jme3.math.Plane; |
|
|
|
import com.jme3.math.Plane; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
|
import com.jme3.math.Vector3f; |
|
|
@ -44,36 +45,121 @@ import java.io.IOException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Represents a spot light. |
|
|
|
* Represents a spot light. |
|
|
|
* A spot light emmit a cone of light from a position and in a direction. |
|
|
|
* A spot light emits a cone of light from a position and in a direction. |
|
|
|
* It can be used to fake torch lights or car's lights. |
|
|
|
* It can be used to fake torch lights or cars' lights. |
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* In addition to a position and a direction, spot lights also have a range which |
|
|
|
* 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 |
|
|
|
* can be used to attenuate the influence of the light depending on the |
|
|
|
* distance between the light and the effected object. |
|
|
|
* 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. |
|
|
|
* Also the angle of the cone can be tweaked by changing the spot inner angle and the spot outer angle. |
|
|
|
* the spot inner angle determin the cone of light where light has full influence. |
|
|
|
* the spot inner angle determines the cone of light where light has full influence. |
|
|
|
* the spot outer angle determin the cone global cone of light of the spot light. |
|
|
|
* the spot outer angle determines the cone global cone of light of the spot light. |
|
|
|
* the light intensity slowly decrease between the inner cone and the outer cone. |
|
|
|
* the light intensity slowly decreases between the inner cone and the outer cone. |
|
|
|
* @author Nehon |
|
|
|
* @author Nehon |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SpotLight extends Light { |
|
|
|
public class SpotLight extends Light { |
|
|
|
|
|
|
|
|
|
|
|
protected Vector3f position = new Vector3f(); |
|
|
|
protected Vector3f position = new Vector3f(); |
|
|
|
protected Vector3f direction = new Vector3f(0,-1,0); |
|
|
|
protected Vector3f direction = new Vector3f(0, -1, 0); |
|
|
|
protected float spotInnerAngle = FastMath.QUARTER_PI / 8; |
|
|
|
protected float spotInnerAngle = FastMath.QUARTER_PI / 8; |
|
|
|
protected float spotOuterAngle = FastMath.QUARTER_PI / 6; |
|
|
|
protected float spotOuterAngle = FastMath.QUARTER_PI / 6; |
|
|
|
protected float spotRange = 100; |
|
|
|
protected float spotRange = 100; |
|
|
|
protected float invSpotRange = 1f / 100; |
|
|
|
protected float invSpotRange = 1f / 100; |
|
|
|
protected float packedAngleCos=0; |
|
|
|
protected float packedAngleCos = 0; |
|
|
|
|
|
|
|
|
|
|
|
protected float outerAngleCosSqr, outerAngleSinSqr; |
|
|
|
protected float outerAngleCosSqr, outerAngleSinSqr; |
|
|
|
protected float outerAngleSinRcp, outerAngleSin, outerAngleCos; |
|
|
|
protected float outerAngleSinRcp, outerAngleSin, outerAngleCos; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a SpotLight. |
|
|
|
|
|
|
|
*/ |
|
|
|
public SpotLight() { |
|
|
|
public SpotLight() { |
|
|
|
super(); |
|
|
|
super(); |
|
|
|
computeAngleParameters(); |
|
|
|
computeAngleParameters(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a SpotLight at the given position and with the given direction. |
|
|
|
|
|
|
|
* @param position the position in world space. |
|
|
|
|
|
|
|
* @param direction the direction of the light. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public SpotLight(Vector3f position, Vector3f direction) { |
|
|
|
|
|
|
|
this(); |
|
|
|
|
|
|
|
setPosition(position); |
|
|
|
|
|
|
|
setDirection(direction); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a SpotLight at the given position, with the given direction, and the |
|
|
|
|
|
|
|
* given range. |
|
|
|
|
|
|
|
* @param position the position in world space. |
|
|
|
|
|
|
|
* @param direction the direction of the light. |
|
|
|
|
|
|
|
* @param range the spot light range |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public SpotLight(Vector3f position, Vector3f direction, float range) { |
|
|
|
|
|
|
|
this(); |
|
|
|
|
|
|
|
setPosition(position); |
|
|
|
|
|
|
|
setDirection(direction); |
|
|
|
|
|
|
|
this.spotRange = range; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a SpotLight at the given position, with the given direction and |
|
|
|
|
|
|
|
* the given color. |
|
|
|
|
|
|
|
* @param position the position in world space. |
|
|
|
|
|
|
|
* @param direction the direction of the light. |
|
|
|
|
|
|
|
* @param color the light's color. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public SpotLight(Vector3f position, Vector3f direction, ColorRGBA color) { |
|
|
|
|
|
|
|
super(color); |
|
|
|
|
|
|
|
computeAngleParameters(); |
|
|
|
|
|
|
|
setPosition(position); |
|
|
|
|
|
|
|
setDirection(direction); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Creates a SpotLight at the given position, with the given direction, |
|
|
|
|
|
|
|
* the given range and the given color. |
|
|
|
|
|
|
|
* @param position the position in world space. |
|
|
|
|
|
|
|
* @param direction the direction of the light. |
|
|
|
|
|
|
|
* @param range the spot light range |
|
|
|
|
|
|
|
* @param color the light's color. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color) { |
|
|
|
|
|
|
|
super(color); |
|
|
|
|
|
|
|
computeAngleParameters(); |
|
|
|
|
|
|
|
setPosition(position); |
|
|
|
|
|
|
|
setDirection(direction); |
|
|
|
|
|
|
|
this.spotRange = range; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 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) |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param position the position in world space. |
|
|
|
|
|
|
|
* @param direction the direction of the light. |
|
|
|
|
|
|
|
* @param range the spot light range |
|
|
|
|
|
|
|
* @param color the light's color. |
|
|
|
|
|
|
|
* @param innerAngle the inner angle of the spot light. |
|
|
|
|
|
|
|
* @param outerAngle the outer angle of the spot light. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @see SpotLight#setSpotInnerAngle(float) |
|
|
|
|
|
|
|
* @see SpotLight#setSpotOuterAngle(float) |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public SpotLight(Vector3f position, Vector3f direction, float range, ColorRGBA color, float innerAngle, float outerAngle) { |
|
|
|
|
|
|
|
super(color); |
|
|
|
|
|
|
|
this.spotInnerAngle = innerAngle; |
|
|
|
|
|
|
|
this.spotOuterAngle = outerAngle; |
|
|
|
|
|
|
|
computeAngleParameters(); |
|
|
|
|
|
|
|
setPosition(position); |
|
|
|
|
|
|
|
setDirection(direction); |
|
|
|
|
|
|
|
this.spotRange = range; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void computeAngleParameters() { |
|
|
|
private void computeAngleParameters() { |
|
|
|
float innerCos = FastMath.cos(spotInnerAngle); |
|
|
|
float innerCos = FastMath.cos(spotInnerAngle); |
|
|
|
outerAngleCos = FastMath.cos(spotOuterAngle); |
|
|
|
outerAngleCos = FastMath.cos(spotOuterAngle); |
|
|
@ -189,7 +275,7 @@ public class SpotLight extends Light { |
|
|
|
return direction; |
|
|
|
return direction; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setDirection(Vector3f direction) { |
|
|
|
public final void setDirection(Vector3f direction) { |
|
|
|
this.direction.set(direction); |
|
|
|
this.direction.set(direction); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -197,7 +283,7 @@ public class SpotLight extends Light { |
|
|
|
return position; |
|
|
|
return position; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setPosition(Vector3f position) { |
|
|
|
public final void setPosition(Vector3f position) { |
|
|
|
this.position.set(position); |
|
|
|
this.position.set(position); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|