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

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

#declare roleta = seed(167494);


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

#declare tx_plastico = 
  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_fosca = 
  texture{
    pigment{ color rgb < 1.00, 0.80, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_black = 
  texture{
    pigment{ color rgb < 0.00, 0.00, 0.00 > }
    finish{ diffuse 1.0 ambient 0.0 }
  }

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

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

#local tx_coke = 
  texture{
    pigment{ color rgb < 1, 0, 0 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

#declare tx_coke_2 = 
  texture{
    pigment{ color rgb < 0.58, 0.29, 0.00 > }
    normal { bumps 0.75 scale <0.025,0.075,0.025> }
    finish { diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_brown = 
  texture{
    pigment{ color rgb < 0.9, 0.00, 0.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }


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

#declare tx_espelho = 
  texture{
    pigment{ color rgb < 1.00, 0.85, 0.30 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

#declare tx_vidro = 
  texture{
    pigment{ color rgb < 0.85, 0.95, 1.00 > filter 0.70 }
    finish{ diffuse 0.03 reflection 0.25 ambient 0.02 specular 0.25 roughness 0.005 }
  }

#declare tx_vidro_green = 
  texture{
    pigment{ color rgb < 0.05, 0.90, 0.00 > filter 0.70 }
    finish{ diffuse 0.33 reflection 0.05 ambient 0.02 specular 0.25 roughness 0.005 }
  }


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

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

#declare raio = 2.000;

// Partes da cena:
  
#declare bolinha = 
  sphere{ < 0,0,0 >, 0.50 }
 
#declare bolota = 
  sphere{ < 0,0,0 >, 1.50 }
 
#declare bola =
  sphere{
    < 0.00, 0.00, 0.00 >, raio 
    texture{ tx_plastico }
  }
  
#declare pino = 
  cylinder{
    < -2.00, +2.00, -1.00 >,
    < +2.00, -2.00, +1.00 >,
    0.75
    texture{ tx_fosca }
  }
  
#declare furo = 
  cylinder{
    < -1.00, -2.00, -2.00 >,
    < +1.00, +2.00, +2.00 >,
    0.75*raio
    texture{ tx_fosca }
  }

#declare chao = 
  box{ <-20,-20,-1>, <+20,+20,0> texture { tx_green }}

#declare ovniBody = cylinder{
    < 0.00, 0.00, 0.00 >,
    < 0.00, 2.00, 0.00 >,
    0.5
    texture{ tx_xadrez }
  }

#declare ovniHead = cone{ < 0, 0, 0 >, 0.5, < 0, 1, 0 >, 0 texture{ tx_xadrez } }

#declare ovniBox =  box{ <0, 0, 0>, <1, 1, 1> texture {tx_fosca} }

#declare ovniHole = cylinder { <0, 0, 0>, <0, 2, 0>, 0.25 texture { tx_coke } }



// /////////////




#include "eixos.inc"




// Aqui est� a cena, finalmente:

#declare ovni = 
  union {
    object { bolinha translate <0, -4.5, 0>texture{ tx_coke } }  
    object { bolinha translate <0, -3.5, 0> texture{ tx_fosca } }  
    object { bolinha translate <0, -2.5, 0> texture{ tx_coke } }  
    object { bolinha translate <0, -1.5, 0> texture{ tx_fosca } } 
    object { bolinha translate <0, -0.5, 0> texture{ tx_coke } } 
    object { ovniBody }
    object { ovniHead translate <0, 2, 0> }
    difference {
      object { ovniBox translate <-0.5, +3.0, -0.5> }
      object { ovniHole translate <0, 2.5, 0> }
    }
  }


#macro soldier(fullTexture)
  #local soldierHead = sphere{ <0, 0, 0>, 0.25 translate <0, 0, 1> }
  #local soldierBody = box { <0, 0, 0>, <0.2, 0.2, 1> translate <-0.1, -0.1, 0.2> }
  #local soldierBase = box { <0, 0, 0>, <0.5, 0.5, 0.2> translate <-0.25, -0.25, 0> }
  
  union {
    object { soldierHead texture { fullTexture } }
    object { soldierBody texture { fullTexture } }
    object { soldierBase texture { fullTexture } }
  }
#end



#macro ship(fullTexture)
  #local shipMiddle = sphere{ <0, 0, 0>, 0.4 translate <0, 0, 0>    }
  #local shipHead   = sphere{ <0, 0, 0>, 0.3 translate <0, 0.7, 0>  }
  #local shipTail   = sphere{ <0, 0, 0>, 0.4 translate <0, -0.8, 0> }

  union {
    object { shipMiddle texture { fullTexture } }
    object { shipHead texture { fullTexture } }
    object { shipTail texture { fullTexture } }
  }
#end

#macro generateArmy(soldierRows, soldierColumns)
  union {
    #local soldierRowsCounter = 0;
    #while (soldierRowsCounter < soldierRows)
      #local soldierColumnsCounter = 0;
      #while (soldierColumnsCounter < soldierColumns)

        #local kk = (soldierColumnsCounter) * (soldierRowsCounter + 1);
        #if (sin(15*kk*kk) > -0.2) 
          object { soldier(tx_fosca) translate <2 * soldierRowsCounter, 1.2 * soldierColumnsCounter, 0> }
        #end

        #local soldierColumnsCounter = soldierColumnsCounter + 1;
      #end
      #local soldierRowsCounter = soldierRowsCounter + 1;    
    #end
  }
#end

#macro generateShipArmy(shipRows, shipColumns)
  union {
    #local shipRowsCounter = 0;
    #while (shipRowsCounter < shipRows)
      #local shipColumnsCounter = 0;
      #while (shipColumnsCounter < shipColumns)
        
        #local kk = (shipColumnsCounter + 1) * (shipRowsCounter + 5);
        #if (sin(15*kk*kk) > 0) 
          object { ship(tx_coke_2) translate <3 * shipRowsCounter, 2.5 * shipColumnsCounter, 0> scale <0.5, 0.5, 0.5> }
        #end


        #local shipColumnsCounter = shipColumnsCounter + 1;
      #end
      #local shipRowsCounter = shipRowsCounter + 1;    
    #end
  }
#end

#macro randomNegative()
  
  #local value = 1;
    #if (rand(roleta) < 0.5)
      #local value = 1;
    #else
      #local value = -1;
    #end

  value
#end


#macro generateTree(leaves)
  union {
    object { cylinder { <0, 0, 0>, <0, 0, 1>, 0.2 texture { tx_coke_2 } } }
    object { sphere{ <0, 0, 0>, 0.2 translate <0, 0, 1> texture { tx_coke_2 } } }

    #if (leaves)
      object { sphere { <0, 0, 0>, 0.4 translate <0, 0, 1> texture { tx_green } }}
    #end
  }
#end

#macro arvore(P, A, K, S)

  #if (A < 1) 
    union {
      object { generateTree(true) translate P } 
    }

  // return
  #else
    #if (K < 1)
      union {
        object { generateTree(true) translate P } 
      }
    #else
      union {
        object { generateTree(false) }  
        
        #if (rand(roleta) < 0.9)
          #local newS = S - 0.05;
          #local NL = <0, 0, 0>;
          
          #local la = rand(roleta) * 40 * randomNegative();
          #local lb = rand(roleta) * 40 * randomNegative();
          #local lc = rand(roleta) * 40 * randomNegative();
          object { arvore(NL, A - 1, K - 1, newS) rotate <la, lb, lc> scale <newS, newS, newS> translate <0, 0, 1>  }  
        #end

        #if (rand(roleta) < 0.9)
          #local newS = S - 0.02;
          #local NL = <0, 0, 0>;
          
          #local ra = rand(roleta) * -40 * randomNegative();
          #local rb = rand(roleta) * -40 * randomNegative();
          #local rc = rand(roleta) * -40 * randomNegative();
          object { arvore(NL, A - 1, K - 1, newS) rotate <ra, rb, rc>  scale <newS, newS, newS> translate <0, 0, 1> }  
        #end

        translate P 
      }
    #end
  #end
  
#end

#macro plantacao(M, N, A, K)
  union {
    #local counterM = 0;
    #while (counterM < M)
      #local counterN = 0;
      #while (counterN < N)

        #local xx = counterM * 5;
        #local yy = counterN * 5;
        #local zz = 0;

        #local xxx = xx + (rand(roleta) * 1.5) * randomNegative();
        #local yyy = yy + (rand(roleta) * 1.5) * randomNegative();

        #local place = <xxx, yyy, zz>;
        object { arvore(place, A, K, 1) }

        #local counterN = counterN + 1;
      #end

      #local counterM = counterM + 1;
    #end
    
  }
#end

#macro braco1()
union {
  object { sphere { < 0.00, 0.00, 0.00 >, 0.4 texture{ tx_black } } }
  object { box { <-0.1, 0.1, -0.1>, <0.1, 2.1, 0.1> texture { tx_brown } } }
}
#end

#macro braco2(angleX1)
union {
  object { sphere { < 0.00, 0.00, 0.00 >, 0.4 texture{ tx_black } } }
  object { box { <-0.2, 0.2, -0.2>, <0.2, 3.2, 0.2> texture { tx_plastico } } }
  object { braco1() rotate <angleX1, 0, 0> translate <0, 3, 0> }
}
#end

#macro perna1()
union {
  object { sphere { < 0.00, 0.00, 0.00 >, 0.4 texture{ tx_brown } } }
  object { box { <-0.2, 0.2, -0.2>, <0.2, 2.2, 0.2> texture { tx_black } } }
}
#end

#macro perna2(angleX1, angleY1)
union {
  object { sphere { < 0.00, 0.00, 0.00 >, 0.4 texture{ tx_brown } } }
  object { box { <-0.3, 0.3, -0.3>, <0.3, 2.3, 0.3> texture { tx_coke_2 } } }
  object { perna1() rotate <angleX1, angleY1, 0> translate <0, 2, 0> }
}
#end

#macro perna3(angleX2, angleY2, angleX1, angleY1)
union {
  object { sphere { < 0.00, 0.00, 0.00 >, 0.4 texture{ tx_brown } } }
  object { box { <-0.25, 0.25, -0.25>, <0.25, 2.25, 0.25> texture { tx_green } } }
  object { perna2(angleX1, angleY1) rotate <angleX2, angleY2, 0> translate <0, 2, 0> }
}
#end

#macro robo(bracoDireitoX, bracoDireitoY, bracoDireitoZ, bracoDireito1X, bracoEsquerdoX, bracoEsquerdoY, bracoEsquerdoZ, bracoEsquerdo1X, pd1, pd2, pd3, pd4, pdrX, pdrY, pdrZ, pe1, pe2, pe3, pe4, perX, perY, perZ)
union {
  // head
  difference {
    object { box { <-0.5, -0.5, -0.5>, <0.5, 0.5, 0.5> texture { tx_coke_2 } } translate <0, 0, 0> }
    object { box { <-5, -0.15, -0.15>, <5, 0.15, 0.15> texture { tx_coke_2 } } translate <0, 0.25, 0.1> }
    object { box { <-5, -0.15, -0.15>, <5, 0.15, 0.15> texture { tx_coke_2 } } translate <0, 0.25, 0.1> scale <1, -1, 1> }
    object { box { <-5, -0.4, -0.15>, <5, 0.4, 0.15> texture { tx_coke_2 } } translate <0, 0.0, -0.3> }
  }
  


  object { braco2(bracoDireito1X) rotate <bracoDireitoX, bracoDireitoY, bracoDireitoZ> }
  object { braco2(bracoEsquerdo1X) rotate <bracoEsquerdoX, bracoEsquerdoY, bracoEsquerdoZ> scale <1, -1, 1> }

  object { perna3(pd1, pd2, pd3, pd4) rotate <pdrX - 90, pdrY, pdrZ> translate <0, 0.35, 0> }
  object { perna3(pe1, pe2, pe3, pe4) rotate <perX - 90, perY, perZ> translate <0, 0.35, 0> scale <1, -1, 1> }
}
#end

union{
  // object { eixos(3.00) }
  // object { chao translate <8, 8, 0> }

  
  #local pd1 = 90;
  #local pd2 = 20;
  #local pd3 = 25;
  #local pd4 = 20;

  #local pdrX = 0;
  #local pdrY = 0;
  #local pdrZ = 0;

  #local pe1 = 0;
  #local pe2 = 0;
  #local pe3 = 0;
  #local pe4 = 0;

  #local perX = 0;
  #local perY = 0;
  #local perZ = 0;

  object { 
    robo(0, 0, 0, 45, 0, -30, 0, -45, pd1, pd2, pd3, pd4, pdrX, pdrY, pdrZ, pe1, pe2, pe3, pe4, perX, perY, perZ) 
    translate <0, 0, 3>
    scale < 0.7, 0.7, 0.7 >
  }

  object { 
    robo(20, 40, 10, -45, 32, -30, 0, -45, pd1*3, pd2*3, pd3*-2, pd4*2, pdrX*4, pdrY, pdrZ, pe1, pe2, pe3, pe4, 20, 40, 60) 
    translate <0, 7, 3>
    scale < 0.4, 0.4, 0.4 >
  }

  object { 
    robo(60, -40, 35, -95, 12, -30, 0, -45, pd1*3, pd2*3, pd3*-2, pd4*2, pdrX*-1, pdrY*2, pdrZ*-3, 40, 30, 20, 10, 0, 40, 0) 
    translate <0, -7, 3>
    scale < 0.4, 0.4, 0.4 >
  }
}


#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 7.0;
#declare dir_camera = < 14.00, -2.00, -3.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)