#include "colors.inc"
#include "shapes.inc"
#include "camlight.inc"
#include "eixos.inc"

#declare component_color_red = texture {
  pigment { color rgb <0.7, 0.12, 0.12> }
  finish{ diffuse 0.8 ambient 0.1 specular 0.4 roughness 0.5 }
}

#declare component_color_blue = texture {
  pigment { color rgb <0.12, 0.12, 0.7> }
  finish{ diffuse 0.8 ambient 0.1 specular 0.4 roughness 0.5 }
}

#declare component_color_green = texture {
  pigment { color rgb <0.12, 0.7, 0.12> }
  finish{ diffuse 0.8 ambient 0.1 specular 0.4 roughness 0.5 }
}

#declare component_color_yellow = texture {
  pigment { color rgb <0.12, 0.7, 0.7> }
  finish{ diffuse 0.8 ambient 0.1 specular 0.4 roughness 0.5 }
}

#declare component_color_any = texture {
  pigment { color rgb <0.7, 0.12, 0.7> }
  finish{ diffuse 0.8 ambient 0.1 specular 0.4 roughness 0.5 }
}


#declare SEGMENT_SIZE = <0, 1, 0>;

#macro Segment(a1, a2, a3)
  union {
    sphere { 0.0, 0.25 }
    object {
      cylinder { <0, 0, 0>, SEGMENT_SIZE, 0.2 }
      rotate <a1, a2, a3>
    }
  }
#end

#macro Seg0(a)
  object { 
    Segment(a, 0, 0)
    texture { component_color_blue }
  }
#end

#macro Seg1(a, b)
  union {
    object {
      Segment(a, 0, 0)
      texture { component_color_green }
    }

    object {
      Seg0(b)
      translate SEGMENT_SIZE
      rotate <a, 0, 0>
    }
  }
#end

#macro Seg2(a, b, c)
  union {
    object {
      Segment(a, 0, 0)
      texture { component_color_red }
    }

    object {
      Seg1(b, c)
      translate SEGMENT_SIZE
      rotate <a, 0, 0>
    }
  }
#end

#macro Seg3(a, b, c, d)
  union {
    object {
      Segment(a, 0, 0)
      texture { component_color_any }
    }

    object {
      Seg2(b, c, d)
      translate SEGMENT_SIZE
      rotate <a, 0, 0>
    }
  }
#end

#macro Seg4(a, b, c, d, e)
  union {
    object {
      Segment(a, 0, 0)
      texture { component_color_yellow }
    }

    object {
      Seg3(b, c, d, e)
      translate SEGMENT_SIZE
      rotate <a, 0, 0>
    }
  }
#end

#macro DragaoMosquito(position, 
  l0_a, l0_b, l0_c, l0_d, l0_e, 
  l1_a, l1_b, l1_c, l1_d, l1_e, 
  l2_a, l2_b, l2_c, l2_d, l2_e, 
  d0_a, d0_b, d0_c, d0_d, d0_e, 
  d1_a, d1_b, d1_c, d1_d, d1_e, 
  d2_a, d2_b, d2_c, d2_d, d2_e)

union {

  //Body 
  sphere {
    0, 2
    texture { component_color_red }
  }

  sphere {
    <0, 0, -2>, 1.5
    texture { component_color_green }
  }

  sphere {
    <0, 0, 2>, 1.5
    texture { component_color_blue }
  }
  

  //D0
  object {
    Seg4(d0_a, d0_b, d0_c, d0_d, d0_e)
    translate <0, 1.5, 2>
  }

  //D1
  object {
    Seg4(d1_a, d1_b, d1_c, d1_d, d1_e)
    translate <0, 2, 0>
  }

  //D2
  object {
    Seg4(d2_a, d2_b, d2_c, d2_d, d2_e)
    translate <0, 1.5, -2>
  }

  //L0
  object {
    Seg4(l0_a, l0_b, l0_c, l0_d, l0_e)
    translate <0, 1.5, 2>
    scale <0, -1, 0>
  }

  //L1
  object {
    Seg4(l1_a, l1_b, l1_c, l1_d, l1_e)
    translate <0, 2, 0>
    scale <0, -1, 0>
  }

  //L2
  object {
    Seg4(l2_a, l2_b, l2_c, l2_d, l2_e)
    translate <0, 1.5, -2>
    scale <0, -1, 0>
  }
}

#end

// SCENE

#declare center = <0.00, 0.00, 0.00>;
#declare scene_radius = 10.0;
#declare camera_direction = <4.00, 0.00, 0.00>;
#declare camera_distance = 5 * scene_radius;
#declare light_intensity = 0.6;

camlight(
  center, 
  scene_radius, 
  camera_direction, 
  camera_distance,
  z, 
  light_intensity
)

background { color rgb <0.7, 0.7, 0.7> }

DragaoMosquito(
  <0, 0, 0>,
   45, -45, -45,  45,  12,
  -45,  45, -45,  45,  12,
  -45, -45, -45,  45,  12,
   45,  45, -45,  45, -12,
  -45, -45,  45,  45,  12,
  -45, -45, -45,  45, -12
)