#include <random.h>

#include <pointgrid3Dbilineardraw.h>

pointgrid3Dbilineardraw::pointgrid3Dbilineardraw
(
  pointgrid3D const & pg_
)
  : row(0), col(0), pg(pg_), mp(1,1)
{
  pointsdisplay=true;
  pointsperpatch=2000;

  quadric.radius = 0.02;
  quadric.slices=20;
  quadric.loops=6;

} 


void pointgrid3Dbilineardraw::update()
{
  nuke();

  push( new gobjglPushAttrib(GL_LIGHTING) );
  push( new gobjglPushAttrib(GL_CURRENT_BIT) );

  push(new gobjglDisable(GL_LIGHTING) );
    
  //push( new gobjglColor3ub(255,165,0) );

  random11<double> r;

  point3<double> p;

  push( new gobjglBegin(GL_POINTS) );

  row=0; 
  col=0;
  for (uint k=0; k+1<pg.N; ++k)
  {
    for (uint i=0; i+1<pg.M; ++i)
    {
//cout << SHOW(row) << " " << SHOW(col) << endl;

      push( new gobjglColor3ub(rand()%256,rand()%165,rand()%256) );

      for (uint a=0; a<pointsperpatch; ++a)
      {
        mp.eval(p,r(),r(),*this);
        push( new gobjglVertex3f(p) );
      }
      ++col;
    }
    ++row;
    col=0;
  }

/*
  for (uint i=0; i<pointsperpatch; ++i)
  {
    mp.eval(p,r(),r(),*this);
    push( new gobjglVertex3f(p) );
  }

  ++col;

  for (uint i=0; i<pointsperpatch; ++i)
  {
    mp.eval(p,r(),r(),*this);
    push( new gobjglVertex3f(p) );
  }
*/



  push( new gobjglEnd() );

  push( new gobjglPopAttrib() );
  push( new gobjglPopAttrib() );
}




