diff --git a/src/sg/env/Environment.java b/src/sg/env/Environment.java index 88de1b5..dd1972a 100644 --- a/src/sg/env/Environment.java +++ b/src/sg/env/Environment.java @@ -3,21 +3,35 @@ 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.renderer.Renderer; import com.jme.scene.Node; import com.jme.scene.Skybox; +import com.jme.scene.state.TextureState; import com.jme.system.DisplaySystem; +import com.jmex.effects.LensFlare; +import com.jmex.effects.LensFlareFactory; public class Environment extends Node { private static final long serialVersionUID = 1L; - private Skybox space; + /** A Node that follows the player, contains only + * things that the player can't interact with + * */ + private Node localNode; public Environment(){ - buildSkyBox(); + buildLocalNode(); } - private void buildSkyBox() { - space = new Skybox("space", 500, 500, 500); + private void buildLocalNode() { + localNode = new Node("local_space"); + + // Skybox + Skybox space = new Skybox("space", 500, 500, 500); Texture north = SGUtil.loadTexture("sg/data/skybox/advanced/front.png"); Texture rest = SGUtil.loadTexture("sg/data/skybox/advanced/rest.png"); @@ -29,10 +43,39 @@ public class Environment extends Node { space.setTexture(Skybox.Face.Down, rest); space.preloadTextures(); space.updateRenderState(); - this.attachChild(space); + 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)); + dr.setShadowCaster(true); + this.setRenderQueueMode(Renderer.QUEUE_OPAQUE); + + LightNode lightNode = new LightNode("space_light_node"); + lightNode.setLight(dr); + + // Setup the lens flare textures. + TextureState[] tex = new TextureState[4]; + tex[0] = SGUtil.getTextureState("jmetest/data/texture/flare1.png"); + tex[1] = SGUtil.getTextureState("jmetest/data/texture/flare2.png"); + tex[2] = SGUtil.getTextureState("jmetest/data/texture/flare3.png"); + tex[3] = SGUtil.getTextureState("jmetest/data/texture/flare4.png"); + LensFlare flare = LensFlareFactory.createBasicLensFlare("sunflare", tex); + flare.setRootNode(this); + flare.setLocalTranslation( 0, 0, 500); + lightNode.attachChild(flare); + lightNode.updateRenderState(); + + // attach the nodes + localNode.attachChild(lightNode); + this.attachChild(localNode); } public void update(){ - space.setLocalTranslation(DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation()); + localNode.setLocalTranslation( + DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation()); } }