#include <GL/glut.h>
#include <GL/gl.h>

#include <gobj.h>
#include <graphmisc.h>
#include <plotpolartest.h>
#include <zpr.h>


void plotpolartest::keyboard01
(
  unsigned char key, 
  int x, 
  int y
)
{
  switch (key)
  {
    case 27: exit(0); break;
  }
}


void plotpolartest::display01()
{ 
  myglPushMatrixMode temp;
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  assert(gobj::global!=0);
  gobj::global->draw();

  glerrordisplay();
  
  glutSwapBuffers();
}


int plotpolartest::test01(int argc, char** & argv)
{
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  uintc wx=800;
  uintc wy=800;

  glutInitWindowSize(wx,wy);

  glutCreateWindow("");

  glutDisplayFunc(display01);
  glutKeyboardFunc(keyboard01);

  OpenGLinitialisation();

  glEnable(GL_DEPTH_TEST);
  glEnable(GL_CULL_FACE);

  xGraphics.set();


  //  Create the heart plot of points.

  vector< point2<double> > v;
 
  uintc n=50;
  // The degrees are converted to radians.
  double dt = PI * 2.0 / n;

  for (uint i=0; i<n; ++i)
  {
    v.push_back( point2<double>(1.0+cos(dt*i),dt*i) );
    //v.push_back( point2<double>(1.0,dt*i) );
  }

  plotpolar * plt = new plotpolar();
  plt->adddatapointsinPolarRadians(v);
  //plt->addpoints(255,0,0);
  plt->addcrosses(0,255,0,0.05);
  xGraphics.push(plt);

  protractor * prot = new protractor(2.5);
  prot->addAxes(8);
  prot->addCircles(5);

  stringc nms[] = 
  { 
    "0", "45", "90", "135", "180", 
    "225", "270", "315" 
  };
  vector<string> ang(nms,nms+8);

  prot->addCirclesText(ang);

  prot->addRadiusRuler(0.15, 0.1, 0.05);

  prot->addAngleRuler(0.15, 0.1, 0.05);
  
  
  xGraphics.push(prot);

  zpr zz;

  zz.update();
  glutMainLoop();


  
  return 0; 
}



