#include "Planet.h"
#include "Material.h"
#include "TextureObject.h"
#include "Sphere.h"

Planet::Planet(Vec3f position, float radius)
{
	this->position = position;
	this->radius = radius;

	mat = new Material(Vec4f(0.7, 0.55, 0.4),  Vec4f(8, 0.6, 0.5), Vec4f(0.2, 0.2, 0.2), 64);
	tex = new TextureObject("Textures/asteroid_v8.jpg");
	clouds = new TextureObject("Textures/clouds.png");

	rotAngle = 0.0f;
	geo = new Sphere();
}
//-------------------------------------------------------------------------
Planet::~Planet()
{
	delete mat;
	delete tex;
	delete geo;
}
//-------------------------------------------------------------------------
void Planet::update()
{
	rotAngle += 0.05f;
}
//-------------------------------------------------------------------------
void Planet::render()
{
	//glEnable(GL_TEXTURE_GEN_S);				
	//glEnable(GL_TEXTURE_GEN_T);	

	mat->activate();

	glPushMatrix();
		glTranslatef(position.x, position.y, position.z);
		
		glRotatef(rotAngle, 1,0,0);
		glRotatef(90, 0,0,1);
		glScalef(radius, radius, radius);

		tex->activate();
		geo->render();
		
		//glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		//glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		//glutSolidSphere(radius,40,40);
		
		tex->deactivate();

	glPopMatrix();


	glPushMatrix();
		
		glTranslatef(position.x, position.y, position.z);

		glRotatef(0.5f * rotAngle, 1,0,0);
		glRotatef(90, 0,0,1);
		glScalef(radius * 1.005f, radius * 1.005f, radius * 1.005f);

		mat->activate(1, 0.3f);
		clouds->activate();
		geo->render();

		//glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		//glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
		//glutSolidSphere(radius * 1.005f,40,40);
		clouds->deactivate();

	glPopMatrix();
	
/*	glDisable(GL_TEXTURE_GEN_S);				
	glDisable(GL_TEXTURE_GEN_T);*/	
}