#include "CGScene.h"
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "CGShaderProgram.h"
#include "CGFigure.h"
#include "CGLight.h"
#include "CGMaterial.h"
#include "CGCube.h"
#include "CGCone.h"
#include "CGCylinder.h"
#include "CGSphere.h"
#include "CGTorus.h"
#include "CGIcosahedron.h"
#include "CGGround.h"

//
// FUNCIÓN: CGScene::CGScene()
//
// PROPÓSITO: Construye el objeto que representa la escena
//
CGScene::CGScene()
{
    glm::vec3 Ldir = glm::vec3(1.0f, -0.8f, -1.0f);
    Ldir = glm::normalize(Ldir);
    light = new CGLight();
    light->SetLightDirection(Ldir);
    light->SetAmbientLight(glm::vec3(0.2f, 0.2f, 0.2f));
    light->SetDifusseLight(glm::vec3(0.8f, 0.8f, 0.8f));
    light->SetSpecularLight(glm::vec3(1.0f, 1.0f, 1.0f));

    matg = new CGMaterial();
    matg->SetAmbientReflect(0.0f, 0.6f, 0.0f);
    matg->SetDifusseReflect(0.0f, 0.6f, 0.0f);
    matg->SetSpecularReflect(0.8f, 0.8f, 0.8f);
    matg->SetShininess(16.0f);

    material = new CGMaterial();
    material->SetAmbientReflect(1.0f, 0.0f, 0.0f);
    material->SetDifusseReflect(1.0f, 0.0f, 0.0f);
    material->SetSpecularReflect(0.8f, 0.8f, 0.8f);
    material->SetShininess(4.0f);

    ground = new CGGround(50.0f, 50.0f);
    ground->SetMaterial(matg);

    fig0 = new CGCone(5, 20, 5.0f, 5.0f);
    fig0->SetMaterial(material);
    fig0->Translate(glm::vec3(25.0f, 5.0f, 25.0f));
    fig0->Rotate(-90.0f, glm::vec3(1.0f, 0.0f, 0.0f));

    fig1 = new CGCube(5.0f);
    fig1->SetMaterial(material);
    fig1->Translate(glm::vec3(-25.0f, 5.0f, 25.0f));
    fig1->Rotate(-90.0f, glm::vec3(1.0f, 0.0f, 0.0f));

    fig2 = new CGCylinder(20, 20, 5.0f, 5.0f);
    fig2->SetMaterial(material);
    fig2->Translate(glm::vec3(25.0f, 5.0f, 0.0f));
    fig2->Rotate(90.0f, glm::vec3(1.0f, 0.0f, 0.0f));

    fig3 = new CGTorus(20, 40, 3.0f, 5.0f);
    fig3->SetMaterial(material);
    fig3->Translate(glm::vec3(-25.0f, 8.0f, 0.0f));

    fig4 = new CGSphere(20, 40, 8.0f);
    fig4->SetMaterial(material);
    fig4->Translate(glm::vec3(25.0f, 8.0f, -25.0f));

    fig5 = new CGIcosahedron(5.0f);
    fig5->SetMaterial(material);
    fig5->Translate(glm::vec3(-25.0f, 8.0f, -25.0f));
}

//
// FUNCIÓN: CGScene3:~CGScene()
//
// PROPÓSITO: Destruye el objeto que representa la escena
//
CGScene::~CGScene()
{
    delete ground;
    delete fig0;
    delete fig1;
    delete fig2;
    delete fig3;
    delete fig4;
    delete fig5;
    delete light;
    delete matg;
    delete material;
}

//
// FUNCIÓN: CGScene::Draw()
//
// PROPÓSITO: Dibuja la escena
//
void CGScene::Draw(CGShaderProgram* program, glm::mat4 proj, glm::mat4 view)
{
    light->SetUniforms(program);

    ground->Draw(program, proj, view);
    fig0->Draw(program, proj, view);
    fig1->Draw(program, proj, view);
    fig2->Draw(program, proj, view);
    fig3->Draw(program, proj, view);
    fig4->Draw(program, proj, view);
    fig5->Draw(program, proj, view);
}