#include "Maze.h"

#include <GL/glew.h>

#include "GL/glus.h"
#include "../vsgl3/glHelper.h"

class Maze2DGraphics : public IGraphicsObject
{
public:

  Maze2DGraphics(float a_halfSize, float a_texMult);
  ~Maze2DGraphics();

  void draw(float4x4 worldViewMatrix, float4x4 projectionMatrix) const;
  void translate(float3 a_pos) { }
  void rotateY(float angle) { }

protected:

  ShaderProgram* m_pProgram;
  SimpleMesh*    m_pLandMesh;
  Texture2D*     m_pSnowTex;

};


Maze2DGraphics::Maze2DGraphics(float a_halfSize, float a_texMult)
{
  m_pProgram  = new ShaderProgram("../main/Vertex.vert", "../main/Fragment.frag");
  m_pLandMesh = new SimpleMesh(m_pProgram->program, 2, SimpleMesh::PLANE, a_halfSize, a_texMult);
  m_pSnowTex  = new Texture2D("../data/checker.bmp");
}


Maze2DGraphics::~Maze2DGraphics()
{
  delete m_pSnowTex;  m_pSnowTex  = NULL;
  delete m_pLandMesh; m_pLandMesh = NULL;
  delete m_pProgram;  m_pProgram  = NULL;
}


void Maze2DGraphics::draw(float4x4 worldViewMatrix, float4x4 projectionMatrix) const
{
  float4x4 rotationMatrix, scaleMatrix, translateMatrix;
  float4x4 transformMatrix1;

  glusRotateRzRyRxf(rotationMatrix.L(), -90, 0.0f, 0.0f);
  glusScalef(scaleMatrix.L(), 10, 10, 10);
  glusMultMatrixf(transformMatrix1.L(), rotationMatrix.L(), scaleMatrix.L());

  glUseProgram(m_pProgram->program);

  setUniform(m_pProgram->program, "worldViewMatrix", worldViewMatrix);
  setUniform(m_pProgram->program, "projectionMatrix", projectionMatrix);  // set matrix we have calculated in "reshape" funtion
  setUniform(m_pProgram->program, "objectMatrix", transformMatrix1);

  bindTexture(m_pProgram->program, 1, "diffuseTexture", m_pSnowTex->GetColorTexId());

  m_pLandMesh->Draw();
}



IGraphicsObject* CreateMazeGraphics(float a_halfSize, float a_texMult)
{
  return new Maze2DGraphics(a_halfSize, a_texMult);
}









