#pragma once
#include "ED_Engine.h"

class EDE_GridSceneNode : public ISceneNode
{

    private:
		/////////////////
		// The Grid Cells
		/////////////////
		class Cell
		{
			private:
				IDynamicMeshBuffer* meshBuffer;
				bool visible;
				vector3df topLeft, topRight, bottomLeft, bottomRight, center;
				int id;
				SMaterial Material;

				void setDefaultMaterial();

			public:
				Cell();
				Cell(vector3df topLeft, vector3df topRight, vector3df bottomLeft, vector3df bottomRight, int id, bool visible, SMaterial material);
				~Cell();

				void RenderCell(IVideoDriver* driver, SColor color);
		};

		///////////
		// The Grid
		///////////
		vector3df gridPos;
		float cellSize;
		int width, height;
		Cell** gridCells;
		SColor color;

		aabbox3d<f32> Box;
		SMaterial Material;
	public:
		EDE_GridSceneNode(ISceneNode* parent, ISceneManager* smgr, s32 id = -1);

		void init( int width, int height, SColor color, vector3df gridPos = vector3df(0.0f, 0.0f, 0.0f), float cellSize = 1.0f);

		void createGridFlat();
		void createGridOnTerrain(ITerrainSceneNode* terrainSceneNode);

		void renderGrid(IVideoDriver* driver, SColor color);

		virtual void OnRegisterSceneNode();
		virtual void render();
		virtual const core::aabbox3d<f32>& getBoundingBox() const;
		virtual u32 getMaterialCount() const;
		virtual video::SMaterial& getMaterial(u32 i);
};