SpotLight is not shown

Hey there! I’ve implemented a SpotLight as FlashLight for testing in my (currently) little game.

The problem is: The light is not shown … -.-"



Here’s my code, hope anyone see my mistake:

[java]package org.team4j.openalbion;



import com.jme3.app.SimpleApplication;

import com.jme3.audio.AudioNode;

import com.jme3.input.KeyInput;

import com.jme3.input.MouseInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.input.controls.MouseButtonTrigger;

import com.jme3.light.DirectionalLight;

import com.jme3.light.SpotLight;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Vector2f;

import com.jme3.math.Vector3f;

import com.jme3.post.FilterPostProcessor;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Spatial;

import com.jme3.water.WaterFilter;



/**

  • Project: OpenAlbion
  • @author Morph

    */

    public class OpenAlbion extends SimpleApplication {

    private final Timer gameTimer = new Timer();

    private final Thread tGameTimer = new Thread(gameTimer);



    // Global Lights

    private DirectionalLight sun = new DirectionalLight();

    private Vector3f sunDirection = new Vector3f(0f, -.0f, 1f);



    // Debug Objects

    private SpotLight flashLight = new SpotLight();



    public static void main(String[] args) {

    OpenAlbion app = new OpenAlbion();

    app.start();

    }



    @Override

    public void destroy() {

    tGameTimer.interrupt();



    super.destroy();

    }



    @Override

    public void simpleInitApp() {

    // Init gameTimer

    tGameTimer.start();



    // Init sun

    sun.setName("globalSun");

    sun.setColor(new ColorRGBA(0.9f, 0.5f, 0.3f, 1.0f));

    sun.setDirection(sunDirection);



    // Init flashlight

    flashLight.setName("flashlight");

    flashLight.setColor(ColorRGBA.White);

    flashLight.setDirection(cam.getDirection());

    flashLight.setPosition(cam.getLocation());

    flashLight.setSpotInnerAngle(10.0f);

    flashLight.setSpotOuterAngle(15.0f);

    flashLight.setSpotRange(100.0f);



    Spatial devMap = assetManager.loadModel("Scenes/Maps/map_100_iceland.j3o");

    WaterFilter wf = new WaterFilter(rootNode, sunDirection);

    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);



    // Filter

    wf.setWaterHeight(70.0f);

    wf.setWindDirection(new Vector2f(-1.0f, 0f));

    wf.setLightDirection(sunDirection);

    wf.setLightColor(sun.getColor());

    fpp.addFilter(wf);



    rootNode.attachChild(devMap);

    rootNode.addLight(flashLight);

    rootNode.addLight(sun);



    viewPort.addProcessor(fpp);

    cam.setLocation(new Vector3f(0, 100.0f, 0));

    flyCam.setMoveSpeed(40.0f);



    // Test Music

    AudioNode mainMusic = new AudioNode(assetManager, "Sounds/Music/Main.ogg");

    //audioRenderer.playSource(mainMusic);



    // Init Keys

    initKeys();

    }



    @Override

    public void simpleUpdate(float tpf) {

    // Calc sun

    calcSunDirection();

    }



    @Override

    public void simpleRender(RenderManager rm) {



    }



    public void calcSunDirection() {

    int deg = (gameTimer.getTicks() * 2) / 10;

    float deg2 = ((float)deg / 180) * (float) Math.PI;



    sunDirection.set(new Vector3f(FastMath.sin(deg2), FastMath.cos(deg2), 0f));

    sun.setDirection(sunDirection);



    // Debug

    fpsText.setText(String.format("GameTime: %s; GameTicks: %d; Sun Deg: %d; Sin %f; Cos: %f",

    gameTimer.getTime(),

    gameTimer.getTicks(),

    deg,

    FastMath.sin(deg2),

    FastMath.cos(deg2)));

    }



    private void initKeys() {

    inputManager.addMapping("gameTimeUp", new KeyTrigger(KeyInput.KEY_ADD));

    inputManager.addMapping("gameTimeDown", new KeyTrigger(KeyInput.KEY_SUBTRACT));

    inputManager.addMapping("flashlightToggle", new KeyTrigger(KeyInput.KEY_F), new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));



    inputManager.addListener(actionListener, new String[] { "gameTimeUp", "gameTimeDown", "flashlightToggle" });

    }



    private ActionListener actionListener = new ActionListener() {

    public void onAction(String name, boolean isPressed, float tpf) {

    if (name.equalsIgnoreCase("gameTimeUp") && !isPressed) {

    gameTimer.increment(75); // Add hour

    } else if (name.equalsIgnoreCase("gameTimeDown") && !isPressed) {

    gameTimer.decrement(75); // Remove hour

    } else if (name.equalsIgnoreCase("flashlightToggle") && !isPressed) {

    if (flashLight.getSpotRange() > 1.0f) {

    flashLight.setSpotRange(1.0f);

    } else {

    flashLight.setSpotRange(100.0f);

    }

    }

    }

    };

    }

    [/java]



    Greetz - Morph 8)

Are you moving the flashlight with the camera? Simple update is change the sun direction… but I see nothing that updates the flashlight according to the camera.