Added some more constructors to SpotLight and PointLight, also added javadoc to all lights constructors.
This commit is contained in:
parent
609d9a1832
commit
168e1755ff
@ -54,13 +54,25 @@ public class DirectionalLight extends Light {
|
|||||||
|
|
||||||
protected Vector3f direction = new Vector3f(0f, -1f, 0f);
|
protected Vector3f direction = new Vector3f(0f, -1f, 0f);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a DirectionalLight
|
||||||
|
*/
|
||||||
public DirectionalLight() {
|
public DirectionalLight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a DirectionalLight with the given direction
|
||||||
|
* @param direction the light's direction
|
||||||
|
*/
|
||||||
public DirectionalLight(Vector3f direction) {
|
public DirectionalLight(Vector3f direction) {
|
||||||
setDirection(direction);
|
setDirection(direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a DirectionalLight with the given direction and the given color
|
||||||
|
* @param direction the light's direction
|
||||||
|
* @param color the light's color
|
||||||
|
*/
|
||||||
public DirectionalLight(Vector3f direction, ColorRGBA color) {
|
public DirectionalLight(Vector3f direction, ColorRGBA color) {
|
||||||
super(color);
|
super(color);
|
||||||
setDirection(direction);
|
setDirection(direction);
|
||||||
@ -90,7 +102,7 @@ public class DirectionalLight extends Light {
|
|||||||
*
|
*
|
||||||
* @param dir the direction of the light.
|
* @param dir the direction of the light.
|
||||||
*/
|
*/
|
||||||
public void setDirection(Vector3f dir){
|
public final void setDirection(Vector3f dir){
|
||||||
direction.set(dir);
|
direction.set(dir);
|
||||||
if (!direction.isUnitVector()) {
|
if (!direction.isUnitVector()) {
|
||||||
direction.normalizeLocal();
|
direction.normalizeLocal();
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
package com.jme3.light;
|
package com.jme3.light;
|
||||||
|
|
||||||
import com.jme3.bounding.BoundingBox;
|
import com.jme3.bounding.BoundingBox;
|
||||||
import com.jme3.bounding.BoundingSphere;
|
|
||||||
import com.jme3.bounding.BoundingVolume;
|
import com.jme3.bounding.BoundingVolume;
|
||||||
import com.jme3.export.InputCapsule;
|
import com.jme3.export.InputCapsule;
|
||||||
import com.jme3.export.JmeExporter;
|
import com.jme3.export.JmeExporter;
|
||||||
@ -40,7 +39,6 @@ import com.jme3.export.JmeImporter;
|
|||||||
import com.jme3.export.OutputCapsule;
|
import com.jme3.export.OutputCapsule;
|
||||||
import com.jme3.math.ColorRGBA;
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.FastMath;
|
import com.jme3.math.FastMath;
|
||||||
import com.jme3.math.Plane;
|
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.renderer.Camera;
|
import com.jme3.renderer.Camera;
|
||||||
import com.jme3.scene.Spatial;
|
import com.jme3.scene.Spatial;
|
||||||
@ -63,18 +61,52 @@ public class PointLight extends Light {
|
|||||||
protected float radius = 0;
|
protected float radius = 0;
|
||||||
protected float invRadius = 0;
|
protected float invRadius = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a PointLight
|
||||||
|
*/
|
||||||
public PointLight() {
|
public PointLight() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a PointLight at the given position
|
||||||
|
* @param position the position in world space
|
||||||
|
*/
|
||||||
public PointLight(Vector3f position) {
|
public PointLight(Vector3f position) {
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a PointLight at the given position and with the given color
|
||||||
|
* @param position the position in world space
|
||||||
|
* @param color the light color
|
||||||
|
*/
|
||||||
public PointLight(Vector3f position, ColorRGBA color) {
|
public PointLight(Vector3f position, ColorRGBA color) {
|
||||||
super(color);
|
super(color);
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a PointLight at the given position, with the given color and the
|
||||||
|
* given radius
|
||||||
|
* @param position the position in world space
|
||||||
|
* @param color the light color
|
||||||
|
* @param radius the light radius
|
||||||
|
*/
|
||||||
|
public PointLight(Vector3f position, ColorRGBA color, float radius) {
|
||||||
|
this(position, color);
|
||||||
|
setRadius(radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a PointLight at the given position, with the given radius
|
||||||
|
* @param position the position in world space
|
||||||
|
* @param radius the light radius
|
||||||
|
*/
|
||||||
|
public PointLight(Vector3f position, float radius) {
|
||||||
|
this(position);
|
||||||
|
setRadius(radius);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void computeLastDistance(Spatial owner) {
|
public void computeLastDistance(Spatial owner) {
|
||||||
if (owner.getWorldBound() != null) {
|
if (owner.getWorldBound() != null) {
|
||||||
@ -101,7 +133,7 @@ public class PointLight extends Light {
|
|||||||
*
|
*
|
||||||
* @param position the world space position of the light.
|
* @param position the world space position of the light.
|
||||||
*/
|
*/
|
||||||
public void setPosition(Vector3f position) {
|
public final void setPosition(Vector3f position) {
|
||||||
this.position.set(position);
|
this.position.set(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +160,7 @@ public class PointLight extends Light {
|
|||||||
*
|
*
|
||||||
* @throws IllegalArgumentException If radius is negative
|
* @throws IllegalArgumentException If radius is negative
|
||||||
*/
|
*/
|
||||||
public void setRadius(float radius) {
|
public final void setRadius(float radius) {
|
||||||
if (radius < 0) {
|
if (radius < 0) {
|
||||||
throw new IllegalArgumentException("Light radius cannot be negative");
|
throw new IllegalArgumentException("Light radius cannot be negative");
|
||||||
}
|
}
|
||||||
|
@ -70,17 +70,46 @@ public class SpotLight extends Light {
|
|||||||
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) {
|
public SpotLight(Vector3f position, Vector3f direction) {
|
||||||
this();
|
this();
|
||||||
setPosition(position);
|
setPosition(position);
|
||||||
setDirection(direction);
|
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) {
|
public SpotLight(Vector3f position, Vector3f direction, ColorRGBA color) {
|
||||||
super(color);
|
super(color);
|
||||||
computeAngleParameters();
|
computeAngleParameters();
|
||||||
@ -88,6 +117,49 @@ public class SpotLight extends Light {
|
|||||||
setDirection(direction);
|
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);
|
||||||
@ -203,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user