Added lens flare and a localNode
This commit is contained in:
parent
eda35769c0
commit
3c49eda28f
1 changed files with 49 additions and 6 deletions
55
src/sg/env/Environment.java
vendored
55
src/sg/env/Environment.java
vendored
|
|
@ -3,21 +3,35 @@ package sg.env;
|
||||||
import sg.util.SGUtil;
|
import sg.util.SGUtil;
|
||||||
|
|
||||||
import com.jme.image.Texture;
|
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.Node;
|
||||||
import com.jme.scene.Skybox;
|
import com.jme.scene.Skybox;
|
||||||
|
import com.jme.scene.state.TextureState;
|
||||||
import com.jme.system.DisplaySystem;
|
import com.jme.system.DisplaySystem;
|
||||||
|
import com.jmex.effects.LensFlare;
|
||||||
|
import com.jmex.effects.LensFlareFactory;
|
||||||
|
|
||||||
public class Environment extends Node {
|
public class Environment extends Node {
|
||||||
private static final long serialVersionUID = 1L;
|
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(){
|
public Environment(){
|
||||||
buildSkyBox();
|
buildLocalNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildSkyBox() {
|
private void buildLocalNode() {
|
||||||
space = new Skybox("space", 500, 500, 500);
|
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 north = SGUtil.loadTexture("sg/data/skybox/advanced/front.png");
|
||||||
Texture rest = SGUtil.loadTexture("sg/data/skybox/advanced/rest.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.setTexture(Skybox.Face.Down, rest);
|
||||||
space.preloadTextures();
|
space.preloadTextures();
|
||||||
space.updateRenderState();
|
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(){
|
public void update(){
|
||||||
space.setLocalTranslation(DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
|
localNode.setLocalTranslation(
|
||||||
|
DisplaySystem.getDisplaySystem().getRenderer().getCamera().getLocation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue