2009-03-08 17:25:15 +00:00
|
|
|
package sg;
|
|
|
|
|
|
2009-03-09 09:59:22 +00:00
|
|
|
import com.jme.app.SimpleGame;
|
2009-03-09 10:32:07 +00:00
|
|
|
import com.jme.renderer.ColorRGBA;
|
2009-03-09 09:59:22 +00:00
|
|
|
import com.jme.scene.Skybox;
|
2009-03-09 10:32:07 +00:00
|
|
|
import com.jme.scene.state.LightState;
|
2009-03-09 09:59:22 +00:00
|
|
|
import com.jme.image.Texture;
|
2009-03-09 10:32:07 +00:00
|
|
|
import com.jme.light.PointLight;
|
|
|
|
|
import com.jme.math.Vector3f;
|
2009-03-09 09:59:22 +00:00
|
|
|
import com.jme.util.TextureManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SpaceGame extends SimpleGame {
|
|
|
|
|
private Skybox skybox;
|
2009-03-09 10:32:07 +00:00
|
|
|
private LightState lightState;
|
2009-03-08 17:25:15 +00:00
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
2009-03-09 09:59:22 +00:00
|
|
|
SpaceGame app = new SpaceGame();
|
|
|
|
|
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
|
|
|
|
|
app.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void simpleInitGame() {
|
|
|
|
|
display.setTitle("SpaceGame");
|
|
|
|
|
buildSkyBox();
|
|
|
|
|
rootNode.attachChild(skybox);
|
2009-03-09 10:32:07 +00:00
|
|
|
buildLighting();
|
|
|
|
|
rootNode.setRenderState(lightState);
|
2009-03-09 09:59:22 +00:00
|
|
|
}
|
2009-03-09 10:32:07 +00:00
|
|
|
|
2009-03-09 09:59:22 +00:00
|
|
|
public void simpleUpdate(){
|
|
|
|
|
skybox.setLocalTranslation(cam.getLocation());
|
|
|
|
|
}
|
2009-03-08 17:25:15 +00:00
|
|
|
|
2009-03-09 09:59:22 +00:00
|
|
|
private void buildSkyBox() {
|
|
|
|
|
skybox = new Skybox("skybox", 500, 500, 500);
|
|
|
|
|
Texture north = TextureManager.loadTexture(
|
2009-03-09 10:32:07 +00:00
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
2009-03-09 09:59:22 +00:00
|
|
|
"sg/data/skybox/advanced/front.png"),
|
|
|
|
|
Texture.MinificationFilter.BilinearNearestMipMap,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
Texture south = TextureManager.loadTexture(
|
2009-03-09 10:32:07 +00:00
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
2009-03-09 09:59:22 +00:00
|
|
|
"sg/data/skybox/advanced/rest.png"),
|
|
|
|
|
Texture.MinificationFilter.BilinearNearestMipMap,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
Texture east = TextureManager.loadTexture(
|
2009-03-09 10:32:07 +00:00
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
2009-03-09 09:59:22 +00:00
|
|
|
"sg/data/skybox/advanced/rest.png"),
|
|
|
|
|
Texture.MinificationFilter.BilinearNearestMipMap,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
Texture west = TextureManager.loadTexture(
|
2009-03-09 10:32:07 +00:00
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
2009-03-09 09:59:22 +00:00
|
|
|
"sg/data/skybox/advanced/rest.png"),
|
|
|
|
|
Texture.MinificationFilter.BilinearNearestMipMap,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
Texture up = TextureManager.loadTexture(
|
2009-03-09 10:32:07 +00:00
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
2009-03-09 09:59:22 +00:00
|
|
|
"sg/data/skybox/advanced/rest.png"),
|
|
|
|
|
Texture.MinificationFilter.BilinearNearestMipMap,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
Texture down = TextureManager.loadTexture(
|
2009-03-09 10:32:07 +00:00
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
2009-03-09 09:59:22 +00:00
|
|
|
"sg/data/skybox/advanced/rest.png"),
|
|
|
|
|
Texture.MinificationFilter.BilinearNearestMipMap,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
skybox.setTexture(Skybox.Face.North, north);
|
|
|
|
|
skybox.setTexture(Skybox.Face.West, west);
|
|
|
|
|
skybox.setTexture(Skybox.Face.South, south);
|
|
|
|
|
skybox.setTexture(Skybox.Face.East, east);
|
|
|
|
|
skybox.setTexture(Skybox.Face.Up, up);
|
|
|
|
|
skybox.setTexture(Skybox.Face.Down, down);
|
|
|
|
|
skybox.preloadTextures();
|
|
|
|
|
skybox.updateRenderState();
|
2009-03-08 17:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-09 10:32:07 +00:00
|
|
|
private void buildLighting() {
|
|
|
|
|
/** Set up a basic, default light. */
|
|
|
|
|
PointLight light = new PointLight();
|
|
|
|
|
light.setDiffuse( new ColorRGBA( 1.0f, 1.0f, 1.0f, 1.0f ) );
|
|
|
|
|
light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
|
|
|
|
|
light.setLocation( new Vector3f( 100, 100, 100 ) );
|
|
|
|
|
light.setEnabled( true );
|
|
|
|
|
|
|
|
|
|
lightState = display.getRenderer().createLightState();
|
|
|
|
|
lightState.setEnabled( true );
|
|
|
|
|
lightState.attach( light );
|
|
|
|
|
}
|
2009-03-09 09:59:22 +00:00
|
|
|
}
|