// ======================================================================
// LABORATÓRIO 03 - COMPUTAÇÃO GRÁFICA
// O TEMPLO DA COMPUTAÇÃO
// RAFAEL LAMARE SILVEIRA 009669
// ======================================================================

#include "colors.inc"

#declare semente = seed(4345);

// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2003-09-04 15:25:26 by stolfi

// ======================================================================
// CÂMERA 

camera {
  location  <  14.00, 23.00, 6.00 >  // Posição do observador.
  right     -1.0*x                // Largura RELATIVA da imagem.
  up        0.75*y                 // Altura RELATIVA da imagem.      
  sky       z                      // Qual direção é "para cima"?
  look_at   <  -3.00, 0.00, -2.00 >  // Para onde a câmera está apontando.
} 
// Nota: os parâmetros "right" e "up" devem ter a mesma proporção
// que os parâmetros ${WIDTH} e ${HEIGHT} no Makefile.

// ======================================================================
// FONTES DE LUZ

light_source {
  10 * < +50.0, +30.0, +50.0 >              // Posição da lâmpada.
  color rgb 1.2 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < +50.0, -10.0, +10.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

// ======================================================================
// DESCRIÇÃO DA CENA 

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

#declare tx_cristal = 
  texture {
    finish {
      ambient 0.1 diffuse 0.1 reflection 0.25
      specular 1 roughness 0.001
    }
    pigment { color rgb <0.5, 0.5, 1.0> filter 1 }
  }

#declare tx_cristal2 = 
  texture {
    finish {
      ambient 0.1 diffuse 0.1 reflection 0.25
      specular 1 roughness 0.001
    }
    pigment { color Brown filter 1 }
  }

#declare cor_espelho =  <1.0, 1.0, 0.3> ;

#declare tx_espelho =
  texture {
    pigment { color rgb <1.00, 1.00, 1.00> }
    finish {
      ambient 0.05 diffuse 0.05 
      reflection cor_espelho
      specular 0.20 roughness 0.05
      metallic
    }
  }

#declare pintura = 
  texture {
    pigment { color Gray60 }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

// ======================================================================
// OBJETOS

#declare predio = 
  box {
    <-13.00, 0.00, 2.00>, <7.00, 6.00, -5.00>
    texture { pintura }
    interior { ior 2.5 }
  }

#declare janelas = 
  union {
    #declare x0 = 6.50;
    #declare y0 = 6.00;
    #declare z0 = -4.00;
    #declare j = 0;

    // Loop para o número de andares (4)
    #while (j < 4)
      #declare i = 0;
      // Loop para o número de janelas por andar
      #while (i < 13)
        // Desenha uma janela de cada lado do prédio
        #declare janela_dupla = 
	  union {
            object {  
            box {
              <x0 - i*1.50, y0, z0 + j*1.50>, <x0 - i*1.50 - 1.00, y0 - 0.01, z0 + 1.00 + j*1.50>
	      // A textura da janela é escolhida aleatoriamente
	      // Ou cristal azul ou espelho dourado
  	      #if (rand(semente) < 0.50)
                texture { tx_cristal }
              #else
                texture { tx_espelho }
	      #end
            } }
            object {
            box {
              <x0 - i*1.50, 0.00, z0 + j*1.50>, <x0 - i*1.50 - 1.00, 0.00 + 0.01, z0 + 1.00 + j*1.50>
	      // A textura da janela é escolhida aleatoriamente
	      // Ou cristal azul ou espelho dourado
  	      #if (rand(semente) < 0.50)
                texture { tx_cristal }
              #else
                texture { tx_espelho }
	      #end
            } }
          }
        object { janela_dupla }
        #declare i = i + 1;
      #end
    #declare j = j + 1;
    #end
  }

#declare portao = 
  union {
    object {
      box {
        <7.00, 1.00, -5.00>, <6.99, 5.00, -1.00>
        //pigment { color Brown }
	texture { tx_cristal2 }
      }
    }
    object {
      disc {
	<7.00, 3.00, -1.00>, x, 2.00
        //pigment { color Brown }
	texture { tx_cristal2 }	
      }
    }
  }

#declare topo =
  box {
    <-12.00, 0.50, 2.00>, <6.00, 5.50, 2.50>
    texture { pintura }
    interior { ior 2.5 }
  }

#declare chao = 
  plane { z, 0
  pigment {
    brick pigment{ Gray80 }, pigment{ Gray60 }
  }
}

difference {
  union {
  object {
    union {
      object { predio }
      object { topo }
      object { janelas }
      object { portao }
    }
  }
    object { 
      chao 
      translate -5.0*z
    }
  }
  
}