#include <cmath>
using namespace std;

#include <plotpolar.h>

#define PI 3.14159265359

void plotpolar::adddatapointsinPolarRadians
( 
  vector< point2<double> > const & p 
)
{
  pts.clear();

  uintc sz = p.size();
  for (uint i=0; i<sz; ++i)
  {
    point2<double> const & z(p[i]);
    // Convert the polar coordinates to cartesian coordinates.
    pts.push_back( point2<double>(z.x*cos(z.y), z.x*sin(z.y)) );
  }
}


void plotpolar::adddatapointsinPolarDegrees
( 
  vector< point2<double> > const & p 
)
{
  pts.clear();

  double t;
  uintc sz = p.size();
  for (uint i=0; i<sz; ++i)
  {
    point2<double> const & z(p[i]);
    // Convert degrees to polar coordinates.
    t = z.y * PI / 180.0;
    // Convert polar to cartesian coordinates.
    pts.push_back( point2<double>(z.x*cos(t), z.x*sin(t)) );
  }
}



void plotpolar::addpoints
(
  uintc r, 
  uintc g, 
  uintc b
)
{
  gobjContainer * c = new gobjContainer();

  c->push( new gobjglPushAttrib(GL_CURRENT_BIT) );
  c->push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
  c->push( new gobjglDisable(GL_LIGHTING) );

  c->push( new gobjglColor3ub(r,g,b) );


  uintc sz = pts.size();
 
  c->push( new gobjglBegin(GL_POINTS) );
  for (uint i=0; i<sz; ++i)
  {
    c->push( new gobjglVertex2f(pts[i]) );
  }

  c->push(new gobjglEnd());

  c->push( new gobjglPopAttrib() );
  c->push( new gobjglPopAttrib() );

  push(c);
}

void plotpolar::addcrosses
(
  uintc r,  
  uintc g, 
  uintc b,
  doublec crosshairlength
)
{
  gobjContainer * c = new gobjContainer();

  c->push( new gobjglPushAttrib(GL_CURRENT_BIT) );
  c->push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
  c->push( new gobjglDisable(GL_LIGHTING) );

  c->push( new gobjglColor3ub(r,g,b) );

  uintc sz = pts.size();

  doublec h = crosshairlength / 2.0;
 
  c->push( new gobjglBegin(GL_LINES) );
  for (uint i=0; i<sz; ++i)
  {
    point2<double> const & x(pts[i]);
    c->push( new gobjglVertex2f(x.x,x.y+h) );
    c->push( new gobjglVertex2f(x.x,x.y-h) );
    c->push( new gobjglVertex2f(x.x+h,x.y) );
    c->push( new gobjglVertex2f(x.x-h,x.y) );
  }

  c->push(new gobjglEnd());

  c->push( new gobjglPopAttrib() );
  c->push( new gobjglPopAttrib() );

  push(c);
}






    



