From e33d2539edbac1adebe0bf34b318f2d1bde2ae4c Mon Sep 17 00:00:00 2001
From: Daniel Johansson
Date: Wed, 15 Jul 2015 13:08:36 +0100
Subject: [PATCH] Added additional convenience constructors to Light,
AmbientLight, DirectionalLight, PointLight and SpotLight as mentioned in #297
---
.../java/com/jme3/light/AmbientLight.java | 16 ++++++++
.../java/com/jme3/light/DirectionalLight.java | 27 ++++++++++++
.../src/main/java/com/jme3/light/Light.java | 16 ++++++++
.../main/java/com/jme3/light/PointLight.java | 36 ++++++++++++++++
.../main/java/com/jme3/light/SpotLight.java | 41 +++++++++++++++++--
5 files changed, 132 insertions(+), 4 deletions(-)
diff --git a/jme3-core/src/main/java/com/jme3/light/AmbientLight.java b/jme3-core/src/main/java/com/jme3/light/AmbientLight.java
index e147c6590..fb52301f9 100644
--- a/jme3-core/src/main/java/com/jme3/light/AmbientLight.java
+++ b/jme3-core/src/main/java/com/jme3/light/AmbientLight.java
@@ -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;
diff --git a/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java b/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java
index c4258a67f..7f1541fda 100644
--- a/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java
+++ b/jme3-core/src/main/java/com/jme3/light/DirectionalLight.java
@@ -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
diff --git a/jme3-core/src/main/java/com/jme3/light/Light.java b/jme3-core/src/main/java/com/jme3/light/Light.java
index 4217e1b62..7738c1721 100644
--- a/jme3-core/src/main/java/com/jme3/light/Light.java
+++ b/jme3-core/src/main/java/com/jme3/light/Light.java
@@ -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.
*
diff --git a/jme3-core/src/main/java/com/jme3/light/PointLight.java b/jme3-core/src/main/java/com/jme3/light/PointLight.java
index 55a129275..1e93e1f1e 100644
--- a/jme3-core/src/main/java/com/jme3/light/PointLight.java
+++ b/jme3-core/src/main/java/com/jme3/light/PointLight.java
@@ -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.
+ *
+ *
+ * - Position will be defaulted to 0,0,0.
+ * - Radius will be defaulted to 0
+ *
+ *
+ */
+ 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) {
diff --git a/jme3-core/src/main/java/com/jme3/light/SpotLight.java b/jme3-core/src/main/java/com/jme3/light/SpotLight.java
index e6443df7c..b4531fb1c 100644
--- a/jme3-core/src/main/java/com/jme3/light/SpotLight.java
+++ b/jme3-core/src/main/java/com/jme3/light/SpotLight.java
@@ -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.
+ *
+ *
+ * - Position will be defaulted to 0,0,0
+ * - Direction will be defaulted to -1 on the Y axis
+ * - Range will be defaulted to 100
+ *
+ *
+ */
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);