/*
 *   nouveau projet Thu Dec  5 11:37:05 AM UTC 2024
 */

/*   voir aussi le fichier 'globals.inc'   */

/* ======================================================= */

#include  "groundbase.inc"

/* ======================================================= */
/*
 *	essai du 12 mars 2025
 */

#declare RedB_0_X = 18;
#declare RedB_0_Z = 28;

#declare RedB_1_X = -24;
#declare RedB_1_Z =   4;

#declare Pos_RedB_0 = <RedB_0_X, 0, RedB_0_Z>;
#declare Pos_RedB_1 = <RedB_1_X, 0, RedB_1_Z>;

#macro RedBase_0 ( T )
difference {
#local R = 2.46;
	cylinder { 0,      y*0.40,     R      }
	cone { y*0.37, R*0.78, y*0.42,          R*0.83 }
	#for (Foo, 20, 339, 10)
	  #local Dx = R * sin(radians(Foo));
	  #local Dz = R * cos(radians(Foo));
	  cone { 0, 0.01, y*0.41, 0.10 translate <Dx, 0, Dz> }
	#end
	}
// pigment { color Red*0.8 }
texture { T }
#end    // macro

/* ======================================================= */

#macro GyroPhare_mat ()
union	{
	cylinder { 0, y*H_gyro, R_gyro }
	intersection {
		sphere { 0, R_gyro scale <1, 1.414, 1> }
		box { <-1, 0, -1>, <1, 1.94, 1> }
		translate y*(H_gyro+H_gylampe+0.04) 
		}
	#if (rand(Rng1) < 0.5)
	  texture { T_Stone25 scale 1+rand(Rng1) }
	#else
	  texture { T_Stone6 }
	#end
	}
#end // macro

#macro GyroPhare_lampe ()
union	{
	difference {
		cylinder { 0, y*H_gylampe,    R_gyro }
		cylinder { y*0.01, y*(H_gylampe-0.01), R_gyro*0.97 }
		#local WB = 0.017;
		union {
		  box { <-1, 0.03, -WB>, <1, (H_gylampe-0.03), WB> }
		  box { <-WB, 0.03, -1>, <WB, (H_gylampe-0.03), 1> }
		  }
		#undef WB
		pigment { color Gray90 }
		#local Ro = 0.5 + (2.0 * rand(Rng1));
		#if (rand(Rng1) < 0.50)
		  #local Ro = -Ro;
		#end
		rotate y * Ro * clock
		#undef Ro
		}
	light_source { y*0.10
			rgb <0.8, 0.9, 0.999999999>
			fade_distance	3.96
			fade_power	1.55
			}
	}
#end // macro

#macro GyroPhare ()
union	{
	object { GyroPhare_mat () }
	object { GyroPhare_lampe ()
			// rotate y*rand(Rng1)*clock
			translate y*(H_gyro+0.02) }
	}
#end // macro

#macro Les_GyroPhares ()
union	{
	#local E = SzSol * 0.431;
	#for (Idx, 0, 359, 60)
	  #local Ang = radians(Idx+7.33);
	  #local Dx  = E * sin(Ang);
	  #local Dz  = E * cos(Ang);
	  object { GyroPhare ()	 translate <Dx, H_sol, Dz> }
	#end
	#undef E
	}
#end
/* ======================================================= */

#declare Rhxba = 0.30;
#declare R2hxba = Rhxba * 0.48;

#declare HexaBalls = object
{
merge	{
	sphere { 0, Rhxba }
	#local E = Rhxba * 1.260;
	sphere { 0, R2hxba	translate <-E,  0,  0>	}
	sphere { 0, R2hxba	translate < E,  0,  0>	}
	sphere { 0, R2hxba	translate < 0, -E,  0>	}
	sphere { 0, R2hxba	translate < 0,  E,  0>	}
	sphere { 0, R2hxba	translate < 0,  0, -E>	}
	sphere { 0, R2hxba	translate < 0,  0,  E>	}
	#undef E
	}
}

#declare Les_Bibelots = object
{
union	{
	object	{ HexaBalls
		texture { Lightning1 scale 0.33 }
		rotate <clock/3, clock/6, clock/9>
		translate <2, -1.1+1.01*Cos_010(NormClock), 4>
		}

	object	{ HexaBalls
		texture { Lightning2 scale 0.56 }
		rotate <-clock, clock*0.33333, clock>
		translate <5, -1+0.92*Cos_010(NormClock), -3>
		}
	}
}
/* ------------------------------------------------------------ */
#declare RHBlo  = 0.24;
#declare RHBlo2 = RHBlo * 0.666;

#declare HexaBlob = object
{
blob			{
	// threshold 0.01 + NormClock
	threshold 0.01
	sphere { <0, 0, 0>, RHBlo, 1 }
	#local E = RHBlo * 1.210;
	#local W = 0.1;
	sphere { <-E,  0,  0>, RHBlo2, W }
	sphere { < E,  0,  0>, RHBlo2, W }
	sphere { < 0, -E,  0>, RHBlo2, W }
	sphere { < 0,  E,  0>, RHBlo2, W }
	sphere { < 0,  0, -E>, RHBlo2, W }
	sphere { < 0,  0,  E>, RHBlo2, W }
	}
}

/* ======================================================= */

/* ======================================================= */

