http://www.jmonkeyengine.com/jmeforum/index.php?topic=9390.15
If a DirectionalLight is attached to a LightNode, its not inheriting its direction.
there seems to be a Bug in LightNode:
114 switch (light.getType()) {
115 case Directional: {
116 DirectionalLight dLight = (DirectionalLight) light;
117 dLight.getDirection().set(worldTranslation).negateLocal();
118 break;
119 }
120
121 case Point: {
122 PointLight pLight = (PointLight) light;
123 pLight.getLocation().set(worldTranslation);
124 break;
125 }
should be:
117 dLight.getDirection().set(worldRotation.getRotationColumn(2));
the following Test shows a pretty black screen without the fix, because the direction of the directional light will be (0,0,0)
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.light.DirectionalLight;
import com.jme.light.LightNode;
import com.jme.math.FastMath;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.shape.Sphere;
public class TestLightNode extends SimpleGame {
static final float worldsize = 40;//The size of the world
public static void main(String[] args) {
TestLightNode app = new TestLightNode();
app.setConfigShowMode(ConfigShowMode.NeverShow);
app.start();
}
void randomSphere(int i) {
//Crate the big spheres and position it.
Sphere newSphere = new Sphere("sp" + i, 8, 8, 2);
newSphere.setModelBound(new BoundingSphere());
newSphere.updateModelBound();
newSphere.setLocalTranslation(new Vector3f(FastMath.rand.nextFloat()
* worldsize * 2 - worldsize, FastMath.rand.nextFloat()
* worldsize * 2 - worldsize, FastMath.rand.nextFloat()
* worldsize * 2 - worldsize));
rootNode.attachChild(newSphere);
}
protected void simpleInitGame() {
this.lightState.detachAll();
FastMath.rand.setSeed(1520);
//Add the spheres.
for (int i = 0; i < 60; i++) {
this.randomSphere(i);
}
//Create a new DirectionalLight
DirectionalLight dr = new DirectionalLight();
dr.setEnabled(true);
dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
dr.setAmbient(new ColorRGBA(0.2f, 0.2f, 0.2f, 1.0f));
dr.setDirection(new Vector3f(0.5f, -0.5f, 0));
dr.setShadowCaster(true);
LightNode ln = new LightNode("drn");
// let the light node look to the bottom right
ln.lookAt(new Vector3f(5, -5, 0), Vector3f.UNIT_Y.clone());
ln.setLight(dr);
lightState.attach(dr);
rootNode.attachChild(ln);
}
}
there still seems to be a problem if the LightNode is rotated and translated at the same time though.