Hi i have some weird lighting problem on my Quad when i move the camera around. The problem seems to be in the location of the light
import java.net.URL;
import loading.Loaders;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.image.Texture;
import com.jme.light.SpotLight;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
public class LightTest extends SimpleGame
{
private static final URL floorURL = LightTest.class
.getClassLoader()
.getResource(
"jmetest/data/texture/wall.jpg");
private static final URL modelUrl = LightTest.class
.getClassLoader()
.getResource(
"jmetest/data/model/Character.3DS");
private Node dude;
private Quad floor;
private Node terrainNode;
@Override
protected void simpleInitGame()
{
buildDude();
buildFloor();
buildLight();
rootNode.updateGeometricState(0, true);
}
private void buildFloor()
{
// texture
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(TextureManager.loadTexture(floorURL, Texture.MM_LINEAR,
Texture.FM_LINEAR));
ts.getTexture().setWrap(Texture.WM_MIRRORED_S_MIRRORED_T);
ts.getTexture().setScale(new Vector3f(1.5f, 1.5f, 1.5f));
// vloer
terrainNode = new Node();
floor = new Quad("floor", 500, 500);
Quaternion turn = new Quaternion();
turn.fromAngles(-90 * FastMath.DEG_TO_RAD, 0, 0);
floor.setLocalRotation(turn);
floor.setLocalTranslation(0, 0, 0);
floor.setModelBound(new BoundingBox());
floor.updateModelBound();
terrainNode.attachChild(floor);
terrainNode.setRenderState(ts);
terrainNode.updateRenderState();
rootNode.attachChild(terrainNode);
rootNode.updateWorldBound();
}
private void buildDude()
{
dude = new Node("dude");
dude.setModelBound(new BoundingSphere());
dude.attachChild(Loaders.load3dsModel(modelUrl));
dude.setLocalScale(.5f);
dude.setLocalTranslation(0, 0, 0);
dude.updateModelBound();
dude.updateGeometricState(0, true);
dude.updateWorldBound();
rootNode.attachChild(dude);
rootNode.updateWorldBound();
}
private void buildLight()
{
SpotLight sp1 = new SpotLight();
sp1.setLocation(new Vector3f(0, 50, 0));
sp1.setDiffuse(ColorRGBA.blue);
sp1.setAmbient(new ColorRGBA(0.50f, 0.50f, 1.0f, 1.0f));
sp1.setEnabled(true);
sp1.setDirection(new Vector3f(-300, 0, 300));
sp1.setAngle(90);
SpotLight sp2 = new SpotLight();
sp2.setDiffuse(ColorRGBA.red);
sp2.setAmbient(new ColorRGBA(1.0f, 0.50f, 0.50f, 1.0f));
sp2.setDirection(new Vector3f(300, 0, -300));
sp2.setLocation(new Vector3f(200, 50, -200));
sp2.setAngle(90);
sp2.setEnabled(true);
LightState ls = display.getRenderer().createLightState();
ls.detachAll();
ls.attach(sp1);
ls.attach(sp2);
rootNode.setRenderState(ls);
rootNode.updateRenderState();
}
/**
*
*
* @param args
*/
public static void main(String[] args)
{
LightTest app = new LightTest();
app.setDialogBehaviour(SimpleGame.ALWAYS_SHOW_PROPS_DIALOG);
app.start();
}
}
Only the quad is affected by this flickering not the model that is in the center. When i change the location of sp1 to say new Vector3f(-1,50,1)
the flickering stops when the location is 1,50,1 the flickering back again, Why is this ?
i would be grateful if someone could shed some light on this