// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2020-09-30 19:57:13 by jstolfi

// ======================================================================
// CORES E TEXTURAS

//#include "textures.inc"

background{ color rgb < 240/255, 243/255, 246/255 > }

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

#declare tx_ponto_top =
  texture{
    pigment{ color rgb < 0.80, 0.0, 0.17 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }


#declare tx_grau1 =
  texture{
    pigment{ color rgb < 0.17, 0.80, 1.00 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_grau2 =
  texture{
    pigment{ color rgb < 0.80, 0.17, 1.00 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_grau3 =
  texture{
    pigment{ color rgb < 0.10, 1.00, 0.17 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_grau4 =
  texture{
    pigment{ color rgb < 1.00, 0.17, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_tubo =
  texture{
    pigment{ color rgb < 0.20, 0.07, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

// ======================================================================
// DESCRI��O DA CENA 

//--------------------------------------------------------------

#macro ponto(centro, raio)
  union{
    sphere{ 
      centro, raio
      texture{ tx_ponto }
    }
  }
#end

#macro ponto_top(centro, raio)
  union{
    sphere{ 
      centro, raio
      texture{ tx_ponto_top }
    }
  }
#end

#macro grau1(i, j)
  union{
    sphere{ 
      < i, j, 0.25 >, 0.25
      texture{ tx_grau1 }
    }
    cylinder{ 
      < i, j, 0.25 >, < i + 0.35, j, 0.25 >, 0.1
      texture{ tx_tubo }
    }
  }
#end

#macro grau2(i, j)
   union{
    cylinder{ 
      < i, j, 0 >, < i, j, 0.25>, 0.35
      texture{ tx_grau2 }
    }
    box{ 
      < i - 0.2, j - 0.2, 0.25>, < i + 0.2, j + 0.2, 0.75 >
      texture{ tx_grau2 }
    }
    cylinder{ 
      < i, j, 0.5 >, < i + 0.5, j, 0.5 >, 0.1
      texture{ tx_tubo }
    }
    cylinder{ 
      < i, j, 0.5 >, < i - 0.5, j, 0.5 >, 0.1
      texture{ tx_tubo }
    }
  }
#end

#macro grau3(i, j)
  union{
    cylinder{ 
      < i, j, 0 >, < i, j, 0.5>, 0.2
      texture{ tx_grau3 }
    }
    sphere{ 
      < i, j, 0.75 >, 0.25
      texture{ tx_grau3 }
    }
    cylinder{ 
      < i, j, 0.25 >, < i + 0.35, j, 0.25 >, 0.1
      texture{ tx_tubo }
    }
    cylinder{ 
      < i, j, 0.25 >, < i, j + 0.35, 0.25 >, 0.1
      texture{ tx_tubo }
    }
    cylinder{ 
      < i, j, 0.25 >, < i, j - 0.35, 0.25 >, 0.1
      texture{ tx_tubo }
    }
  }
#end

#macro grau4(i, j)
  union{
    sphere{ 
      < i, j, 0.25 >, 0.25
      texture{ tx_grau4 }
    }
    cone{ 
      < i, j, 0.75 >, 0, < i, j, 0.5 >, 0.3
      texture{ tx_grau4 }
    }
    cylinder{ 
      < i, j, 0.25 >, < i + 0.35, j, 0.25 >, 0.1
      texture{ tx_tubo }
    }
    cylinder{ 
      < i, j, 0.25 >, < i, j + 0.35, 0.25 >, 0.1
      texture{ tx_tubo }
    }
    cylinder{ 
      < i, j, 0.25 >, < i, j - 0.35, 0.25 >, 0.1
      texture{ tx_tubo }
    }
    cylinder{ 
      < i, j, 0.25 >, < i - 0.35, j, 0.25 >, 0.1
      texture{ tx_tubo }
    }
  }
#end

//------------------------------------------------------------------

#macro interpola_1(tt, t0, t1, p0, p1)
  #local ss = (tt - t0)/(t1 - t0);
  #local vv = (1 - ss)*p0 + ss*p1;
  vv
#end

#macro interpola_3(tt, t0, t1, p0, p1, p2, p3)
  #local p01 = interpola_1(tt, t0, t1, p0, p1);
  #local p12 = interpola_1(tt, t0, t1, p1, p2);
  #local p23 = interpola_1(tt, t0, t1, p2, p3);

  #local p012 = interpola_1(tt, t0, t1, p01, p12);
  #local p123 = interpola_1(tt, t0, t1, p12, p23);
  
  #local p = interpola_1(tt, t0, t1, p012, p123);
  p
#end

#macro testa_interpola_3(p0, p1, p2, p3, n, raio)
  union{
    #local i = 0;
    #while(i < n)
        #local centro = interpola_3(i, 0, n, p0, p1, p2, p3);
        ponto(centro, raio)
        #local i = i + 1;
    #end
  }
#end

#macro testa_interpola_1(p0, p1, n, raio)
  union{
    #local i = 0;
    #while(i < n)
        #local centro = interpola_1(i, 0, n, p0, p1);
        ponto(centro, raio)
        #local i = i + 1;
    #end
  }
#end

//------------------------------------------------------------------

#macro interpola3_multi(tt, p_ini, n, p1, p2, p_fim)

  #local k  = floor(tt);
    
  // Inicializa para preencher dps
  #local Q0 = <0,0,0>;
  #local Q1 = <0,0,0>;
  #local Q2 = <0,0,0>;
  #local Q3 = <0,0,0>;

  #if (k = 0)
    #local Q0 = p_ini;
  #end
  #if (k > 0)
    #local Q0 = (p2[k-1] + p1[k])/2;
  #end

  #if (k = N-1)
    #local Q3 = p_fim;
  #end
  #if (k < N-1)
    #local Q3 = (p2[k] + p1[k+1])/2;
  #end

  #local Q1 = p1[k];
  #local Q2 = p2[k];

  #local centro = interpola_3(tt, k, k+1, Q0, Q1, Q2, Q3);
  ponto(centro, 0.1)
  ponto_top(Q3, 0.5)
#end

#macro teste_interpola3_multi()

  #local N = 3;
  #declare p1 = array[N]

  #declare p1[0] = <0,-4,1.25>;
  #declare p1[1] = <0,8,2.5>;
  #declare p1[2] = <-2,-8,0.5>;

  #local p2 = array[N]
  #declare p2[0] = <-10,10,10>;
  #declare p2[1] = <10, -10, -10>;
  #declare p2[2] = <-5,5,0>;

  #declare p_ini = <2.75, 4.66726, 1>;
  #declare p_fim = <1, 4.66726, 2.75>;
  
  #local raio = 0.05;

  ponto_top(p_ini, 0.5)
  ponto_top(p_fim, 0.5)

  #local tt = 0;
  #while(tt < N)
    interpola3_multi(tt, p_ini, N, p1, p2, p_fim)
    #local tt = tt + 0.001;
  #end

#end

union{
  
  teste_interpola3_multi()

  light_source {
    <0, 10, -3>
    color rgb < 200/255, 42/255, 222/255 >
    spotlight
    radius 100
    falloff 30
    tightness 10
    point_at <0, 0, 0>
  }

}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 3*8.0;
#declare dir_camera = < 10.00, 4.00, 7.00 >;
#declare dist_camera = raio_cena;
#declare intens_luz = 0.80;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)