// 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

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


#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 7.0;
#declare dir_camera = < 14.00, 10.00, 4.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)
// macro nave alienígena
// macro nave terrestre
// tem que ter parâmetro pra mudar algum detalhe da nave (cor, tamanho, direção, etc.)
// #debug concat("coisas = ", str(coisas,0,6), "\n")


// cylinder{p,q,r  rotate 30*z }
// object{ banana(20,N) rotate 30*z }