// 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_casa =
  texture{
    pigment{ color rgb < 0.20, 0.07, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_hiperpeao_chapeu =
  texture{
    pigment{ color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_hiperpeao =
  texture{
    pigment{ checker color rgb < 0.09, 0.0, 0.06 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#declare tx_hiperrainha =
  texture{
    pigment{ checker color rgb < 1.00, 0.17, 0.10 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

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

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

#declare casa = 
  union{
    cylinder{ 
      < 0.00, 0.00, 0.00 >, < 0.00, 0.00, 0.50 >, 0.4
      texture{ tx_casa }
    }
  }


#declare hiperpeao = 
  union{
    cylinder{ 
      < 0.00, 0.00, 0.50 >, < 0.00, 0.00, 2.00 >, 0.3
      texture{ tx_hiperpeao }
    }
    cylinder{ 
      < 0.00, 0.00, 2.00 >, < 0.00, 0.00, 2.50 >, 0.15
      texture{ tx_hiperpeao_chapeu }
    }
    sphere{ 
      < 0.00, 0.00, 2.65 >, 0.15
      texture{ tx_hiperpeao_chapeu }
    }
  }


#declare hiperrainha = 
  union{
    cone{ 
      < 0.00, 0.00, 0.50 >, 0.3, < 0.00, 0.00, 2.00 >, 0.7
      texture{ tx_hiperrainha }
    }
    box{ 
      < 0.25, 0.25, 2 >, <-0.25, -0.25, 2.5 >
      texture{ tx_hiperrainha_coroa }
    }
    sphere{ 
      < 0.00, 0.00, 2.75 >, 0.25
      texture{ tx_hiperrainha_coroa }
    }
  }


#macro fileira(RaioI, RaioE, cor)
    difference {
       cylinder{ < 0.00, 0.00, -1.00 >, < 0.00, 0.00, 0.00 >, RaioE}
       cylinder{ < 0.00, 0.00, -2.00 >, < 0.00, 0.00, 2.00 >, RaioI}
    }
    pigment { rgb ( cor ) }
#end

#include "eixos.inc"

#macro tabuleiro(m, n)

  // object{ hiperpeao translate < 0,2,0 > }
  // object{ hiperrainha translate < 2,-2,0 > }

  #declare Ri = 2;
  #declare Espessura = 1;
  // object{ fileira(1, Ri, 1) }

  #declare i = 0;
  #while(i < m)
    #declare c = mod(i, 2);
    // #debug concat("x = ", str(c, 5, 1), "\n")

    object{ fileira(Ri, Ri + Espessura, c) }
    #declare Ri = Ri + Espessura;

    #declare l = Ri + Espessura/2 - 1;
    #declare theta  = 0;
    #declare dtheta = 360/n; 

    #while(theta < dtheta*n)
      #declare X_casa =  l*cos(radians(theta));
      #declare Y_casa =  l*sin(radians(theta));

      object{  casa translate < X_casa, Y_casa,0 > }

      #if (i = 0)
        #if (theta = 0)
          object{ hiperrainha translate < X_casa, Y_casa,0 > }
        #end
        #if (theta = (floor(n/2)*dtheta))
          object{ hiperrainha translate < X_casa, Y_casa,0 > }
        #end
      #end

      #if (i = m-1)
        object{ hiperpeao translate < X_casa, Y_casa,0 > }
      #end

      #declare theta = theta + dtheta;
    #end

    #declare i = i + 1;

  #end



#end
// Aqui est� a cena, finalmente:

union{
  tabuleiro(4, 4)

  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 = 10.0;
#declare dir_camera = < 15.00, 10.00, 15.00 >;
#declare dist_camera = 2*raio_cena;
#declare intens_luz = 0.80;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)