From 0935259b6c3502e53f7741f273170fd887dd4f3a Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Wed, 11 Mar 2009 14:55:21 +0000 Subject: [PATCH] Fixed lights --- src/sg/env/Environment.java | 14 ++------------ src/sg/states/InGameState.java | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/sg/env/Environment.java b/src/sg/env/Environment.java index a0bb413..7fe1df6 100644 --- a/src/sg/env/Environment.java +++ b/src/sg/env/Environment.java @@ -3,10 +3,7 @@ package sg.env; import sg.util.SGUtil; import com.jme.image.Texture; -import com.jme.light.DirectionalLight; import com.jme.light.LightNode; -import com.jme.math.Vector3f; -import com.jme.renderer.ColorRGBA; import com.jme.scene.Node; import com.jme.scene.Skybox; import com.jme.scene.state.TextureState; @@ -22,7 +19,7 @@ public class Environment extends Node { * */ private Node localNode; - public Environment(Node rootNode){ + public Environment(Node parentNode){ buildLocalNode(); } @@ -44,15 +41,8 @@ public class Environment extends Node { space.updateRenderState(); localNode.attachChild(space); - // Lights - DirectionalLight dr = new DirectionalLight(); - dr.setEnabled(true); - dr.setDiffuse(ColorRGBA.white); - dr.setAmbient(ColorRGBA.gray); - dr.setDirection(new Vector3f(0.0f, 0.0f, 0.0f)); - + // Lights LightNode lightNode = new LightNode("space_light_node"); - lightNode.setLight(dr); // Setup the lens flare textures. TextureState[] tex = new TextureState[4]; diff --git a/src/sg/states/InGameState.java b/src/sg/states/InGameState.java index 5ab143c..195ee4c 100644 --- a/src/sg/states/InGameState.java +++ b/src/sg/states/InGameState.java @@ -7,9 +7,12 @@ import sg.util.SGUtil; import com.jme.input.FirstPersonHandler; import com.jme.input.InputHandler; +import com.jme.light.PointLight; import com.jme.math.Vector3f; +import com.jme.renderer.ColorRGBA; import com.jme.renderer.Renderer; import com.jme.scene.Node; +import com.jme.scene.state.LightState; import com.jme.system.DisplaySystem; import com.jmex.game.state.CameraGameState; import com.jmex.game.state.GameStateManager; @@ -51,23 +54,37 @@ public class InGameState extends CameraGameState { rootNode.attachChild(dynamicNode); rootNode.attachChild(staticNode); - // ship - Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds"); - ship.setLocalTranslation(new Vector3f(0,0,-40)); - //ship.setLocalScale(0.01f); - rootNode.attachChild(ship); - loader.increment(); - // environment environment = new Environment(rootNode); rootNode.attachChild(environment); loader.increment(); + // ship + Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds"); + ship.setLocalTranslation(new Vector3f( 0, 0, 40)); + rootNode.attachChild(ship); + loader.increment(); + // inputs FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 ); input = new InputHandler(); input.addToAttachedHandlers( first ); loader.increment(); + + // lights + /** Set up a basic, default light. */ + PointLight light = new PointLight(); + light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) ); + light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) ); + light.setLocation( new Vector3f( 100, 100, 100 ) ); + light.setEnabled( true ); + + /** Attach the light to a lightState and the lightState to rootNode. */ + LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState(); + lightState.setEnabled( true ); + lightState.attach( light ); + rootNode.setRenderState( lightState ); + rootNode.updateRenderState(); // ***************** Done loading ********************************** loader.setActive(false);