#ifndef SCENE_H
#define SCENE_H

#include <string>
#include "object.h"
#include "mesh.h"
#include "utils.h"

using namespace std;

class Scene
{
public:
    friend class GLView;

    Scene()
    {
        _camera.setFovY(M_PI/3.);
        _camera.lookAt(Vector3f(0, 0.01, 1).normalized()*2, Vector3f(0, 0, 0), Vector3f::UnitY());
    }

protected:
    Object openObject(const string path)
    {
        Mesh *mesh = new Mesh(path);
        Object obj;
        obj.attachShader(&_program);
        obj.attachMesh(mesh);
        return obj;
    }

    void loadShaders() { _program.load_from_files(VERTEX_SHADER, FRAGMENT_SHADER); }
    virtual void init()
    {
        _frame = openObject(OBJECT_FRAME);
        _frame.setRenderType(2);
    }

public:
    vector<Object> _objs;

protected:
    Object _frame;
    static Shader _program;
    static Camera _camera;
};



/******** SCENE 1 ********/
class Scene1 : public Scene
{
public:
    Scene1()
        : Scene()
    {
        init();
    }

private:
    virtual void init()
    {
        // init parent
        Scene::init();

        // object
        Object obj = openObject(OBJECT_BOX);
        obj.setRenderType(1);
        _objs.push_back(obj);
    }
};

/******** SCENE 2 ********/
class Scene2 : public Scene
{
public:
    Scene2()
        : Scene()
    {
        init();
    }

private:
    virtual void init()
    {
        // init parent
        Scene::init();

        // object
        Object obj = openObject(OBJECT_BOX);
        obj.setRenderType(3);
        obj.setId(0.5);
        _objs.push_back(obj);
    }
};

/******** SCENE 3 ********/
class Scene3 : public Scene
{
public:
    Scene3()
        : Scene()
    {
        init();
    }

private:
    virtual void init()
    {
        // init parent
        Scene::init();
        _camera.lookAt(Vector3f(0, 0.01, 1).normalized()*5, Vector3f(0, 0, 0), Vector3f::UnitY());

        // object 1
        Object obj1 = openObject(OBJECT_BOX);
        obj1.setRenderType(3);
        obj1.setId(0);
        obj1.setTranslation(Translation3f(1, -1, 0));
        _objs.push_back(obj1);

        // object 2
        Object obj2 = openObject(OBJECT_BOX);
        obj2.setRenderType(3);
        obj2.setId(0.5);
        obj2.setTranslation(Translation3f(-1, -1, 0));
        _objs.push_back(obj2);

        // object 3
        Object obj3 = openObject(OBJECT_BOX);
        obj3.setRenderType(3);
        obj3.setId(0.75);
        obj3.setTranslation(Translation3f(1, 1, 0));
        _objs.push_back(obj3);

        // object 4
        Object obj4 = openObject(OBJECT_BOX);
        obj4.setRenderType(3);
        obj4.setId(1);
        obj4.setTranslation(Translation3f(-1, 1, 0));
        _objs.push_back(obj4);
    }
};

#endif // SCENE_H
