// Grappe de 13 sphères autour d'une sphère centrale (mais de rayon plus grand)
// cf Pour La Science, n°427, mai 2013, La grappe de sphères collantes

#include "colors.inc"
#include "textures.inc"
#include "shapes.inc"
#include "stones.inc"
#include "woods.inc"                                                
#include "glass.inc"


// ***************************
// Installation de la caméra *
// ***************************
// On installe la caméra et on définit son orientation.
// L'axe des x est vers la droite, l'axe des y vers le haut, l'axe des z vers le fond.

#declare cl=0;//clock/400;    // cl=clock/400; pour une animation de 400 images, clock variant de 1 à 400

camera {orthographic
#declare DistanceObservateur = 8;
#declare HauteurObservateur = 2;
#declare Angle = 2;  // < 0 pour l'oeil gauche (G.POV) . L'image devra être placée à DROITE en vision croisée
                     // > 0 pour l'oeil droit (D.POV) (en degré), l'image devra être placée à GAUCHE. 
                     // En général 3 à 5° degré d'écart entre les deux yeux. Angle est en degré. 

//Définir l'angle pour choisir l'oeil
location  <DistanceObservateur*cos(Angle/180*3.142), HauteurObservateur, DistanceObservateur*sin(Angle/180*3.142)> 
look_at  <0, 0, 0>
}

// On définit le fond (par défaut noir)

background { color Black}  


// ********
// Objets *
// ********            

// Le calcul des centres des sphères et du rayon de la sphère centrale provient de 13spherb.mws. Attention, la verticale est donnée par la dernière composante, contrairement á l'usage de Povray.
// Il conviendra donc de pivoter la figure.
// r est le rayon de la sphère centrale.
#declare r = 1.100049116;
#declare S = array[13] {
<0., 0., -1-r>, 
<1.758696595, 0., -1.147691723>,
<-0.8793482975, 1.523075929, -1.147691723>,
<-0.8793482975, -1.523075929, -1.147691723>,
<1.013855557, 1.756049336, -0.5464408922>,
<-2.027711112, 0., -0.5464408924>,
<1.013855557, -1.756049336, -0.5464408922>,
<1.877541485, 0.5303193634, 0.7770517061>,
<-0.4795007010, 1.891158304, 0.7770517061>,
<-0.9611397465, -1.664742875, 0.8456072107>,
<-1.563825487, 0.1622665942, 1.392238989>,
<0.9224397368, -1.273179304, 1.392238989>,
<0.3032383090, 0.5252241547, 2.010571093>
}

// *****************      
// Le plan de base *
// *****************

//#declare Floor_Texture =
//    texture { pigment { P_WoodGrain18A color_map { M_Wood18A }}}
//    texture { pigment { P_WoodGrain12A color_map { M_Wood18B }}}
//    texture {
//        pigment { P_WoodGrain12B color_map { M_Wood18B }}
//        finish { reflection 0.25 }
//    }

#declare Floor_Texture =
    texture { pigment { P_WoodGrain18A color_map { M_Wood18A }}}
    texture { pigment { P_WoodGrain12A color_map { M_Wood18B }}}
    texture {
        pigment { P_WoodGrain12B color_map { M_Wood18B }}
        finish { reflection 0.15 }
    }

union {    

union {
sphere {<0,0,0>, r 
       texture {
        T_Wood6
        finish { specular 0.5 roughness 0.005 ambient 0.35 }
        rotate <45, 0, 20>
        }}

#declare indice=0;
#while (indice<=12)
    sphere {S[indice], 1
        texture {
            T_Wood10
            finish { specular 0.5 roughness 0.005 ambient 0.35 }
            rotate <-10*indice, 20*indice, 30*indice>
        }}                                                          
    #declare indice=indice+1;
#end
rotate -x*90  
}

#declare hauteurplan = -4;
#declare longueurtige = 8;
#declare rayontige = 0.1;
#declare rayontige = 0.1;
cylinder {<0,hauteurplan,0>, <0,hauteurplan+longueurtige> rayontige texture {Silver_Metal} pigment { color White }}
sphere {<0,hauteurplan+longueurtige> rayontige texture {Silver_Metal} pigment { color White }}
sphere {<0,-r-2> 1.5*rayontige texture {Silver_Metal} pigment { color White }}
sphere {<0,hauteurplan,0> 1.5*rayontige texture {Silver_Metal} pigment { color White }}
sphere {<0,2.7> 1.5*rayontige texture {Silver_Metal} pigment { color White }}
box {<-5,hauteurplan,-5> <5,hauteurplan-2*rayontige,5>
    texture { Floor_Texture
        scale 0.25
        rotate <10, 0, 15>
        translate z*4
    }}  


rotate y*360*cl
rotate -z*80*sin(cl*pi)*sin(cl*pi)
translate <0,sin(cl*pi)*sin(cl*pi),0>          
}
   



// *********
// Lumière *
// *********

                
//light_source { <0, 10, 0> color White shadowless}
//light_source { <10, 0, 0> color White shadowless}
//light_source { <0, 0, -10> color White shadowless}
//light_source { <10, -10, -10> color White shadowless}

#declare Dist=80.0; // 80.0
#declare AutreDist=10; // 10
light_source {< -5*AutreDist, 2.5*AutreDist, -5*AutreDist> color White
     fade_distance Dist fade_power 2
     adaptive 1
}

light_source {< 10*AutreDist, 5*AutreDist,  -4> color White
     fade_distance Dist fade_power 2
     adaptive 1
}

light_source {< 0, 10*AutreDist,  0> color White
     fade_distance Dist fade_power 2
     adaptive 1
}


