#include <GL/gl.h>
#include "World.h"
#include "Player.h"
#include <string>
#include "Model.h"


World* World::instance = nullptr;


World::World()
{
    objects[0].position = Vec3f(GridSizeX*SizeX/2,-5,GridSizeY*SizeY/2);
    objects[0].scale = 200;

    objects[1].position = Vec3f(30,-5,30);
    objects[1].scale = 2;
    objects[1].text = "Gebruiker invloed met Z en X";

    objects[2].position = Vec3f(40,-5,30);
    objects[2].scale = 2;
    objects[2].text = "Stil staand object";

    objects[3].position = Vec3f(50,-5,30);
    objects[3].scale = 2;
    objects[3].text = "Nog een stil staand object";

    objects[4].position = Vec3f(60,-5,30);
    objects[4].scale = 2;
    objects[4].text = "Automatisch bewegend object";

    randomobject.position = Vec3f(70,-5,30);
    randomobject.text = "Door computer gegenereerd";
    randomobject.scale = 2;

    entity.model = Model::load("models/Bob.obj");
    entity.position = Vec3f(80, -5, 30);
    entity.text = "Een model ingeladen";

   entity2.model = Model::load("models/IronMan.obj");
    entity2.position = Vec3f(100, -5, 30);
    entity2.scale = 1;
    entity2.text = "Nog een model ingeladen";

}

World::~World()
{

}

World* World::getInstance()
{
	if (instance == nullptr)
		instance = new World();

	return instance;
}

void World::init()
{
	instance = new World();
}

void World::draw(void) {
    Player::getInstance()->setCamera();


    Player::getInstance()->draw();

    for (unsigned int x = 0; x < GridSizeX; ++x){
        for (unsigned int y = 0; y < GridSizeY; ++y) {
            glBegin(GL_QUADS);
            if ((x+y)&0x00000001) //modulo 2
                glColor3f(1.0f,1.0f,1.0f); //white
            else
                glColor3f(0.0f,0.0f,0.0f); //black
            glVertex3f(x*SizeX, -10, y*SizeY);
            glVertex3f((x+1)*SizeX, -10, y*SizeY);
            glVertex3f((x+1)*SizeX, -10, (y+1)*SizeY);
            glVertex3f(x*SizeX, -10, (y+1)*SizeY);
            glEnd();
        }
    }

    for(auto e:objects)
        e.draw();

    randomobject.draw();
    entity.draw();
}

void World::update(float deltaTime)
{
    objects[4].rotation.x += 20*deltaTime;
    objects[0].rotation.x += 20*deltaTime;
}