#ifndef TEST01OBJ_H
#define TEST01OBJ_H

#include <menu01.h>
#include <zpr.h>


typedef void pftessinit(d3tess & );


template< typename P, typename PD >
class test01obj : public myglutgui
{
public:

  zpr zz;

  menu01< test01obj<P,PD> > menu;

  gobjContainer xGraphics;

  d3tess * mesh;
  d3tessdraw *meshdraw;
  d3clipping *clip;

  d2partitiondraw< PD > * hdraw;

  test01obj
  (
    pftessinit tessinit, 
    P * cp,
    int & argc, 
    char** & argv,
    uintc mode,
    uintc x,
    uintc y,
    string const & title
  )
    : myglutgui(argc,argv,mode,x,y,title), menu(*this)
  {
    set();

    xGraphics.set();

    unsigned int N(1000);
    mesh = new d3tess(N);
    assert(tessinit!=0);
    (*tessinit)(*mesh);

    meshdraw = new d3tessdraw(*mesh);
    meshdraw->graphicsDeffered.v[d3tessdraw::multicolor]->isdrawn = true;
    meshdraw->graphicsDeffered.v[d3tessdraw::points]->isdrawn = true;
    meshdraw->graphicsDeffered.v[d3tessdraw::simplexes]->isdrawn = true;
    meshdraw->meshupdate();

    xGraphics.push_back(new gobjglPushMatrix());
    xGraphics.push_back(& menu.meshAoffset);

    xGraphics.push_back(meshdraw);

    xGraphics.push_back(new gobjglPopMatrix());

    clip = new d3clipping(*mesh,*cp);
    clip->zero = 1.0e-10;

    hdraw = new d2partitiondraw<PD>(*new PD(*cp));
    xGraphics.push_back(hdraw);
//cout << SHOW(xGraphics.vg.size()) << endl;
  }

  void keyboard(unsigned char key, int x, int y)
    { menu.read(key); }

  void display()
  {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    menu.draw();

    xGraphics.draw();

    glerrordisplay();
    glutSwapBuffers();
  }

  void eval()
  {
    OpenGLinitialisation();
  
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);

    xGraphics.set();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt
    (
      3.0,0.0,6.0,  // Eye
      3.0,0.0,0.0,  // Center
      0.0,1.0,0.0   // Up
    );

    zz.update();


    glutPostRedisplay();
  }

};



#endif




