Fixed lights
This commit is contained in:
parent
14f395d273
commit
0935259b6c
2 changed files with 26 additions and 19 deletions
14
src/sg/env/Environment.java
vendored
14
src/sg/env/Environment.java
vendored
|
|
@ -3,10 +3,7 @@ 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.light.LightNode;
|
||||||
import com.jme.math.Vector3f;
|
|
||||||
import com.jme.renderer.ColorRGBA;
|
|
||||||
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.scene.state.TextureState;
|
||||||
|
|
@ -22,7 +19,7 @@ public class Environment extends Node {
|
||||||
* */
|
* */
|
||||||
private Node localNode;
|
private Node localNode;
|
||||||
|
|
||||||
public Environment(Node rootNode){
|
public Environment(Node parentNode){
|
||||||
buildLocalNode();
|
buildLocalNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -44,15 +41,8 @@ public class Environment extends Node {
|
||||||
space.updateRenderState();
|
space.updateRenderState();
|
||||||
localNode.attachChild(space);
|
localNode.attachChild(space);
|
||||||
|
|
||||||
// Lights
|
// 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 lightNode = new LightNode("space_light_node");
|
||||||
lightNode.setLight(dr);
|
|
||||||
|
|
||||||
// Setup the lens flare textures.
|
// Setup the lens flare textures.
|
||||||
TextureState[] tex = new TextureState[4];
|
TextureState[] tex = new TextureState[4];
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,12 @@ import sg.util.SGUtil;
|
||||||
|
|
||||||
import com.jme.input.FirstPersonHandler;
|
import com.jme.input.FirstPersonHandler;
|
||||||
import com.jme.input.InputHandler;
|
import com.jme.input.InputHandler;
|
||||||
|
import com.jme.light.PointLight;
|
||||||
import com.jme.math.Vector3f;
|
import com.jme.math.Vector3f;
|
||||||
|
import com.jme.renderer.ColorRGBA;
|
||||||
import com.jme.renderer.Renderer;
|
import com.jme.renderer.Renderer;
|
||||||
import com.jme.scene.Node;
|
import com.jme.scene.Node;
|
||||||
|
import com.jme.scene.state.LightState;
|
||||||
import com.jme.system.DisplaySystem;
|
import com.jme.system.DisplaySystem;
|
||||||
import com.jmex.game.state.CameraGameState;
|
import com.jmex.game.state.CameraGameState;
|
||||||
import com.jmex.game.state.GameStateManager;
|
import com.jmex.game.state.GameStateManager;
|
||||||
|
|
@ -51,23 +54,37 @@ public class InGameState extends CameraGameState {
|
||||||
rootNode.attachChild(dynamicNode);
|
rootNode.attachChild(dynamicNode);
|
||||||
rootNode.attachChild(staticNode);
|
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
|
||||||
environment = new Environment(rootNode);
|
environment = new Environment(rootNode);
|
||||||
rootNode.attachChild(environment);
|
rootNode.attachChild(environment);
|
||||||
loader.increment();
|
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
|
// inputs
|
||||||
FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 );
|
FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 );
|
||||||
input = new InputHandler();
|
input = new InputHandler();
|
||||||
input.addToAttachedHandlers( first );
|
input.addToAttachedHandlers( first );
|
||||||
loader.increment();
|
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 **********************************
|
// ***************** Done loading **********************************
|
||||||
loader.setActive(false);
|
loader.setActive(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue