// This is light.cc CVS version: $Id: light.cc,v 1.2 2000/02/28 18:06:24 andreaha Exp $
#include "eng.h"

/************************************************************************/
/* World::Light                                                         */
/************************************************************************/

/* light contructor */
World::Light::Light(float i, float red, float green, float blue) {
  dpush5("World::Light::Light(%3.1f,%3.1f,%3.1f,%3.1f)",i,red,green,blue);

  strcpy(name, "unnamed light");

  matrix.genIdentity();

  parent = NULL;
  range = i;
  color.set(red, green, blue);
  on = TRUE;

  pos.reset();
  posr.reset();

  dpop();
}

/* light destructor */
World::Light::~Light() {
  dpush1("World::Light::~Light()");

  dpop();
}

/* set values */
void World::Light::set(float red, float green, float blue) {
  dpush4("World::Light::set(%3.1f,%3.1f,%3.1f)",red,green,blue);

  color.set(red, green, blue);

  dpop();
}

/* create matrix */
void World::Light::createMatrix() {
  dpush1("World::Light::createMatrix()");

  matrix.genTranslationWith(pos.x, pos.y, pos.z);

  if (parent == NULL)
    matrix.mulWith(&myworld->activecamera->matrix);
  else {
    if (!parent->donematrix) 
      parent->createMatrix();
    matrix.mulWith(&parent->matrix);
  }

  dpop();
}

/* print light info */
void World::Light::printOut() {
  dpush1("World::Light::printOut()");

  print2("Light [%#010x] printout:\n", (int)this);
  print4("  Color: r = %6.2f, g = %6.2f, b = %6.2f\n", color.r, color.g, color.b);
  print2("  Range: %6.2f\n", range);
  print4("  Position: (%6.2f, %6.2f, %6.2f)\n", pos.x, pos.y, pos.z);
  dpop();
}

