// Last edited on DATE TIME by USER
// Processed by remove-cam-lights

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

#declare tx_red =
texture{
  pigment{ color rgb < 0.90, 0.20, 0.20 > }
  finish{ diffuse 0.8 ambient 0.4 specular 0.5 roughness 0.005 }
}

#declare tx_blue =
texture{
  pigment{ color rgb < 0.30, 0.30, 1.0 > }
  finish{ diffuse 0.8 ambient 0.5 specular 0.7777777 roughness 0.005 }
}

#declare tx_green =
texture{
  pigment{ color rgb < 0.20, 0.90, 0.20 > }
  finish{ diffuse 0.8 ambient 0.4 specular 0.5 roughness 0.005 }
}

#declare tx_steel =
texture{
  pigment { rgb <0.55, 0.5, 0.45> }
  finish { metallic ambient 0.1 diffuse 0.65 specular 0.85 roughness 0.01 reflection 0.45 brilliance 1.5}
}

#declare tx_black =
texture{
  pigment{ color rgb < 0.30, 0.30, 0.30 > }
  finish{ diffuse 0.5 ambient 0.2 }
}

#declare tx_glass =
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 zero = 0.0000001;
#declare rseed = seed(10);

#macro wheel (R)
  union {
    torus {R,R/12 texture {tx_black}}
    #local i=0;
    #while (i<8)
      cylinder {<-R,0,0>,<R,0,0>,R/20 rotate<0,i*45,0> texture {tx_steel}}
      #local i=i+1;
    #end
  }
#end

#macro axle (R,A)
  union {
    object {wheel(R) translate <0,(-A/2)-(R/12),0>}
    object {wheel(R) translate <0,(A/2)+(R/12),0>}
    cylinder {<0,(-A/2)-(R/12),0>,<0,(A/2)+(R/12),0>,R/18 texture {tx_steel}}
  }
#end

#macro wheeledSeat (L,H,R)
  union {
    object {axle (R,L) translate <0,0,(-R/2)-(R/18)>}
    translate <0,0,(-H/2)+(R/7)>
  }
#end

#macro easyBezier (A)
  object { retalho (A[0][0],A[0][1],A[0][2],A[0][3],A[1][0],A[1][1],A[1][2],A[1][3],A[2][0],A[2][1],A[2][2],A[2][3],A[3][0],A[3][1],A[3][2],A[3][3], zero, tx_blue, tx_red) }
#end

#macro squareBezierPatch (L,ff)
  #local A = array[4][4];
  #local i=0;
  #while (i<4)
    #local j=0;
    #while (j<4)
      #if ((mod(i,3)*mod(j,3))=0)
        #local A[i][j] = <i*(L/3),j*(L/3),0>;
      #else
        #local A[i][j] = <i*(L/3),j*(L/3),ff>;
      #end
      #local j=j+1;
    #end
    #local i = i+1;
  #end

  object {easyBezier(A) translate <-L/2,-L/2,0>}
#end

#macro waveBezier (X,Y,Z,ff)

  #local A = array[4][4];
  #local A[0][0] = <0,0,0>;
  #local A[0][1] = <X/3,0,0>;
  #local A[0][2] = <2*X/3,0,0>;
  #local A[0][3] = <X,0,0>;

  #local A[1][0] = <0,Y/3,ff>;
  #local A[1][1] = <X/3,Y/3,ff>;
  #local A[1][2] = <2*X/3,Y/3,ff>;
  #local A[1][3] = <X,Y/3,ff>;

  #local A[2][0] = <0,2*Y/3,Z-ff>;
  #local A[2][1] = <X/3,2*Y/3,Z-ff>;
  #local A[2][2] = <2*X/3,2*Y/3,Z-ff>;
  #local A[2][3] = <X,2*Y/3,Z-ff>;

  #local A[3][0] = <0,Y,Z>;
  #local A[3][1] = <X/3,Y,Z>;
  #local A[3][2] = <2*X/3,Y,Z>;
  #local A[3][3] = <X,Y,Z>;

  union {
    object {easyBezier(A) translate <-X/2,-Y/2,-Z/2> rotate <0,0,90>}
  }
