space-game/src/sg/env/Environment.java

79 lines
2.6 KiB
Java
Raw Normal View History

2009-03-10 13:41:26 +00:00
package sg.env;
2009-03-10 16:32:33 +00:00
import sg.util.SGUtil;
2009-03-10 13:41:26 +00:00
import com.jme.image.Texture;
2009-03-11 13:43:00 +00:00
import com.jme.light.DirectionalLight;
import com.jme.light.LightNode;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
2009-03-10 13:41:26 +00:00
import com.jme.scene.Node;
import com.jme.scene.Skybox;
2009-03-11 13:43:00 +00:00
import com.jme.scene.state.TextureState;
2009-03-10 16:32:33 +00:00
import com.jme.system.DisplaySystem;
2009-03-11 13:43:00 +00:00
import com.jmex.effects.LensFlare;
import com.jmex.effects.LensFlareFactory;
2009-03-10 13:41:26 +00:00
public class Environment extends Node {
2009-03-10 15:27:00 +00:00
private static final long serialVersionUID = 1L;
2009-03-10 16:32:33 +00:00
2009-03-11 13:43:00 +00:00
/** A Node that follows the player, contains only
* things that the player can't interact with
* */
private Node localNode;
2009-03-10 13:41:26 +00:00
2009-03-11 14:15:06 +00:00
public Environment(Node rootNode){
2009-03-11 13:43:00 +00:00
buildLocalNode();
2009-03-10 13:41:26 +00:00
}
2009-03-11 13:43:00 +00:00
private void buildLocalNode() {
localNode = new Node("local_space");
// Skybox
Skybox space = new Skybox("space", 500, 500, 500);
2009-03-10 16:32:33 +00:00
Texture north = SGUtil.loadTexture("sg/data/skybox/advanced/front.png");
Texture rest = SGUtil.loadTexture("sg/data/skybox/advanced/rest.png");
space.setTexture(Skybox.Face.North, north);
space.setTexture(Skybox.Face.West, rest);
space.setTexture(Skybox.Face.South, rest);
space.setTexture(Skybox.Face.East, rest);
space.setTexture(Skybox.Face.Up, rest);
space.setTexture(Skybox.Face.Down, rest);
space.preloadTextures();
space.updateRenderState();
2009-03-11 13:43:00 +00:00
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));
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);
2009-03-10 16:32:33 +00:00
}
public void update(){
2009-03-11 13:43:00 +00:00
localNode.setLocalTranslation(
DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
2009-03-10 13:41:26 +00:00
}
}