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

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

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

#declare tx_plastico = 
  texture{
    pigment{ color rgb < 0.50, 0.90, 0.50 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_fosca = 
  texture{
    pigment{ color rgb < 0.40, 0.01, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }


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

#declare raio = 2.500;

// Partes da cena:
 
#declare bola =
  sphere{
    < 0.00, 0.00, 0.00 >, raio 
    texture{ tx_plastico }
  }  

#declare caixa = 
  box{ <-1,-1,0>, <+1,1,1> texture{ tx_plastico }}


#declare assento = 
  box{ <-2,-4,0>, <+8,+4,1> }

#declare encosto = 
  box{ <-2,-4,0>, <+0,+4,5> }

#declare perna = 
  cylinder{
    < 0.00, +0.00, 0.00 >,
    < 0.00, 0.00, +5.00 >,
    0.5
    texture{ tx_plastico }
  }

#declare bolinha = 
  sphere{
    < 0, 0, 0 >, 1 
    texture{ tx_plastico }
  }

#declare enfeite = 
  cone{
    < 0, 0, 0 >,
     1
    < 0, 0, 3.00 >,
    0.5   
    texture{ tx_plastico }
  }

#declare peao = 
  union {
      object { enfeite }
      object { bolinha translate < 0,0,4> }
      object { caixa translate < 0,0,5>}
    }

#declare dama = 
  union {
      object { bolinha }
      object { perna }      
      object { caixa translate < 0,0,5>}
    }



#macro tabuleiro_dentro(r) 
  cylinder{
    < 0.00, +0.00, -2.00 >,
    < 0.00, 0.00, 1.00 >,
    r
    texture{ tx_plastico }
  }
#end

#macro tabuleiro_fora(r) 
  cylinder{
    < 0.00, +0.00, -1.00 >,
    < 0.00, 0.00, 0.00 >,
    r
    texture{ tx_fosca }
  }
#end

#macro faixa(r)
  difference {
    object { tabuleiro_fora(r) }
    object { tabuleiro_dentro(r - 3) }
  }
#end

#declare PI = 3.14;

#macro tabuleiro(m, n) 
  union {
    #declare r = m * 3;
    #while(r > 0)
      object { faixa(r) }
      #declare r = r - 3;
      
      #declare alfa = 0;
      #declare i = 0;

      #while (alfa < 2 * PI)
        #declare alfa = alfa + (2 * PI / n);

        #declare x_pos = sin(alfa) * ((2*r - 3) / 2);
        #declare y_pos = cos(alfa) * ((2*r - 3) / 2);

        // #if (i = 0)
          object { peao translate<x_pos, y_pos, 0> }
          // #declare i = 1;
        // #end
        // #if (i = 1)
        //   object { dama translate<x_pos, y_pos, 0> }
        //   #declare i = 2;
        // #end
        // #if (i = 2)
        //   #declare i = 0;
        // #end   

        
      #end

    #end    
  }
#end

#include "eixos.inc"

// Aqui est� a cena, finalmente:

union{
  object{ eixos(5.00) }
  

  object { dama translate <6, 6, 1>}
  // object { peao translate <0, -5, 0>}
  object { tabuleiro(6, 3) }

}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 20;
#declare dir_camera = < 7.00, -7.00, 5.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)