// Last edited on 2019-07-17 13:27:38 by stolfilocal
// Processed by remove-cam-lights

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

#declare tx_mosdragon =
    texture{
     pigment{ color rgb < 0.6, 0.4, 0.2 > }
     finish{ diffuse 0.9 ambient 0.1 }
}

#include "eixos.inc"
#include "frames.inc"

#macro interpola_linear(T,T0,T1,P0,P1)
  (P0+(T-T0)/(T1-T0)*(P1-P0))
#end

#macro interpola_3d(T, T0, T1, P0, P00, P1, P11)
  (P0*pow((1-((T-T0)/(T1-T0))),3) + P00*3*((T-T0)/(T1-T0))*pow((1-((T-T0)/(T1-T0))),2) + 3*P11*pow(((T-T0)/(T1-T0)),2)*(1-((T-T0)/(T1-T0))) + pow(((T-T0)/(T1-T0)),3)*P1)
#end

#macro interpola_linear_matriz(P,Q,N,C0,C1,CC)

  #local A = array[N][3];

  #local I = 0;
  #while (I < N)
    #local K = 0;
    #while (K < 3)
        #local A[I][K] = interpola_linear(CC,C0,C1,P[I][K],Q[I][K]);
        #local K = K + 1;
    #end
    #local I = I + 1;
  #end
  A
#end

#macro get_membro (I, N, P)
  #local R = array[N][3];

  #for (J, 0, N-1,1)
    #for (K, 0, 2, 1)
      #local R[J][K] = P[I][J][K];
    #end
  #end
  R
#end

#macro busca_tempo (clk, NK, TK)
  #local K = 0;
  #local find = 0;

  #while ((K < NK-1) & (find = 0))
    #if ((TK[K] <= clk) & (TK[K+1] >= clk))
      #local find = 1;
    #else
      #local K = K + 1;
    #end
  #end
  K
#end

#macro mosdragon(L, R)
  union{
    object{
      cylinder{
        <0,0,0>, <0,0,5>, 1
        texture {tx_mosdragon}
      }
    }
    object{
      coxa(L,R)
      rotate<0,0,90>
      translate<0,1,0>
    }
    object{
      coxa(L,R)
      rotate<0,-45,90>
      translate<0,1,2>
    }
    object{
      coxa(L,R)
      rotate<0,-60,90>
      translate<0,1,4>
    }
    object{
      coxa(L,R)
      translate<1,0,0>
    }
    object{
      coxa(L,R)
      rotate<0,90,90>
      translate<1,0,2>
    }
    object{
      coxa(L,R)
      rotate<0,90,90>
      translate<1,0,4>
    }
  }
#end

#macro coxa (L, R)

  union{

    object{
      sphere{
        <0, 0, 0>, 0.4
        texture {tx_mosdragon}
      }
    }

    object{
      cylinder{
        <0,0,0>, <L[0],0,0>, 0.2
        texture {tx_mosdragon}
      }
    }

    object{
      ante_coxa(L, R)
      rotate<R[0][0],R[0][1],R[0][2]>
      translate<L[0],0,0>
    }

  }

#end

#macro ante_coxa (L, R)

  union{

    object{
      sphere{
        <0, 0, 0>, 0.4
        texture {tx_mosdragon}
      }
    }

    object{
      cylinder{
        <0,0,0>, <L[1],0,0>, 0.2
        texture {tx_mosdragon}
      }
    }

    object{
      meio_perna(L, R)
      rotate<R[1][0],R[1][1],R[1][2]>
      translate<L[1],0,0>
    }

  }

#end

#macro meio_perna (L, R)

  union{

    object{
      sphere{
        <0, 0, 0>, 0.4
        texture {tx_mosdragon}
      }
    }

    object{
      cylinder{
        <0,0,0>, <L[2],0,0>, 0.2
        texture {tx_mosdragon}
      }
    }

    object{
      ante_pe(L, R)
      rotate<R[2][0],R[2][1],R[2][2]>
      translate<L[2],0,0>
    }

  }

#end

#macro ante_pe (L, R)

  union{

    object{
      sphere{
        <0, 0, 0>, 0.4
        texture {tx_mosdragon}
      }
    }

    object{
      cylinder{
        <0,0,0>, <L[3],0,0>, 0.2
        texture {tx_mosdragon}
      }
    }

    object{
      pe(L)
      rotate<R[3][0],R[3][1],R[3][2]>
      translate<L[3],0,0>
    }

  }

#end

#macro pe (L)

  union{

    object{
      sphere{
        <0, 0, 0>, 0.4
        texture {tx_mosdragon}
      }
    }

    object{
      cylinder{
        <0,0,0>, <L[4],0,0>, 0.2
        texture {tx_mosdragon}
      }
    }
  }

#end

#macro quadro(tt)
  #declare P = membros();

  #declare L = array[5];
  #declare L[0] = 2;
  #declare L[1] = 3;
  #declare L[2] = 4;
  #declare L[3] = 2;
  #declare L[4] = 1;

  #declare TK = array[6];
  #declare TK[0] = 0;
  #declare TK[1] = 0.2;
  #declare TK[2] = 0.4;
  #declare TK[3] = 0.6;
  #declare TK[4] = 0.8;
  #declare TK[5] = 1;

  #declare I = busca_tempo (clock, 6, TK);

  #declare P1 = get_membro(I, 4, P);
  #declare P2 = get_membro(I+1, 4, P);
  #declare G = interpola_linear_matriz(P1,P2,4,TK[I],TK[I+1],clock);

  mosdragon(L, G)
#end

union{
  eixos (3)

  quadro(clock)
}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 17;
#declare dir_camera = < 1.0, 1.0, 1.0 >;

#declare dist_camera = 4*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)