Added additional convenience constructors to Light, AmbientLight, DirectionalLight, PointLight and SpotLight as mentioned in #297
This commit is contained in:
parent
0869880c8e
commit
e33d2539ed
@ -32,6 +32,7 @@
|
||||
package com.jme3.light;
|
||||
|
||||
import com.jme3.bounding.BoundingBox;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.Camera;
|
||||
import com.jme3.scene.Spatial;
|
||||
@ -49,6 +50,21 @@ import com.jme3.util.TempVars;
|
||||
*/
|
||||
public class AmbientLight extends Light {
|
||||
|
||||
/**
|
||||
* Default constructor for AmbientLight.
|
||||
*/
|
||||
public AmbientLight() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting of the color.
|
||||
*
|
||||
* @param color the color to apply to this light.
|
||||
*/
|
||||
public AmbientLight(final ColorRGBA color) {
|
||||
super(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean intersectsBox(BoundingBox box, TempVars vars) {
|
||||
return true;
|
||||
|
@ -36,6 +36,7 @@ import com.jme3.export.InputCapsule;
|
||||
import com.jme3.export.JmeExporter;
|
||||
import com.jme3.export.JmeImporter;
|
||||
import com.jme3.export.OutputCapsule;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.renderer.Camera;
|
||||
import com.jme3.scene.Spatial;
|
||||
@ -53,6 +54,32 @@ public class DirectionalLight extends Light {
|
||||
|
||||
protected Vector3f direction = new Vector3f(0f, -1f, 0f);
|
||||
|
||||
/**
|
||||
* Default constructor for DirectionalLight. Direction will be defaulted to -1 on the Y axis.
|
||||
*/
|
||||
public DirectionalLight() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting of the direction.
|
||||
*
|
||||
* @param direction the direction vector for the light.
|
||||
*/
|
||||
public DirectionalLight(final Vector3f direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting of the color and direction.
|
||||
*
|
||||
* @param color the color to apply to this light.
|
||||
* @param direction the direction vector for the light.
|
||||
*/
|
||||
public DirectionalLight(final ColorRGBA color, final Vector3f direction) {
|
||||
super(color);
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeLastDistance(Spatial owner) {
|
||||
lastDistance = 0; // directional lights are always closest to their owner
|
||||
|
@ -115,6 +115,22 @@ public abstract class Light implements Savable, Cloneable {
|
||||
boolean frustumCheckNeeded = true;
|
||||
boolean intersectsFrustum = false;
|
||||
|
||||
/**
|
||||
* Default constructor for Light.
|
||||
*/
|
||||
public Light() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting of the color.
|
||||
*
|
||||
* @param color the color to apply to this light.
|
||||
*/
|
||||
public Light(final ColorRGBA color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color of the light.
|
||||
*
|
||||
|
@ -38,6 +38,7 @@ import com.jme3.export.InputCapsule;
|
||||
import com.jme3.export.JmeExporter;
|
||||
import com.jme3.export.JmeImporter;
|
||||
import com.jme3.export.OutputCapsule;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Plane;
|
||||
import com.jme3.math.Vector3f;
|
||||
@ -62,6 +63,41 @@ public class PointLight extends Light {
|
||||
protected float radius = 0;
|
||||
protected float invRadius = 0;
|
||||
|
||||
/**
|
||||
* Default constructor for PointLight.
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>Position will be defaulted to 0,0,0.</li>
|
||||
* <li>Radius will be defaulted to 0</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
public PointLight() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting of the color and position.
|
||||
*
|
||||
* @param color the color to apply to this light.
|
||||
* @param position the position of the light.
|
||||
*/
|
||||
public PointLight(final ColorRGBA color, final Vector3f position) {
|
||||
this(color, position, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting of the color, position and radius.
|
||||
*
|
||||
* @param color the color to apply to this light.
|
||||
* @param position the position of the light.
|
||||
* @param radius the radius of the light.
|
||||
*/
|
||||
public PointLight(final ColorRGBA color, final Vector3f position, final float radius) {
|
||||
super(color);
|
||||
this.position = position;
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void computeLastDistance(Spatial owner) {
|
||||
if (owner.getWorldBound() != null) {
|
||||
|
@ -34,6 +34,7 @@ package com.jme3.light;
|
||||
import com.jme3.bounding.BoundingBox;
|
||||
import com.jme3.bounding.BoundingVolume;
|
||||
import com.jme3.export.*;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Plane;
|
||||
import com.jme3.math.Vector3f;
|
||||
@ -51,8 +52,8 @@ import java.io.IOException;
|
||||
* can be used to attenuate the influence of the light depending on the
|
||||
* distance between the light and the effected 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 determin 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 inner angle determine the cone of light where light has full influence.
|
||||
* the spot outer angle determine the cone global cone of light of the spot light.
|
||||
* the light intensity slowly decrease between the inner cone and the outer cone.
|
||||
* @author Nehon
|
||||
*/
|
||||
@ -64,16 +65,48 @@ public class SpotLight extends Light {
|
||||
protected float spotOuterAngle = FastMath.QUARTER_PI / 6;
|
||||
protected float spotRange = 100;
|
||||
protected float invSpotRange = 1f / 100;
|
||||
protected float packedAngleCos=0;
|
||||
protected float packedAngleCos = 0;
|
||||
|
||||
protected float outerAngleCosSqr, outerAngleSinSqr;
|
||||
protected float outerAngleSinRcp, outerAngleSin, outerAngleCos;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor for SpotLight.
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>Position will be defaulted to 0,0,0</li>
|
||||
* <li>Direction will be defaulted to -1 on the Y axis</li>
|
||||
* <li>Range will be defaulted to 100</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
*/
|
||||
public SpotLight() {
|
||||
super();
|
||||
computeAngleParameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which allows setting color, position, direction, inner angle, outer angle and range.
|
||||
*
|
||||
* @param color the color of the spotlight.
|
||||
* @param position the position of the spotlight.
|
||||
* @param direction the direction of the spotlight.
|
||||
* @param spotInnerAngle the inner angle of the spotlight.
|
||||
* @param spotOuterAngle the outer angle of the spotlight.
|
||||
* @param spotRange the range of the spotlight.
|
||||
*/
|
||||
public SpotLight(final ColorRGBA color, final Vector3f position, final Vector3f direction, final float spotInnerAngle,
|
||||
final float spotOuterAngle, final float spotRange)
|
||||
{
|
||||
super(color);
|
||||
this.position = position;
|
||||
this.direction = direction;
|
||||
this.spotInnerAngle = spotInnerAngle;
|
||||
this.spotOuterAngle = spotOuterAngle;
|
||||
this.spotRange = spotRange;
|
||||
computeAngleParameters();
|
||||
}
|
||||
|
||||
private void computeAngleParameters() {
|
||||
float innerCos = FastMath.cos(spotInnerAngle);
|
||||
outerAngleCos = FastMath.cos(spotOuterAngle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user