package sg;

import java.util.logging.Level;
import java.util.logging.Logger;

import sg.env.Environment;

import com.jme.bounding.BoundingBox;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.TextureState;
import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.util.TextureManager;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.util.SimplePhysicsGame;

public class SpaceGame extends SimplePhysicsGame {
	private StaticPhysicsNode staticNode;
	private DynamicPhysicsNode dynamicNode;
	private Environment environment;

	public static void main(String[] args) {
		Logger.getLogger("").setLevel( Level.WARNING );
		SpaceGame game = new SpaceGame();
		game.setConfigShowMode(ConfigShowMode.AlwaysShow);
		game.start(); 
	}

	protected void simpleInitGame() {
		display.setTitle("SpaceGame");

		//physics
		getPhysicsSpace().setDirectionalGravity(new Vector3f(0f, 0f, 0f));
		staticNode = getPhysicsSpace().createStaticNode();
		rootNode.attachChild(staticNode);
		dynamicNode = getPhysicsSpace().createDynamicNode();
		rootNode.attachChild(dynamicNode);

		//environment
		environment = new Environment();
		rootNode.attachChild(environment);

		//light
		//TODO

		//sphere
		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.BilinearNearestMipMap,
		                Texture.MagnificationFilter.Bilinear);
		TextureState ts = display.getRenderer().createTextureState();
		ts.setEnabled(true);
		ts.setTexture(texture);
		s.setRenderState(ts);
		dynamicNode.attachChild(s);
	}

	public void simpleUpdate(){
		environment.setLocalTranslation(cam.getLocation());
	}
}