#include "camera.h"

namespace ngObjects
	{
	Camera::Camera(GLfloat xLoc, GLfloat yLoc, GLfloat zLoc
				, GLfloat xView, GLfloat yView, GLfloat zView, GLfloat initDist)
	{
		setLocation(xLoc, yLoc, zLoc);
		lookAt(xView, yView, zView);
		setDistance(initDist);
		
		// Set our rotation position too zero
		rotation.x = 0;
		rotation.y = 0;
		rotation.z = 0;
		update();
	}

	void Camera::lookAt(GLfloat x, GLfloat y, GLfloat z)
	{
		look.x = x;
		look.y = y;
		look.z = z;
	}

	void Camera::move(GLfloat x, GLfloat y, GLfloat z)
	{
		position.x = x;
		position.y = y;
		position.z = z;

		look.x = x;
		look.y = y;
		look.z = z;
	}

	void Camera::rotateAxisX(GLfloat angle)
	{
		GLfloat newY = (GLfloat)(distance * sin((3.14159265 / 180) * -angle));
		rotation.y = newY;
	}

	void Camera::rotateAxisY(GLfloat angle)
	{
		GLfloat newX = (GLfloat)(distance * sin((3.14159265 / 180) * angle));	
		GLfloat newZ = (GLfloat)(distance * cos((3.14159265 / 180) * angle));

		rotation.x = newX;
		rotation.z = newZ;
	}

	void Camera::setLocation(GLfloat x, GLfloat y, GLfloat z)
	{
		position.x = x;
		position.y = y;
		position.z = z;
	}

	void Camera::setDistance(GLfloat newD)
	{
		distance = newD;
	}

	void Camera::update()
	{
		gluLookAt(
			position.x + rotation.x, position.y + rotation.y, position.z + rotation.z, 
			position.x, look.y, position.z, 
			0.0, 1.0, 0.0);
	}
}
