// system includes
#include <math.h>
#include <iostream.h>
#include <stdlib.h>

// openGL includes
#include <GL/gl.h>
#include <GL/glu.h>

// gprims utility library: need definition of max_flt, etc.
#include "gprims/vector.H"

// local includes
#include "drawutils.H"
#include "optfxn.H"
#include "object.H"
#include "bb.H"

Optfxn::Optfxn( Float3 *eqn ) {
  _eqn = new Float3(0.0,0.0,0.0);
  _sphere = new Sphere(0.02);
  setEqn(eqn);
}

int
Optfxn::setEqn( Float3 *eqn) {
  (*_eqn) = (*eqn);
  _eqn->normalize();
  (*_eqn) *= 0.1;
  _sphere->setPosition(*_eqn);
  return 1;
}

int
Optfxn::draw(BB *bb) {
  if (bb->insidePoint(_eqn)) {
    glBegin(GL_LINES);
    glColor3f(0.0,0.0,1.0);
    glVertex3f(0.0,0.0,0.0);
    glVertex3f(_eqn->x(), _eqn->y(), _eqn->z());
    glEnd();
    _sphere->draw(0.0,0.0,1.0);
    return 1;
  }
  return 0;
}
