#include <buttonpanel01.h>

buttonpanel01::buttonpanel01(zprmouse* zm_)
  : zm(zm_)
{
  radiussphere=0.025;
  centerdelta=0.03;

  point2<double> center = point2<double>(0.9,0.2);

  for (uint i=0; i<4; ++i)
    pos[i]=center;
  pos[0].y += centerdelta;
  pos[1].x += centerdelta;
  pos[2].y -= centerdelta;
  pos[3].x -= centerdelta;

  for (uint i=0; i<4; ++i)
    color[i] = point3<uint>(239,151,255);
}

void buttonpanel01::update()
{
  assert(zm);
  if (zm==0)
    return;

  for (uint i=0; i<4; ++i)
  {
    posw[i] = zm->world(pos[i]);
    posw[i].z += -1.0;
//    posw[i].z -= zm->zz.zFar;
//    posw[i].z *= 0.5;
cout << "posw[" << i << "]=" << posw[i] << endl;
  }

  point3<double> diff = posw[0] - posw[2];
  double radius2 = diff.dot();
  radiusworld = sqrt(radius2) * radiussphere * 0.5 / centerdelta;
}

void buttonpanel01::draw()
{
  update();

  glPushAttrib(GL_CURRENT_BIT);

  for (uint i=0; i<4; ++i)
  {
    glColor3ui(color[i].x,color[i].y,color[i].z);

    glPushMatrix();
    glTranslated(posw[i].x,posw[i].y,posw[i].z);
    glutSolidSphere(radiusworld,35,35);
    glPopMatrix();
  }

  glPopAttrib();
}


