/* Rayon lumineux                               */
/*                                              */
/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Mars 2014                                    */

#include "RayonLumineux.h"
#include "Pos3D.h"
#include "Dir3D.h"

RayonLumineux::RayonLumineux(void) {
  origine = new Pos3D();
  direction = new Dir3D();
}

RayonLumineux::RayonLumineux(Pos3D *o,Dir3D *d) {
  origine = new Pos3D(o);
  direction = new Dir3D(d);
}

RayonLumineux::RayonLumineux(RayonLumineux *rl) {
  origine = new Pos3D(rl->origine);
  direction = new Dir3D(rl->direction);
}

RayonLumineux::~RayonLumineux(void) {
  delete(origine);
  delete(direction);
}

void RayonLumineux::print(void) {
}

void RayonLumineux::rayonReflechi(RayonLumineux *rr,Pos3D *p,Dir3D *n) {
  *(rr->origine) = *p;
  Dir3D i(-direction->x,-direction->y,-direction->z);
  rr->direction->reflexion(&i,n);
}

int RayonLumineux::rayonTransmis(RayonLumineux *rt,Pos3D *p,Dir3D *n,
                                 float niSurnt,int exterieur) {
  *(rt->origine) = *p;
  Dir3D *norm = new Dir3D(n);
  if ( !exterieur ) {
    norm->x *= -1;
    norm->y *= -1;
    norm->z *= -1; }
  Dir3D *i = new Dir3D(direction);
  i->x *= -1;
  i->y *= -1;
  i->z *= -1;
  int res = rt->direction->transmission(i,norm,niSurnt);
  delete(i);
  delete(norm);
  return(res);
}
