Merge pull request #306 from mbenson/light-ctors

More convenient light constructors
experimental
Rémy Bouquet 9 years ago
commit 609d9a1832
  1. 10
      jme3-core/src/main/java/com/jme3/light/AmbientLight.java
  2. 15
      jme3-core/src/main/java/com/jme3/light/DirectionalLight.java
  3. 11
      jme3-core/src/main/java/com/jme3/light/Light.java
  4. 15
      jme3-core/src/main/java/com/jme3/light/PointLight.java
  5. 28
      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. * 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
@ -32,6 +32,7 @@
package com.jme3.light; package com.jme3.light;
import com.jme3.bounding.BoundingBox; import com.jme3.bounding.BoundingBox;
import com.jme3.math.ColorRGBA;
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;
@ -49,6 +50,13 @@ import com.jme3.util.TempVars;
*/ */
public class AmbientLight extends Light { public class AmbientLight extends Light {
public AmbientLight() {
}
public AmbientLight(ColorRGBA color) {
super(color);
}
@Override @Override
public boolean intersectsBox(BoundingBox box, TempVars vars) { public boolean intersectsBox(BoundingBox box, TempVars vars) {
return true; return true;

@ -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
@ -36,6 +36,7 @@ import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.math.ColorRGBA;
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;
@ -53,6 +54,18 @@ public class DirectionalLight extends Light {
protected Vector3f direction = new Vector3f(0f, -1f, 0f); protected Vector3f direction = new Vector3f(0f, -1f, 0f);
public DirectionalLight() {
}
public DirectionalLight(Vector3f direction) {
setDirection(direction);
}
public DirectionalLight(Vector3f direction, ColorRGBA color) {
super(color);
setDirection(direction);
}
@Override @Override
public void computeLastDistance(Spatial owner) { public void computeLastDistance(Spatial owner) {
lastDistance = 0; // directional lights are always closest to their owner lastDistance = 0; // directional lights are always closest to their owner

@ -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
@ -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 * Used in LightList for caching the distance
@ -115,6 +115,13 @@ public abstract class Light implements Savable, Cloneable {
boolean frustumCheckNeeded = true; boolean frustumCheckNeeded = true;
boolean intersectsFrustum = false; boolean intersectsFrustum = false;
protected Light() {
}
protected Light(ColorRGBA color) {
setColor(color);
}
/** /**
* Returns the color of the light. * Returns the color of the light.
* *

@ -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
@ -38,6 +38,7 @@ import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter; import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
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;
@ -62,6 +63,18 @@ public class PointLight extends Light {
protected float radius = 0; protected float radius = 0;
protected float invRadius = 0; protected float invRadius = 0;
public PointLight() {
}
public PointLight(Vector3f position) {
setPosition(position);
}
public PointLight(Vector3f position, ColorRGBA color) {
super(color);
setPosition(position);
}
@Override @Override
public void computeLastDistance(Spatial owner) { public void computeLastDistance(Spatial owner) {
if (owner.getWorldBound() != null) { if (owner.getWorldBound() != null) {

@ -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,16 +45,16 @@ 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 {
@ -74,6 +75,19 @@ public class SpotLight extends Light {
computeAngleParameters(); computeAngleParameters();
} }
public SpotLight(Vector3f position, Vector3f direction) {
this();
setPosition(position);
setDirection(direction);
}
public SpotLight(Vector3f position, Vector3f direction, ColorRGBA color) {
super(color);
computeAngleParameters();
setPosition(position);
setDirection(direction);
}
private void computeAngleParameters() { private void computeAngleParameters() {
float innerCos = FastMath.cos(spotInnerAngle); float innerCos = FastMath.cos(spotInnerAngle);
outerAngleCos = FastMath.cos(spotOuterAngle); outerAngleCos = FastMath.cos(spotOuterAngle);

Loading…
Cancel
Save