#end

#macro curveBack (X,Y,Z,ff)
  union {
    object {waveBezier(X,Y,Z,ff)}
    object {waveBezier(X,Y,Z,ff) rotate<0,0,180> rotate<180,0,0> translate<-X,0,Z>}
    scale <1,1,0.5>
  }
#end

#macro endBezierPatch (L,ff)
  #local A = array[4][4];
  #local i=0;
  #while (i<4)
    #local j=0;
    #while (j<4)
      #if ((mod(i,3)*j)=0)
        #local A[i][j] = <i*(L/3),j*(L/3),0>;
      #else
        #local A[i][j] = <i*(L/3),j*(L/3),ff>;
      #end
      #local j=j+1;
    #end
    #local i = i+1;
  #end

  object {easyBezier(A) translate <-L/2,-L/2,0>}
#end

#macro curveBezier (L,H,D)
  #local A = array[4][4];
  #local A[0][0] = <0,0,0>;
  #local A[0][1] = <L/3,0,0>;
  #local A[0][2] = <2*L/3,0,0>;
  #local A[0][3] = <L,0,0>;

  #local A[1][0] = <0,0,H>;
  #local A[1][1] = <L/3,0,H>;
  #local A[1][2] = <2*L/3,0,H>;
  #local A[1][3] = <L,0,H>;

  #local A[2][0] = <0,D,H>;
  #local A[2][1] = <L/3,D,H>;
  #local A[2][2] = <2*L/3,D,H>;
  #local A[2][3] = <L,D,H>;

  #local A[3][0] = <0,D,H/3>;
  #local A[3][1] = <L/3,D,H/3>;
  #local A[3][2] = <2*L/3,D,H/3>;
  #local A[3][3] = <L,D,H/3>;

  object {easyBezier(A) translate <-L/2,-D/2,0>}
#end

#macro recBezier (L,W,ff)
  object {squareBezierPatch (L,ff) scale<1,W/L,1>}
#end

#macro cushion (X,Y,Z,ff)
  union {
    object {recBezier (X,Y,ff) translate <0,0,Z/2>}
    object {recBezier (X,Y,ff) rotate<0,180,0> translate<0,0,-Z/2>}
    object {recBezier (X,Z,ff) rotate<90,0,0> translate<0,-Y/2,0>}
    object {recBezier (X,Z,ff) rotate<270,0,0> translate<0,Y/2,0>}
    object {recBezier (Z,Y,ff) rotate<0,90,0> translate<X/2,0,0>}
    object {recBezier (Z,Y,ff) rotate<0,270,0> translate<-X/2,0,0>}
  }
#end

#macro backrest (L,ff)
  union {
    object {endBezierPatch (L,ff)}
    object {endBezierPatch (L,ff) rotate <0,0,180> translate<0,L,0>}
    rotate <90,0,0>
    rotate <0,0,90>
  }
#end

#macro simpleSeat (X,Y,Z,ff)
  union {
    object {wheeledSeat ((X+ff),2,3)}
    object {backrest (X,ff) translate <-X/2,0,Z>}
    object {cushion (X,Y,Z,ff)}
  }
#end

#macro superSeat (X,Y,Z,H,ff)
  union {
    object {wheeledSeat ((X+ff),2,3)}
    object {curveBack (X/10,Y,H,ff) translate <-X/2,0,Z>}
    object {cushion (X,Y,Z,ff)}
  }
#end

#include "eixos.inc"
#include "retalho.inc"
union {
  object {simpleSeat (4,4,2,1.5) translate <0,-3,0>}
  object {simpleSeat (4,4,2,0) translate <0,3,0>}

}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 20;
#declare dir_camera = < 20, 20, 30 >;
#declare dist_camera = 16.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)