package ei.engine.renderer;

import org.lwjgl.opengl.GL11;

import ei.engine.LWJGLGameWindow;
import ei.engine.math.Vector3f;
import ei.engine.sound.SoundManager;


/**
 * The Camera calss hadels the viewport of the user
 * and the sound listener location
 * @author Ziver
 *
 */
public class Camera{
	//coordinat
	private Vector3f location;
	//Sound
	private Vector3f velocity;
	
	/**
	 * Creates a camera
	 *
	 */
	public Camera(){
		location = new Vector3f();
		velocity = new Vector3f();

		SoundManager.getInstnace().setListenerLocation(
				location.getX() + (LWJGLGameWindow.getWidth()/2),
				location.getY() + (LWJGLGameWindow.getHeight()/2),
				location.getZ());
		SoundManager.getInstnace().setListenerVelocity(
				velocity.getX(),
				velocity.getY(),
				velocity.getZ());
	}
	
	/**
	 * Updates the camera
	 *
	 */
	public void update(){
		SoundManager.getInstnace().setListenerLocation(
				location.getX() + (LWJGLGameWindow.getWidth()/2),
				location.getY() + (LWJGLGameWindow.getHeight()/2),
				location.getZ());
	}
	
	/**
	 * Returns the location of the camera
	 * 
	 * @return The location of the camera
	 */
	public Vector3f getLocation(){
		return location;
	}
	
	/**
	 * Sets the location of the world in opengl
	 * should be used before rendering.
	 */
	public void setWorldTranslationGL(){
		// translate to the right location and prepare to draw
		GL11.glTranslatef(-location.getX(), -location.getY(), -location.getZ());
	}
	
	/**
	 * Set the location of the camera
	 * 
	 * @param v The location of the camera
	 */
	public void setLocation(Vector3f v){
		location = v;
	}
}


