package engineTester;


import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.vecmath.Vector3f;

import org.lwjgl.openvr.Texture;

import entities.Camera;
import entities.Entity;
import entities.Light;
import models.RawModel;
import models.TexturedModel;
import renderEngine.DisplayManager;
import renderEngine.DisplayManagerDraw;
import renderEngine.Loader;
import renderEngine.MasterRenderer;
import renderEngine.OBJLoader;
import renderEngine.Renderer;
import shaders.StaticShader;
import textures.ModelTexture;

/**
 * This class contains the main method and is used to test the engine.
 * 
 * @author Karl
 *
 */
public class MainGameLoop {


	/**
	 * Loads up the position data for two triangles (which together make a quad)
	 * into a VAO. This VAO is then rendered to the screen every frame.
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		
		DisplayManager manager = new DisplayManager();
		Loader loader = new Loader();
		manager.init();

		
		
		RawModel model = OBJLoader.loadObjModel("cube", loader);
		TexturedModel cubeModel = new TexturedModel(model, new ModelTexture(loader.loadTexture("tree_sample")));
		ModelTexture texture = cubeModel.getTexture();
		texture.setShineDamper(10);
		texture.setReflectivity(1);
		
		Light light = new Light(new Vector3f(0,0,-20), new Vector3f(1,1,1));
		
		Camera camera = new Camera();
		
		List<Entity> allCubes = new ArrayList<Entity>();
		Random random = new Random();
		
		for (int iii=0; iii<2000; iii++) {
			float x = random.nextFloat() * 300 - 150;
			float y = random.nextFloat() * 300 - 150;
			float z = random.nextFloat() * -300;
			allCubes.add(new Entity(cubeModel, new Vector3f(x,y,z),
					new Vector3f(random.nextFloat()*3.14f,random.nextFloat()*3.14f,0), 1));
		}
		
		MasterRenderer renderer = new MasterRenderer();
		manager.setDrawer(new DisplayManagerDraw() {
			@Override
			public void draw() {
				//entity.increasePosition(0.0f, 0, -0.01f);
				//entity.increaseRotation(0, 0, 0.01f);
				//entity.increaseRotation(0.01f, 0.02f, 0.0f);
				camera.move();
				for (Entity cube : allCubes) {
					renderer.processEntity(cube);
				}
				renderer.render(light, camera);
			}
		});
		manager.loop();
		renderer.cleanUp();
		loader.cleanUp();
		manager.unInit();
	}

}
