
//=============================================
// 
// Mercredi 12 decembre 2001
//  
// Arash Habibi
// 
// Objet.c
//
//============================================

#include <Objet.h>

//-------------------------------------------
//-------------------------------------------

void O_Check(objet_t o, char *commentaire) 
{
  fprintf(stderr," \n===== objet %s : %s ======\n", o.nom, commentaire);

  switch(o.type)
    {
    case O_SPHERE  : fprintf(stderr,"type : sphere\n");    S_Check(*((sphere_t*)  (o.forme)),""); break; 
    case O_PLAN    : fprintf(stderr,"type : plan\n");      P_Check(*((plan_t*)    (o.forme)),""); break; 
    case O_TRIANGLE: fprintf(stderr,"type : triangle\n"); TR_Check(*((triangle_t*)(o.forme)),""); break; 
    default : fprintf(stderr,"O_Check : type inconnu.\n");
    }
  C_Check(o.couleur, "couleur");
  PH_Check(o.surface, "surface");
}

//-------------------------------------------
//-------------------------------------------

void O_SetShape(objet_t *o, int type, void *forme)
{
  sphere_t   *sphere; 
  plan_t     *plan; 
  triangle_t *triangle; 

  o->type = type; 

  switch(type)
    {
    case O_SPHERE   : NEW(sphere,  1,  sphere_t); *sphere   =  *((sphere_t*)forme); o->forme = (void*)sphere;  break; 
    case O_PLAN     : NEW(plan,    1,    plan_t); *plan     =    *((plan_t*)forme); o->forme = (void*)plan;    break; 
    case O_TRIANGLE : NEW(triangle,1,triangle_t); *triangle =*((triangle_t*)forme); o->forme = (void*)triangle;break; 
    default : fprintf(stderr,"O_SetShape : type inconnu.\n");
    }
}  

//-------------------------------------------
//-------------------------------------------

void O_SetCouleur(objet_t *o, couleur_t couleur)
{
  o->couleur = couleur; 
}  

//-------------------------------------------
//-------------------------------------------

void O_SetSurface(objet_t *o, surface_t surface)
{
  o->surface = surface; 
}  

//-------------------------------------------
//-------------------------------------------

void O_SetNom(objet_t *o, char *nom)
{
  strcpy(o->nom, nom); 
}  

//-------------------------------------------
//-------------------------------------------

void O_IntersectRayon(objet_t o, rayon_t rayon, int *nb_points, vecteur_t *intersect, vecteur_t *normal)
{
  switch(o.type)
    {
    case O_SPHERE   :  S_IntersectRayon(*(  (sphere_t*)(o.forme)), rayon, nb_points, intersect, normal); break; 
    case O_PLAN     :  P_IntersectRayon(*(    (plan_t*)(o.forme)), rayon, nb_points, intersect, normal); break; 
    case O_TRIANGLE : TR_IntersectRayon(*((triangle_t*)(o.forme)), rayon, nb_points, intersect, normal); break; 
    default : fprintf(stderr,"O_IntersectDEmieDroite : %d type inconnu.\n", o.type);
    }
}