#declare UnderHoles = array[6]

#fopen Holes "WS/holes.log" write
#for (Idx, 0, 5)
  #local Angle = Idx* 1.090;
  #local Px = sin(Angle) * (SzSol * 1.21);
  #local Pz = cos(Angle) * (SzSol * 1.23);
  #declare UnderHoles[Idx] = <Px, 0, Pz>;
  #write (Holes, Idx, "  ", Angle, "  ", UnderHoles[Idx], "\n")
#end
#fclose Holes

#declare Underground = object
{
difference {
	// plane { y, 0 }
	#local Big = 300;
	box { <-Big, -0.15, -Big>, < Big, 0.0000,  Big> }
	#undef Big
	#for (Foo, 0, 5)
	  cylinder { -y*5, y*5, 3.4 translate UnderHoles[Foo] }
	#end
	}
texture {
	pigment { color Gray20 }
	normal { bumps 0.38 scale 2.6 }
	finish  { phong 0.125 }
	}
// translate -y*1.55
}

/* ======================================================= */

#declare Repere = object
{
union	{
	#local R = 0.008;
	cylinder { 0, <1, 0, 0>, R pigment { color Red   } }
	cylinder { 0, <0, 1, 0>, R pigment { color Green } }
	cylinder { 0, <0, 0, 1>, R pigment { color Blue  } }
	}
}

/* ======================================================= */

#declare OpenBox = object
{
union	{
	#local R = 0.010;
	/* les verticales */
	cylinder { <-1, -1, -1>, <-1,  1, -1>, R }
	cylinder { < 1, -1, -1>, < 1,  1, -1>, R }
	cylinder { <-1, -1,  1>, <-1,  1,  1>, R }
	cylinder { < 1, -1,  1>, < 1,  1,  1>, R }
	/*   en bas */
	cylinder { < 1, -1,  1>, <-1, -1,  1>, R }
	cylinder { < 1, -1, -1>, <-1, -1, -1>, R }
	cylinder { <-1, -1,  1>, <-1, -1, -1>, R }
	cylinder { < 1, -1,  1>, < 1, -1, -1>, R }

	/*   en haut */
	cylinder { < 1,  1,  1>, <-1,  1,  1>, R }
	cylinder { < 1,  1, -1>, <-1,  1, -1>, R }
	cylinder { <-1,  1,  1>, <-1,  1, -1>, R }
	cylinder { < 1,  1,  1>, < 1,  1, -1>, R }

	#undef R
	texture { WIP_color }
	}
}

/* ======================================================= */
/*
 *	nouvel éclairage du 10 février 2025
 */
#declare Quad_lampe = object
{
light_source {
	0
	color White
	fade_distance	SzSol * 0.40
	fade_power	1.20
	}
}

#declare QuadriLight = object
{
#local T = E_QuadriLight;
#local H = H_QuadriLight;
// #local H = 5;

union	{
	object { Quad_lampe	translate <-T, H, -T>	}
	object { Quad_lampe	translate < T, H, -T>	}
	object { Quad_lampe	translate <-T, H,  T>	}
	object { Quad_lampe	translate < T, H,  T>	}
	}
rotate -12 * y
}
/* ======================================================= */

#declare Les_Lumieres = object
{
union {
	#if (1)
	light_source {
		<2.3, 5.50,  2.8>	color Gray70
		spotlight
		radius 14 falloff 10 tightness 10
		point_at <0, 0.95, 0.22222222>
		}
	#end

	#if (1)
	light_source {
		<-5, 5.60, 18>
		#if ( (clock > 290) & (clock<344) )
		 #local Couleur = rgb <0.20, 0.20, 0.90>;
		#else
		 #local Couleur = rgb <0.80, 0.80, 0.70>;
		#end
		color Couleur
		spotlight
		radius 12 falloff 10 tightness 5
		point_at <0, 0.95, -0.22>
		}
	#end

	light_source {
		<-4, 54, -7>
		colour Gray50
		parallel
		point_at	0
		}

	}
}

/* ======================================================= */

// #declare Le_Ciel = object
// {
sky_sphere {
	pigment {
		gradient y
		color_map {
			[ 0.2  color Gray10		]
			[ 0.4  color rgb <.4, .3, .8>	]
			[ 0.7  color Gray20		]
			[ 0.8  color rgb <.95, .7, .6>	]
			[ 1.0  color Gray10		]
			}
		turbulence 3.14159 + 0.74 * Cos_010(NormClock)
		scale 1.600
		// translate -1
		}
	#local Kem = 0.09;
	emission rgb <Kem, Kem, Kem>
	}
// }

/* ======================================================= */

	/* XXX       XXX */
	light_source {
		<-4, 54, -17>
		colour Gray40
		parallel
		point_at	0
		}

/*
 *	Et on rassemble tous les éléments...
 */
#declare Le_Decor = object
{
union	{
	object { Underground }
	object { La_GroundBase }
	object { RedBase_0 (T_Beton_1)	translate <RedB_0_X, 0, RedB_0_Z> }
	object { RedBase_0 (T_Beton_2)	translate <RedB_1_X, 0, RedB_1_Z> }
	// object { Les_Lumieres }
	object { QuadriLight }
	object { Les_GyroPhares () }
	}
}
/* ------------------------------------------------------------ */