// Textures
background{ color rgb < 0.75, 0.80, 0.85 > }

#declare tx_objetos = 
  texture{
    pigment{ color rgb < 0.80, 0.80, 0.80 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_arestas = 
  texture{
    pigment{ color rgb < 0.90, 0.80, 0.70 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_teste = 
  texture{
    pigment{ color rgb < 1.0, 1.0, 1.0 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

// Objetos
#declare raio_esferas = 2.0;

#declare grau_1 = 
    sphere {
      < 0.00, 0.00, 0.00 >,
      raio_esferas
    }

#declare grau_2 = 
    union {
      sphere{
       < 0.00, 0.00, 0.00 >,
        raio_esferas
      }
      cylinder{
        < 0.00, 0.00, 0.00 >,
        < 0.00, 0.00, 6.00 >,
        raio_esferas
      }
    }

#declare grau_3 = 
  union {
    sphere{
       < -3.00, +3.00, 0.00 >,
        raio_esferas
      }
      box {
        < -1.00, +1.00, 0.00 >, < -5.00, +5.00, 8.00 > // <x, y, z> near lower left corner, <x, y, z> far upper right corner  
      }
  }

#declare chao = 
  box{ <-100,-100,-1>, <+100,+100,0> }

// Macros

#macro interpola1(ti, t0, v0, t1, v1)
  #local ss = (ti - t0)/(t1 - t0);
  #local vv = ((1 - ss) * v0) + (ss * v1);
  vv
#end

#macro interpola3(ti, ta, tb, v0, v1, v2, v3)
  #local v01 = interpola1(ti, ta, v0, tb, v1);
  #local v02 = interpola1(ti, ta, v1, tb, v2);
  #local v03 = interpola1(ti, ta, v2, tb, v3);

  #local v012 = interpola1(ti, ta, v01, tb, v02);
  #local v123 = interpola1(ti, ta, v02, tb, v03);
  
  #local v0123 = interpola1(ti, ta, v012, tb, v123);

  v0123
#end

#macro test_interpola(p0, p1, p2, p3, n, raio)
  union{
    #local k = 0;
    #while (k < n)
      #local centro = interpola3(k, 0, n, p0, p1, p2, p3);
      sphere{
        centro, raio
        texture{ tx_arestas }
      }
      #local k = k + 1;
    #end
  }
#end
  
#include "bezpoly.inc"

#macro interpola3_multi(tt, pini, n, p1, p2, pfim)
  #local raio = 0.5;
  union{
    object{ bezpoly_multi(n, pini, p1, p2, pfim, 0.9*raio) }
    #local q0 = pini;
    #local k = 0;
    #while (k<n-1)
      #local q3 = (p2[k]+p1[k+1])/2;
      test_interpola(q0, p1[k], p2[k], q3, tt, raio)
      #local q0 = q3;
      #local k = k + 1;
    #end
    // k == n-1
    #local q3 = pfim;
    test_interpola(q0, p1[n-1], p2[n-1], q3, tt, raio)
  }
#end

#include "eixos.inc"

// Cena

#local pini = <25, 1, 13>;
#declare p1 = array[3] {< 25,  10,   5>, <  10,  10,  18>, <  15,  10,  +5 >};//, <33, 26, 15>};
#declare p2 = array[3] {< +9, -15,  -1>, < -15, -10,  -5>, < -25, -10,  -5 >};//, <-25, -10, -5>};
#local pfim = <-20, 0, -1>;

union{
  //object{ eixos(30.00) }

  object{
    grau_2
    texture {tx_objetos}
    rotate <180, 0, 0> // <x°, y°, z°>
    translate <+25, 0, +10> // <x, y, z>
  }

  object{
    grau_3
    texture {tx_objetos}
    rotate <180, 0, 0> // <x°, y°, z°>
    translate <-20, 0, -1> // <x, y, z>
  }
  interpola3_multi(100, pini, 3, p1, p2, pfim)
}

#declare cmin = < -28,-17,-10 >;
#declare cmax = < +28,+13,+17 >;

box{ cmin, <cmax.x,cmax.y,cmin.z+0.01>  texture{ pigment{ color rgb <0.80,0.70,0.60> } finish {diffuse 0.7 ambient 0.3 } } }

#include "camlight.inc"
#declare centro_cena = (cmin + cmax)/2;
#declare raio_cena = 0.55*vlength(cmin - cmax);
#declare dir_camera = < 5.00, -9.00, 18.00 >; // <0.001,0,1>; //
#declare dist_camera = 7*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)