//
//  Grid.h
//  prog2
//
//  Created by Neil Killeen on 5/9/13.
//  Copyright (c) 2013 Neil Killeen. All rights reserved.
//

#ifndef __prog2__Grid__
#define __prog2__Grid__

#include "Angel.h"
#include "Mesh.h"
#include "Grid.h"
#include <iostream>
#include <vector>

#define round(x) ((x)>=0?(int)((x)+0.5):(int)((x)-0.5))

using namespace Angel;
using std::vector;

struct Node {
    Node();
    
    bool filled;
    color4 color;
};

class Grid {
public:
    Grid(unsigned width, unsigned height, unsigned depth);
    void Resize(unsigned width, unsigned height, unsigned depth);
    bool CheckLose();
    void CheckLines();
    void Clear();
    bool InBounds(const point3 &position) const; // Checks if position is in bounds.
    void drawAll(GLuint &program, GLuint &vPos, GLuint &vNormal, GLuint &ModelView);
    
    void setNode(vec3 position, color4 color, bool filled = true);
    void setLock(bool that) { lock = that; }
    
    Node* getElement(unsigned x, unsigned y, unsigned z);
    Node* getElement(const vec3& position);
    vec3 getStartPos() const { return start_pos; }
    unsigned getWidth() const { return width; }
    unsigned getHeight() const { return height; }
    unsigned getDepth() const { return depth; }
    bool getLock() const { return lock; }
    
private:
    void Initialize(unsigned width, unsigned height, unsigned depth);
    Grid(); // disable
    
    bool lock;
    unsigned width;
    unsigned height;
    unsigned depth;
    vec3 start_pos;
    int piece_speed;
    
    Mesh grid;
    Mesh cube;
    vector<vector<vector<Node> > > Elements;
};

#endif /* defined(__prog2__Grid__) */
