#include "colors.inc"
#include "textures.inc"
#include "metals.inc"
#include "skies.inc"
#include "stones1.inc"

#declare T_Granite =
  texture {
    pigment {
      granite
      turbulence 0.6
      color_map {
	[0.000, 0.119   color rgb <0.310, 0.384, 0.420>
			color rgb <0.322, 0.369, 0.416>]
	[0.119, 0.322   color rgb <0.322, 0.369, 0.416>
			color rgb <0.424, 0.369, 0.420>]
	[0.322, 0.449   color rgb <0.424, 0.369, 0.420>
			color rgb <0.373, 0.424, 0.518>]
	[0.449, 0.729   color rgb <0.373, 0.424, 0.518>
			color rgb <0.482, 0.573, 0.533>]
	[0.729, 1.001   color rgb <0.482, 0.573, 0.533>
			color rgb <0.310, 0.384, 0.420>]
      }
      scale 0.3
    }
  }

#declare T_Beton =
  texture { 
    pigment { P_Chrome4 } 
    finish {
      ambient 0.35
      brilliance 0.5
      diffuse 0.3
      specular 0.70
      roughness 0.1
      reflection 0.001
    }
  }

light_source {<200.0, 200.0, -150.0> colour White }

sky_sphere { S_Cloud2 }

plane { y, -10.0
  texture {
    finish {
      ambient 0.15
      brilliance 5
      diffuse 0.6
      metallic
      specular 0.80
      roughness 1/100
      reflection 0.5
    }
    pigment {
      color rgb <0.3, 0.6, 0.7>
    }
    normal {
      waves 0.05
      frequency 5000.0
      scale 3000.0
    }
  }
}

#declare Tablier =
  union {
    box {
      <-150,-0.2,-4>, <150,0.2,4>
      texture { T_Granite }
    }
    box { <-150,-0.4,-4.2>, <150,0.4,-3.8> }
    box { <-150,-0.4, 3.8>, <150,0.4, 4.2> }
  }

#declare Pilier =
  union {
    box { <-0.8, -13, -4.4>, <0.8, 15, -3.6> }
    box { <-0.8, -13,  3.6>, <0.8, 15,  4.4> }
    box { <-0.8,  -1, -4  >, <0.8, -0.2, 4> }
    box { <-0.4,  12, -4  >, <0.4, 12.8, 4> }
  }

#declare Suspension1 =
  union {
    #external{ocaml /dev/fd/0}
    let f x = 8.6 *. (cosh (x /. 20.0) -. 1.0) +. 2.0;;
    let si = string_of_int and sf = string_of_float and fi = float_of_int;;
    let sv x y z = "<" ^ (sf x) ^ "," ^ (sf y) ^ "," ^ (sf z) ^ ">";;
    for i = 1 to 14 do
      let x = fi (i * 4 - 30) in
      let y = f x in
      print_string ("cylinder { " ^ (sv x y (-0.18)) ^ "," ^ (sv x y 0.18) ^ ", 0.25 }\n");
      print_string ("cylinder { " ^ (sv x y 0.0) ^ "," ^ (sv x 0.0 0.0) ^ ", 0.12 }\n");
    done;;
    for i = 0 to 14 do
      let x1 = fi (i * 4 - 30)
      and x2 = fi ((i + 1) * 4 - 30) in
      let y1 = f x1
      and y2 = f x2 in
      print_string ("cylinder { " ^ (sv x1 y1 0.0) ^ "," ^ (sv x2 y2 0.0) ^ ", 0.12 }\n");
    done;;
    #external{end}
  }

#declare Suspension =
  union {
    object { Suspension1 translate -3.8*z }
    object { Suspension1 translate  3.8*z }
  }    

union {
  object { Tablier }
  
  object { Pilier translate -90*x }
  object { Pilier translate -30*x }
  object { Pilier translate  30*x }
  object { Pilier translate  90*x }

  object { Suspension translate -60*x }
  object { Suspension }
  object { Suspension translate 60*x }

  cylinder { <-90, 13.63,-3.8>, <-110,0,-3.8>, 0.12 }
  cylinder { <-90, 13.63, 3.8>, <-110,0, 3.8>, 0.12 }
  cylinder { < 90, 13.63,-3.8>, < 110,0,-3.8>, 0.12 }
  cylinder { < 90, 13.63, 3.8>, < 110,0, 3.8>, 0.12 }

  texture { T_Beton }
}

#declare Montagnes0 =
  height_field {
    gif "plasma.gif" 
    smooth
    scale <600, 30, 100>
    translate <-300, -10, -50>
    rotate 90*y
  }
/*#declare Montagnes0 = 
  box {
    <0,0,0>, <1,1,1>
    scale <400, 30, 100>
    translate <-200, -10, -50>
    rotate 90*y
  }*/

#declare Montagnes =
  difference {
    union {
      object {
	Montagnes0
	matrix <1,-0.5,0,0,1,0,0,0,1,0,0,0>
      }
      object {
	Montagnes0
	matrix <-1,0,0,0,1,0,0,0,1,0,0,0>
	translate <-99.99,25,0>
      }
      pigment {
	color rgb <0.5,0.8,0.0>
      }
      translate -110*x
    }
    intersection {
      plane { -y, 0 }
      plane {  z, 0 rotate  18*x translate  4.2*z }
      plane { -z, 0 rotate -18*x translate -4.2*z }
      pigment { color rgb <0.8,0.45,0.0> }
    }
  }

object { Montagnes }
object { Montagnes rotate 180*y }

camera {
  location <70,10,-30>
  look_at <-10,0,0>
}
