// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2023-09-26 18:47:51 by stolfilocal
// Original version by jstolfi
// Moved Around by jevs

background{ color rgb < 0.45, 0.10, 0.20 > }

#declare tx_tanque = 
  texture{
    pigment{ color rgb < 0.10, 0.80, 1.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_cano = 
  texture{
    pigment{ color rgb < 1.0, 1.0, 0.0 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.75, 0.90, 0.75 >, color rgb < 0.65, 0.65, 0.80 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 4.0
  }

#declare raio = 2.000;

#declare raioIni = 3;

#declare chao = 
  disc {
    <0, 0, 0>, <0, 0, 1>, 200
    texture {
      tx_xadrez
    }
  }

// =====================================================================

#macro tqR( px, py )
  object{
    union {
      union {
        box {
          <-1, -1, -0>, <1, 1, 2>
          texture {
            tx_tanque
          }
        }
        cylinder {
          <-1.5, 0, 0.25>, <1.5, 0, 0.25>, 0.25 // center of one end, center of other end, radius
          open // remove end caps
          texture {
            tx_cano
          }
        }
      }
      
      cylinder {
          <-1.5, 0, 0.25>, <1.5, 0, 0.25>, 0.25 // center of one end, center of other end, radius
          open // remove end caps
          texture {
            tx_cano
          }
          rotate <0, 0, 90> // <x°, y°, z°>
      }

    }
    translate <px, py, 0> // <x, y, z>
  }
#end

#macro tqT( px, py )
  object{
    union {
      union {
        torus {
          0.5, .25 // major radius, minor radius
          rotate <90, 0, 0> // <x°, y°, z°>
          texture {
            tx_tanque
          }
          translate <0, 0, 0.25> // <x, y, z>
        }

        cylinder {
          <-1.5, 0, 0.25>, <1.5, 0, 0.25>, 0.125 // center of one end, center of other end, radius
          open // remove end caps
          texture {
            tx_cano
          }
        }

      }

      cylinder {
          <-1.5, 0, 0.25>, <1.5, 0, 0.25>, 0.125 // center of one end, center of other end, radius
          open // remove end caps
          texture {
            tx_cano
          }
          rotate <0, 0, 90> // <x°, y°, z°>
      }
    }
    translate <px, py, 0> // <x, y, z>
  }

#end


#macro tqC( px, py )
  object{
    union {
      union {
        cylinder {
          <0, 0, 0>, <0, 0, 2>, 1 // center of one end, center of other end, radius
          texture {
            tx_tanque
          }  
        }
        cylinder {
          <-1.5, 0, 0.25>, <1.5, 0, 0.25>, 0.25 // center of one end, center of other end, radius
          open // remove end caps
          texture {
            tx_cano
          }
        }
      }
      
      cylinder {
          <-1.5, 0, 0.25>, <1.5, 0, 0.25>, 0.25 // center of one end, center of other end, radius
          open // remove end caps
          texture {
            tx_cano
          }
          rotate <0, 0, 90> // <x°, y°, z°>
      }

    }
    translate <px, py, 0> // <x, y, z>
  }
#end

#declare roleta = seed(3453);

#macro gera_tanques(m, n)
  #local i = 0;

  #while(i < n)
      
    #local xOffset = 4;
    #local yOffset = 4;

    #local j = 0;
    #while(j < m)
      #declare k = mod(int(3*rand(roleta)), 3);

      #local posX = i*xOffset;
      #local posY = j*yOffset;

      #switch(k)
        #case(0)
          tqC(posX, posY)
        #break

        #case(1)
          tqT(posX, posY)
        #break

        #case(2)
          tqR(posX, posY)
        #break
      #end


      #local j = j+1;
    #end
    #local i = i+1;
  #end
#end

#include "eixos.inc"

#declare nx = 7;
#declare ny = 5;

union{
    object{ eixos(3.00)}

    // object{ tqRet }
    // object{ tqCil }

    gera_tanques(ny,nx)
    object{ chao  translate < 0,0,-0.01 > texture{ tx_xadrez } }

}

#declare min_cena = < 4*(0-0.5), 4*(0-0.5), 0 >;
#declare max_cena = < 4*(nx-0.5), 4*(ny-0.5), 2 >;

#include "camlight.inc"
#declare centro_cena = 0.5*(min_cena + max_cena);
#declare raio_cena = 0.6*vlength(min_cena - max_cena);
#declare dir_camera = < -10.00, -10.00, 5.00 >;
#declare dist_camera = 13*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)