Quellcode durchsuchen

Merge branch 'master' of https://github.com/jMonkeyEngine/jmonkeyengine

Julien Gouesse vor 10 Jahren
Ursprung
Commit
8ace69d0c3

+ 1 - 1
.travis.yml

@@ -25,7 +25,7 @@ install:
 script:
   - ./gradlew check
   - ./gradlew createZipDistribution
-  - "[ $TRAVIS_BRANCH == 'master' ] && [ $TRAVIS_PULL_REQUEST == 'false' ] && ./gradlew uploadArchives;"
+  - [ $TRAVIS_BRANCH == 'master' ] && [ $TRAVIS_PULL_REQUEST == 'false' ] && ./gradlew uploadArchives || :
 
 before_deploy:
   - export RELEASE_DIST=$(ls build/distributions/*.zip)

+ 9 - 1
jme3-core/src/main/java/com/jme3/light/AmbientLight.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2012, 2015 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -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,13 @@ import com.jme3.util.TempVars;
  */
 public class AmbientLight extends Light {
 
+    public AmbientLight() {
+    }
+
+    public AmbientLight(ColorRGBA color) {
+        super(color);
+    }
+
     @Override
     public boolean intersectsBox(BoundingBox box, TempVars vars) {
         return true;

+ 27 - 2
jme3-core/src/main/java/com/jme3/light/DirectionalLight.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2012, 2015 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -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,30 @@ public class DirectionalLight extends Light {
 
     protected Vector3f direction = new Vector3f(0f, -1f, 0f);
 
+    /**
+     * Creates a DirectionalLight
+     */
+    public DirectionalLight() {
+    }
+
+    /**
+     * Creates a DirectionalLight with the given direction
+     * @param direction the light's direction
+     */
+    public DirectionalLight(Vector3f 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) {
+        super(color);
+        setDirection(direction);
+    }
+
     @Override
     public void computeLastDistance(Spatial owner) {
         lastDistance = 0; // directional lights are always closest to their owner
@@ -77,7 +102,7 @@ public class DirectionalLight extends Light {
      * 
      * @param dir the direction of the light.
      */
-    public void setDirection(Vector3f dir){
+    public final void setDirection(Vector3f dir){
         direction.set(dir);
         if (!direction.isUnitVector()) {
             direction.normalizeLocal();

+ 9 - 2
jme3-core/src/main/java/com/jme3/light/Light.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2012, 2015 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -94,7 +94,7 @@ public abstract class Light implements Savable, Cloneable {
         }
     }
 
-    protected ColorRGBA color = new ColorRGBA(1f,1f,1f,1f);
+    protected ColorRGBA color = new ColorRGBA(ColorRGBA.White);
     
     /**
      * Used in LightList for caching the distance 
@@ -115,6 +115,13 @@ public abstract class Light implements Savable, Cloneable {
     boolean frustumCheckNeeded = true;
     boolean intersectsFrustum  = false;
 
+    protected Light() {
+    }
+
+    protected Light(ColorRGBA color) {
+        setColor(color);
+    }
+
     /**
      * Returns the color of the light.
      * 

+ 50 - 5
jme3-core/src/main/java/com/jme3/light/PointLight.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2012, 2015 jMonkeyEngine
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -32,14 +32,13 @@
 package com.jme3.light;
 
 import com.jme3.bounding.BoundingBox;
-import com.jme3.bounding.BoundingSphere;
 import com.jme3.bounding.BoundingVolume;
 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;
 import com.jme3.renderer.Camera;
 import com.jme3.scene.Spatial;
@@ -62,6 +61,52 @@ public class PointLight extends Light {
     protected float radius = 0;
     protected float invRadius = 0;
 
+    /**
+     * Creates a PointLight
+     */
+    public PointLight() {
+    }
+
+    /**
+     * Creates a PointLight at the given position
+     * @param position the position in world space
+     */
+    public PointLight(Vector3f 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) {
+        super(color);
+        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
     public void computeLastDistance(Spatial owner) {
         if (owner.getWorldBound() != null) {
@@ -88,7 +133,7 @@ public class PointLight extends 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);
     }
 
@@ -115,7 +160,7 @@ public class PointLight extends Light {
      * 
      * @throws IllegalArgumentException If radius is negative
      */
-    public void setRadius(float radius) {
+    public final void setRadius(float radius) {
         if (radius < 0) {
             throw new IllegalArgumentException("Light radius cannot be negative");
         }

+ 97 - 11
jme3-core/src/main/java/com/jme3/light/SpotLight.java

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 jMonkeyEngine
+ * Copyright (c) 2009-2012, 2015 jMonkeyEngine
  * All rights reserved.
  *
  * 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.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;
@@ -44,36 +45,121 @@ import java.io.IOException;
 
 /**
  * Represents a spot light.
- * A spot light emmit a cone of light from a position and in a direction.
- * It can be used to fake torch lights or car's lights.
+ * A spot light emits a cone of light from a position and in a direction.
+ * It can be used to fake torch lights or cars' lights.
  * <p>
  * 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 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.
- * 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 light intensity slowly decrease between the inner cone and the outer cone.
+ * 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.
  *  @author Nehon
  */
 public class SpotLight extends Light {
 
     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 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;
     
+    /**
+     * Creates a SpotLight.
+     */
     public SpotLight() {
         super();
         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() {
         float innerCos = FastMath.cos(spotInnerAngle);
         outerAngleCos = FastMath.cos(spotOuterAngle);
@@ -189,7 +275,7 @@ public class SpotLight extends Light {
         return direction;
     }
 
-    public void setDirection(Vector3f direction) {
+    public final void setDirection(Vector3f direction) {
         this.direction.set(direction);
     }
 
@@ -197,7 +283,7 @@ public class SpotLight extends Light {
         return position;
     }
 
-    public void setPosition(Vector3f position) {
+    public final void setPosition(Vector3f position) {
         this.position.set(position);
     }