#include <stdio.h>

#include "Relief.h"
#include "coordonn.h"
#include "FileType.h"
#include "vrml.h"

#define UNREFERENCED_PARAMETER(P) (P)

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

void fillpolyVRML(FILE *texte,int type_valeurs,int n,double *p,coord_3D *normale,char *rl) {
  UNREFERENCED_PARAMETER(n);
  UNREFERENCED_PARAMETER(normale);
  sauvegarde_facette_VRML_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_VRML(FILE *texte,char *rl) {
  fprintf(texte,"#VRML V1.0 ascii%sSeparator {%s",rl,rl) ;
}
/* ------------------------------------------------------------------------ */
void ecrit_fin_VRML(FILE *texte,char *rl) {
  fprintf(texte,"}%s",rl) ;
}
/* ------------------------------------------------------------------------ */
void sauvegarde_facette_VRML_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,"Coordinate3 {%s  point [%s",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,"    %lf %lf %lf,%s",x1,y1,z1,rl) ;
        fprintf(texte,"    %lf %lf %lf,%s",x2,y2,z2,rl) ;
        fprintf(texte,"    %lf %lf %lf,%s",x3,y3,z3,rl) ;
        break ; }
    fprintf(texte," ] }%s",rl) ;
    fprintf(texte,"IndexedFaceSet {%s  coordIndex [%s    0, 1, 2, -1 ] }%s",rl,rl,rl);    
}
/* ------------------------------------------------------------------------ */
void sauvegarde_facette_VRML_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,"Coordinate3 {%s  point [%s",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,"    %lf %lf %lf,%s",x1,y1,z1,rl) ;
        fprintf(texte,"    %lf %lf %lf,%s",x2,y2,z2,rl) ;
        fprintf(texte,"    %lf %lf %lf,%s",x3,y3,z3,rl) ;
        fprintf(texte,"    %lf %lf %lf,%s",x4,y4,z4,rl) ;
        break ; }
    fprintf(texte," ] }%s",rl) ;
    fprintf(texte,"IndexedFaceSet {%s  coordIndex [%s    0, 1, 2, 3, -1 ] }%s",rl,rl,rl);    
}
/* ------------------------------------------------------------------------ */
void debut_facette_VRML(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) ; }
}
/* ------------------------------------------------------------------------ */
void sommet_facette_VRML(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) ; }
}

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