/* -*-ePiX-*- */
#include "epix.h"
using namespace ePiX;

const double ht(4);

const P target(0,0,0);
const P observer(0,-4,0);
const P dtarg(-0.5,0,1);
const double dx(0.375);

// location of label
const P obj_loc(1,0,0.25);

P F(P arg)
{
  double x(arg.x2());
  return (ht/(ht+x))*P(arg.x1(), 0, arg.x3());
}

P P1(0.75, -1,    -0.25);
P P2(1,    -1.25, -0.75);
P P3(0.5,  -1.5,  -0.5 );
P midpt((1.0/3)*(P1+P2+P3));

int main() {
  bounding_box(P(-3.5,-3.5),P(3.5,2.5));
  unitlength("0.375in");
  picture(P(7,6));

  begin();

  camera.at(P(1.5,-10,3.5));
  camera.range(10);

  font_size("footnotesize");
  right_angle(target, E_1, -E_2);

  line(target, target+2*dx*E_1);
  line(target, target+2*dx*E_3);

  //  grid(P(-3,0,-2), P(3,0,2), 6, 8);
  grid(P(-3,0,-2), P(3,0,2));

  masklabel(observer+E_1, P(2,0), "\\textbf{Sea}", r);
  masklabel(observer+E_3, P(0,2), "\\textbf{Sky}", t);
  masklabel(observer-E_2, P(-4,0), "\\textbf{Eye}", l);

  masklabel(observer, P(-2,0), "Viewpoint", l);
  dot(observer);

  masklabel(P(3,0,2), P(-6,-2), "Canvas", bl);

  line(observer, target);

  fill(Black(0.5));
  triangle(F(P1), F(P2), F(P3));

  line(P1, F(P1));
  line(P2, F(P2));
  line(P3, F(P3));

  line(observer, F(P1));
  line(observer, F(P2));
  line(observer, F(P3));

  fill(Black(0.1));
  triangle(P1, P2, P3);

  line(obj_loc, midpt);
  masklabel(obj_loc, P(0,0), "Object", t);

  line(P(2,0,-1), F(midpt));
  masklabel(P(2,0,-1), P(0,0), "Shadow", r);

  masklabel(target+dtarg, P(0,0), "Target", t);
  arrow(target+dtarg, target+0.1*dtarg, 0.5);
  dot(target);

  bold();
  arrow(observer, observer+E_1, 0.5);
  arrow(observer, observer-E_2, 0.5);
  arrow(observer, observer+E_3, 0.5);

  end();
}
