2009-03-08 17:25:15 +00:00
|
|
|
package sg;
|
|
|
|
|
|
2009-03-10 13:04:15 +00:00
|
|
|
import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
2009-03-09 09:59:22 +00:00
|
|
|
import com.jme.app.SimpleGame;
|
2009-03-10 13:04:15 +00:00
|
|
|
import com.jme.bounding.BoundingBox;
|
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-10 13:04:15 +00:00
|
|
|
import com.jme.scene.shape.Sphere;
|
2009-03-09 10:32:07 +00:00
|
|
|
import com.jme.scene.state.LightState;
|
2009-03-10 13:04:15 +00:00
|
|
|
import com.jme.scene.state.TextureState;
|
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-10 13:04:15 +00:00
|
|
|
Logger.getLogger( "" ).setLevel( Level.WARNING );
|
|
|
|
|
SpaceGame game = new SpaceGame();
|
|
|
|
|
game.setConfigShowMode(ConfigShowMode.AlwaysShow);
|
|
|
|
|
game.start();
|
2009-03-09 09:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void simpleInitGame() {
|
|
|
|
|
display.setTitle("SpaceGame");
|
2009-03-10 13:04:15 +00:00
|
|
|
|
|
|
|
|
Sphere s = new Sphere("Sphere", 30, 30, 25);
|
|
|
|
|
s.setLocalTranslation(new Vector3f(0,0,-40));
|
|
|
|
|
s.setModelBound(new BoundingBox());
|
|
|
|
|
s.updateModelBound();
|
|
|
|
|
Texture texture = TextureManager.loadTexture(
|
|
|
|
|
SpaceGame.class.getClassLoader().getResource(
|
|
|
|
|
"jmetest/data/images/Monkey.jpg"),
|
|
|
|
|
Texture.MinificationFilter.Trilinear,
|
|
|
|
|
Texture.MagnificationFilter.Bilinear);
|
|
|
|
|
TextureState ts = display.getRenderer().createTextureState();
|
|
|
|
|
ts.setEnabled(true);
|
|
|
|
|
ts.setTexture(texture);
|
|
|
|
|
s.setRenderState(ts);
|
|
|
|
|
rootNode.attachChild(s);
|
|
|
|
|
|
2009-03-09 09:59:22 +00:00
|
|
|
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() {
|
|
|
|
|
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
|
|
|
}
|