#include "Skybox.h"
#include "TextureObject.h"
#include "Camera.h"
#include "math.h"

Skybox::Skybox(Camera* cam, float farplaneDistance)
{
	this->cam = cam;
	this->position = cam->getPosition();
	this->size = size;
	this->farplane = farplaneDistance;

	//this->left = new TextureObject("");
	//this->right = new TextureObject("");
	this->front = new TextureObject("Textures/front.png");
	/*this->back = new TextureObject("");
	this->top = new TextureObject("");
	this->bottom = new TextureObject("");*/

}

Skybox::~Skybox()
{

}

void Skybox::update()
{
	this->position = cam->getPosition();
}

void Skybox::render()
{
	float distance = sqrt(farplane * farplane * 3);
	distance = (farplane * farplane) / distance;
	
	glPushMatrix();

		glDisable (GL_FOG);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		
		// Front
		front->activate();
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f( -distance, distance, -distance);
			glTexCoord2f(.0f, .0f);
			glVertex3f( -distance, -distance, -distance);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f( distance, -distance, -distance);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f( distance, distance, -distance);
		glEnd();
		front->deactivate();

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glEnable (GL_FOG);
	glPopMatrix();
}