#include <stdio.h>

#include "Relief.h"
#include "coordonn.h"
#include "filetype.h"
#include "x3D.h"

#define UNREFERENCED_PARAMETER(P) (P)

/* ************************************************************************ */

void fillpolyX3D(FILE *texte,int type_valeurs,int n,double *p,coord_3D *normale,char *rl) {
  UNREFERENCED_PARAMETER(n);
  UNREFERENCED_PARAMETER(normale);
  sauvegarde_facette_X3D_4(texte,(double) p[0],(double) p[1],(double) p[2],(double) p[3],(double) p[4],(double) p[5],(double) p[6],(double) p[7],(double) p[8],(double) p[9],(double) p[10],(double) p[11],type_valeurs,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_entete_X3D(FILE *texte,char *rl) {
  fprintf(texte,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>%s<X3D profile=\"Immersive\">%s  <Scene>%s    <Viewpoint position='0.0 150.0 0.0' orientation='0.0 1.0 0.0 1.5708' fieldOfView='0.80'/>%s",rl,rl,rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_X3D(FILE *texte,char *rl) {
  fprintf(texte,"  </Scene>%s</X3D>%s",rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_debut_IndexedFaceSet_X3D(FILE *texte,char *rl)
  { fprintf(texte,"    <Shape containerField='children'>%s      <Appearance containerField='appearance'>%s        <Material ambientIntensity='0.000'%s                  containerField='material'%s                  diffuseColor='0.8 0.8 0.8'%s                  specularColor='0.1 0.1 0.1'%s                  shininess='0.500'%s                  transparency='0.000'/>%s      </Appearance>%s      <IndexedFaceSet coordIndex='%s        ",rl,rl,rl,rl,rl,rl,rl,rl,rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_suite_IndexedFaceSet_X3D(FILE *texte,char *rl)
  { fprintf(texte,"'%s                      normalIndex='%s        ",rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_IndexedFaceSet_X3D(FILE *texte,char *rl)
  { fprintf(texte,"      </IndexedFaceSet>%s    </Shape>%s",rl,rl);
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_noeud_X3D(FILE *texte,char *rl)
  { fprintf(texte,"          '>%s",rl);
}
/* ------------------------------------------------------------------------ */
void ecrit_debut_Normal_X3D(FILE *texte,char *rl)
  { fprintf(texte,"        <Normal vector='%s",rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_Normal_X3D(FILE *texte,char *rl)
  { fprintf(texte,"        </Normal>%s",rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_Coordinate_X3D(FILE *texte,char *rl)
  { fprintf(texte,"        </Coordinate>%s",rl) ;
}
/* ------------------------------------------------------------------------ */
void sauvegarde_intermIFS_X3D_3(FILE *texte,char *rl)
  { fprintf(texte,"'%s                      creaseAngle='1.500'>%s        <Coordinate point='%s",rl,rl,rl);
}
/* ------------------------------------------------------------------------ */
void sauvegarde_indexe_X3D_3(FILE *texte,int *n)
  { fprintf(texte,"%d %d %d -1 ",n[0],n[1],n[2]) ;
}
/* ------------------------------------------------------------------------ */
void sauvegarde_indexe_X3D_3(FILE *texte,int *n,char *rl)
  { fprintf(texte,"%d %d %d -1%s        ",n[0],n[1],n[2],rl) ;
}
/* ------------------------------------------------------------------------ */
void sauvegarde_sommet_X3D_3(FILE *texte,struct coord_4D *c,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"          %d %d %d%s",(int) c->x,(int) c->y,(int) c->z,rl) ;
        break ;
      case FileType::REELS  :
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf%s",c->x,c->y,c->z,rl) ;
        break ; }
}
/* ------------------------------------------------------------------------ */
void sauvegarde_sommet_X3D_3(FILE *texte,struct coord_3D_court *c,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"          %d %d %d%s",(int) c->x,(int) c->y,(int) c->z,rl) ;
        break ;
      case FileType::REELS  :
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf%s",c->x,c->y,c->z,rl) ;
        break ; }
}
/* ------------------------------------------------------------------------ */
void sauvegarde_sommet_X3D_3(FILE *texte,struct coord_3D *c,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"          %d %d %d%s",(int) c->x,(int) c->y,(int) c->z,rl) ;
        break ;
      case FileType::REELS  :
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf%s",c->x,c->y,c->z,rl) ;
        break ; }
}
/* ------------------------------------------------------------------------ */
void sauvegarde_facette_X3D_3(FILE *texte,double x1,double z1,double y1,double x2,double z2,double y2,double x3,double z3,double y3,int type_valeurs,char *rl)
  { fprintf(texte,"    <Shape containerField='children'>%s      <Appearance containerField='appearance'>%s        <Material ambientIntensity='0.000'%s                  containerField='material'%s                  diffuseColor='0.8 0.8 0.8'%s                  specularColor='0.1 0.1 0.1'%s                  shininess='0.500'%s                  transparency='0.000'/>%s      </Appearance>%s      <IndexedFaceSet coordIndex='0 1 2 -1'%s                      creaseAngle='1.500'>%s        <Coordinate point='%s",rl,rl,rl,rl,rl,rl,rl,rl,rl,rl,rl,rl) ;
    switch ( type_valeurs ) {
      case FileType::ENTIERS : 
        fprintf(texte,"          %d %d %d,%s",(int) x1,(int) y1,(int) z1,rl) ;
        fprintf(texte,"          %d %d %d,%s",(int) x2,(int) y2,(int) z2,rl) ;
        fprintf(texte,"          %d %d %d,%s",(int) x3,(int) y3,(int) z3,rl) ;
        break ;
      case FileType::REELS  :
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x1,y1,z1,rl) ;
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x2,y2,z2,rl) ;
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x3,y3,z3,rl) ;
        break ; }
    fprintf(texte," '>%s        </Coordinate>%s      </IndexedFaceSet>%s    </Shape>%s",rl,rl,rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void sauvegarde_facette_X3D_4(FILE *texte,double x1,double z1,double y1,double x2,double z2,double y2,double x3,double z3,double y3,double x4,double z4,double y4,int type_valeurs,char *rl)
  { fprintf(texte,"    <Shape containerField='children'>%s      <Appearance containerField='appearance'>%s        <Material ambientIntensity='0.000'%s                  containerField='material'%s                  diffuseColor='0.8 0.8 0.8'%s                  specularColor='0.1 0.1 0.1'%s                  shininess='0.500'%s                  transparency='0.000'/>%s      </Appearance>%s      <IndexedFaceSet coordIndex='0 1 2 3 -1'%s                      creaseAngle='1.500'>%s        <Coordinate point='%s",rl,rl,rl,rl,rl,rl,rl,rl,rl,rl,rl,rl) ;
    switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"          %d %d %d,%s",(int) x1,(int) y1,(int) z1,rl) ;
        fprintf(texte,"          %d %d %d,%s",(int) x2,(int) y2,(int) z2,rl) ;
        fprintf(texte,"          %d %d %d,%s",(int) x3,(int) y3,(int) z3,rl) ;
        fprintf(texte,"          %d %d %d,%s",(int) x4,(int) y4,(int) z4,rl) ;
        break ;
      case FileType::REELS  :
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x1,y1,z1,rl) ;
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x2,y2,z2,rl) ;
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x3,y3,z3,rl) ;
        fprintf(texte,"          %10.5lf %10.5lf %10.5lf,%s",x4,y4,z4,rl) ;
        break ; }
    fprintf(texte," '>%s        </Coordinate>%s      </IndexedFaceSet>%s    </Shape>%s",rl,rl,rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void debut_facette_X3D(FILE *texte,int type_valeurs,char *rl)
  { switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        break ;
      case FileType::REELS  :
        fprintf(texte,"0%s3DFACE%s8%sSV3D%s",rl,rl,rl,rl) ;
        break ; }
}
/* ------------------------------------------------------------------------ */
void sommet_facette_X3D(FILE *texte,double x1,double z1,double y1,int n,int type_valeurs,char *rl)
  { char sn1[8],sn2[8],sn3[8] ;
    sprintf(sn1,"%d",10+n) ;
    sprintf(sn2,"%d",20+n) ;
    sprintf(sn3,"%d",30+n) ;
    switch ( type_valeurs ) {
      case FileType::ENTIERS :
        fprintf(texte,"%s%s%d%s%s%s%d%s%s%s%d%s",sn1,rl,(int) x1,rl,sn2,rl,(int) y1,rl,sn3,rl,(int) z1,rl) ;
        break ;
      case FileType::REELS  : fprintf(texte,"%s%s%lf%s%s%s%lf%s%s%s%lf%s",sn1,rl,x1,rl,sn2,rl,y1,rl,sn3,rl,z1,rl) ;
        break ; }
}

/* ************************************************************************ */
