#include "ZGo.h"



//---- ZGoCAMERA -------------------------------------------------------------//

ZGoCAMERA::ZGoCAMERA(ZGo *zgo)
{
  this->zgo = zgo;

  trans = new ZGoMATRIX(zgo);
  trans->shiftMatrix(0, 0, 0);
}



void ZGoCAMERA::screenSpace(ZGoIMAGE *im, ZGoMATRIX *m, float(*point)[3], float(*tpoint)[3], int points)
{
  float cx = im->w * 0.5;
  float cy = im->h * 0.5;
  float scale = cy;

  ZGoMATRIX *objm = new ZGoMATRIX(zgo, m, trans);

  for(int i=0; i<points; i++)
  {
    //  Transform point

    tpoint[i][0] = point[i][0]*objm->m00 + point[i][1]*objm->m01 + point[i][2]*objm->m02 + objm->m03;
    tpoint[i][1] = point[i][0]*objm->m10 + point[i][1]*objm->m11 + point[i][2]*objm->m12 + objm->m13;
    tpoint[i][2] = point[i][0]*objm->m20 + point[i][1]*objm->m21 + point[i][2]*objm->m22 + objm->m23;

    //  Screen point

    float d = 1.0 / sqrt
              (
                tpoint[i][0]*tpoint[i][0] +
                tpoint[i][1]*tpoint[i][1] +
                tpoint[i][2]*tpoint[i][2]
              );

    tpoint[i][2] = 1.0 / tpoint[i][2];

//    d = tpoint[i][2];

    tpoint[i][0] = cx + scale * tpoint[i][0] * d;
    tpoint[i][1] = cy + scale * tpoint[i][1] * d;
  }

  delete objm;
}



//---- end of file -----------------------------------------------------------//
