// Last edited on 2023-12-24 14:55:40 by stolfi
background{ color rgb < 0.910, 0.900, 0.930 > }

// ======================================================================
// CORES E TEXTURAS
#declare tx_fosca = 
  texture{
    pigment{ color rgb < 0.00, 0.50, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

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

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

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

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

#macro dedo(a1_4)
    #local de = cylinder{<0,0,0>, <0.8,0,0>, 0.1}

    union {
        object{de rotate<0, a1_4, 0>}
    }
#end

#macro submembro(a1_3, a1_4)
    #local tronco = cylinder{<0,0,0>, <0,0,-2>, 0.3}

    union {
        object{tronco}
        object{dedo(a1_4) translate <0.2, 0, -2> rotate <0, 0, 0>}
        object{dedo(a1_4) translate <0.2, 0, -2> rotate <0, 0, 120>}
        object{dedo(a1_4) translate <0.2, 0, -2> rotate <0, 0, 240>}
    } 
#end


#macro membro(a1_3, a1_4) 
    #local tronco = cylinder{<0,0,0>, <0,0,-2>, 0.3}

    #local sub = object{submembro(a1_3, a1_4)}

    union {
        object{tronco}
        sphere{<0, 0, -2>, 0.3}
        object{sub rotate<0, -a1_3, 0> translate <0, 0, -2> }
    } 
#end

#macro cabeca()
    union {
        sphere{<0, 0, 0.5>, 0.7}
    }
#end

#macro superior_sub(P3, P4)
    #local pesc = cylinder{<0,0,0>, <0,0, 0.5>, 0.4}
    #local cab = cabeca()

    union {
        object{pesc}
        object{cab rotate <P3, 0, P4> translate<0, 0, 0.5>}
    }
#end

#macro superior(P2, P3, P4) 
    #local c1 = cylinder{<0,0,0>, <0,0, 0.5>, 0.5}
    

    union {
        object{c1}
        sphere{<0, 0, 0.5>, 0.4}
        object{superior_sub(P3, P4) rotate<0, P2, 0> translate<0, 0, 0.5>}
    }
#end

#macro robo(E1_1, E1_2, E1_3, E1_4,
            E2_1, E2_2, E2_3, E2_4,
            D1_1, D1_2, D1_3, D1_4,
            D2_1, D2_2, D2_3, D2_4,
            P1, P2, P3, P4)
    #local corpo = box {
        <-2, -0.5, -2.5>
        <2, 0.5, 2.5>
    } 

    union {
        object{corpo texture{tx_fosca}}
        object{membro(D2_3, D2_4) rotate <0, D2_1, D2_2> translate <-2, 0, -2.5> 
         texture{tx_fosca}}
        object{sphere{<-2, 0, -2.5>, 0.3} texture{tx_fosca}}

        object{membro(E2_3, E2_4) rotate <0, E2_1, E2_2> translate <-2, 0, -2.5> 
         scale <-1, 1, 1> texture{tx_fosca}}
        object{sphere{<2, 0, -2.5>, 0.3} texture{tx_fosca}}

        object{membro(D1_3, D1_4) rotate <0, D1_1, D1_2> translate <-2.3, 0, 2.5> 
         texture{tx_fosca}}
        object{sphere{<-2.3, 0, 2.5>, 0.3} texture{tx_fosca}}

        object{membro(E1_3, E1_4) rotate <0, E1_1, E1_2> translate <-2.3, 0, 2.5> 
         scale <-1, 1, 1> texture{tx_fosca}}
        object{sphere{<2.3, 0, 2.5>, 0.3} texture{tx_fosca}}

        object{superior(-P2, -P3, -P4) rotate <-P1, 0, 0> translate <0, 0, 2.5> texture{tx_fosca}}
    }
#end

#declare DX = 6;
#declare DY = 5;
#declare DZ = 8;

union {
  object{ robo(26,  5, 32, 13,  36, 19,  9, 35,  25, 47, 27, 8,   4, 14, 17, 2,  12, 42, 20, 28) translate -DY*y }
  object{ robo(90,-75,-32,-53,  70, 39,-59, 35,  80,-15,-27, 8,  45,-30, 57, 2,  12, 42, 20, 28) translate +DY*y }
}

#declare cmin = < -DX, -2*DY, -DZ >;
#declare cmax = < +DX, +2*DY, +DZ-1 >;

#include "gaiola.inc"
//object{ gaiola(cmin,cmax) }

#declare centro_cena = (cmin + cmax)/2;
#declare raio_cena = 0.50*vlength(cmax-cmin);
#declare dist_camera = 7*raio_cena;

#include "camlight.inc"
#declare dir_camera = < 7, 5, 2 >;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)