// ======================================================================
// MC937A/MO603A – Computacao Grafica - 2023-S2
// Trabalho de laboratorio 01 - 2023-08-23
// Hiperxadrez
//
// RA108231 - Oscar dos Santos Esgalha Neto
// ======================================================================
background{ color rgb < 0.7, 0.7, 0.9 > }


#declare tx_laranja = 
  texture{
    pigment{ color rgb < 0.9, 0.5, 0.1 > }
    finish{ diffuse 0.8 ambient 0.1 }
  }

#declare tx_roxo = 
  texture{
    pigment{ color rgb < 0.5, 0.1, 0.5 > }
    finish{ diffuse 0.8 ambient 0.1 }
  }

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.0, 0.0, 0.0 >, color rgb < 1.00, 1.00, 1.00 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 0.5
  }

// ======================================================================
// Pecas
// ======================================================================
#declare corpopeao =
  box{ <0,0,0>, <1,1,+2> }
#declare corpodama =
  cone{ < 0, 0, 0 >, 1, < 0, 0, 2 >, 0.1 }
#declare pe =
  box{ <0,0,0>, <1,0.5,0.5> }
#declare cabeca =
  sphere{ < 0.00, 0.00, 0.00 >, 0.65 }
#declare hiperpeao =
union {
  object{ corpopeao translate < -0.5,-0.5,0.5 > }
  object{ pe translate < 0,0.1,0 > }
  object{ pe translate < 0,-0.6,0 > }
  object{ cabeca translate < 0,0,3 > }
  texture { tx_laranja }
}
#declare hiperdama =
union {
  object{ corpodama translate < -0.2,0,0.5 > }
  object{ pe translate < 0,0.1,0 > }
  object{ pe translate < 0,-0.6,0 > }
  object{ cabeca translate < 0,0,3 > }
  texture { tx_roxo }
}
// ======================================================================
// Casas
// ======================================================================
#declare casa =
  box{ <0,0,0>, <2,2,0> }

#macro tabuleiro (m, n)
  #local angulo_casa = 360/n;
  union {
    #local i = 1;
    #while ( i <= m )
      #local j = 1;
      #while (j <= n)
        object{ casa translate < i * 4, 0, -0.5 > rotate < 0, 0, angulo_casa*j > texture{ tx_xadrez } }
        #if (mod(i, 2) = 0 & mod(j, 3) = 0)
          object{ hiperpeao translate < i * 4, 0, -0.5 > rotate < 0, 0, angulo_casa*j >  }
        #end
        #if (mod(i, 2) = 1 & mod(j,2) = 0)
          object{ hiperdama translate < i * 4, 0, -0.5 > rotate < 0, 0, angulo_casa*j >  }
        #end
        #local j = j + 1;
      #end
      #local i = i + 1;
    #end
  }
#end

object { tabuleiro(3, 6) }


#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 3.00 >;
#declare raio_cena = 20.0;
#declare dir_camera = < 5.00, 3, 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)