!---------------------------------------------------------------
!
! TUTORIAL27 - RayDance tutorial script #27.
!
! This script demonstrates treating the camera as another
! hierarchical object.  Aside from camera treatment, however,
! it is the same as Tutorial #26.
!
! In order to view the animated frames you will need
! a way of converting the 24 bit frames to HAM (or DCTV or
! whatever format) and animation playback software.
!
! Art Department Proffesional tm works well for making HAM
! pictures from IFF24 pictures.  Possibilities for making anim
! files are BuildAnim, AStation, or DPAINT4.  DPAINTIII will
! work for playing back DCTV pictures.
!
! Concepts include :
!
!  o Attaching the camera to a hierarchical object
!
!---------------------------------------------------------------

? "TUTORIAL27 - This script contains an example of an\n",
  "hierarchical object.  This object consists of several\n",
  "rotating arms sitting atop one another.  Two of the\n",
  "arms have propellors.  Set first and last frames to 50 or\n",
  "more to create frames for an animation.  The camera,\n",
  "rather than being fixed is attached to one of the moving\n",
  "objects!\n\n";

! Colors
RED      : color( RGB, [.8, 0, 0] );
BLUE     : color( RGB, [ 0, 0,.8] );
CYAN     : color( RGB, [ 0,.8,.8] );
YELLOW   : color( RGB, [.8,.7, 0] );
GRAY     : color( RGB, [.5,.5,.5] );

OFFWHITE : color( RGB, [.8,.8,.6] );
BLACK    : color( RGB, [.1,.1,.1] );

! Create surfaces for our stuff.
MATTE  : surface(PHONG, 0.4,0.8, 0.0,  0,  0,0,0, 0, 0 );
SHINY  : surface(PHONG, 0.4,0.4, 0.1,100, .4,0,0, 0, SILVER );
BRITE  : surface(PHONG, 0.4,0.9, 0.4, 50,  0,0,0, 0, 0 );

! Start the frame loop
frameloop

  clearscene;  ! all objects must be created after this

! Arm #1 Create the first layer of hierarchy.  All other 
! objects will be positioned relative to this one.

  object( [0,0,0], [0,0,PROGRESS*-360] )

    lathe( ( [20,0,0], [20,0,50] ),
      25, 360, 0, [1,1,1], [0,0,0], [0,0,0],
      RED, MATTE, PHONG ZAXIS OPEN );

    extrude( ( [-40,0,10], [-40,0,-10], [40,0,-10], [40,0,10] ),
      400, [0,1,0], [1,1,1], [0,-150,60], [0,0,0],
      RED, MATTE, 0 );

! Arm #2, a counter rotating arm assembly atop the first one.
! The motion and position of this one will be relative to its
! position on the first one.

    object( [0,200,80], [0,0,PROGRESS*360*3] )

! The camera moves with arm #2. To make this work we must
! supply VIEWDIR and RIGHT directions.
      CAMERA'POS = [-80,-500,100];
      CAMERA'VIEWDIR = [0,1,0];
      CAMERA'RIGHT = [1,0,0];

      lathe( ( [15,0,0], [15,0,60] ),
        21, 360, 0, [1,1,1], [0,0,0], [0,0,0],
        BLUE, MATTE, PHONG ZAXIS OPEN );

      extrude( ( [-50,0,8], [-50,0,-8], [50,0,-8], [50,0,8] ),
        600, [0,1,0], [1,1,1], [0,-150,50], [0,0,0],
        BLUE, MATTE, 0 );

! The propeller assembly for arm #2.

      object( [0,400,60], [PROGRESS*360*6,0,0] )

! Propeller shaft
        lathe( ( [-85,0,0], [-77,0,6], [-70,0,12], [50,0,12],
                 [60,0,10], [61,0,0] ),
          21, 360, 0, [1,1,1], [0,0,0], [0,0,0],
          GRAY, BRITE, PHONG XAXIS );

! Propeller blade #1
        extrude( ( [-1,7,0], [-.8,7,0], [1,-7,0],[.8,-7,0] ),
          120, [0,0,1], [1,1,1], [-67,0,0], [0,0,0],
          YELLOW, BRITE, 0 );

! Propeller blade #2
        extrude( ( [-1,-7,0], [-.8,-7,0], [1,7,0],[.8,7,0] ),
          120, [0,0,-1], [1,1,1], [-67,0,0], [0,0,0],
          YELLOW, BRITE, 0 );

      endobject  ! end of arm #2 propeller assembly

! Arm #3, another arm perched atop arm #2.  This arm will also
! have a propeller assembly

      object( [0,-100,58], [0,0,PROGRESS*360*2] )

        lathe( ( [15,0,0], [15,0,90] ),
          21, 360, 0, [1,1,1], [0,0,0], [0,0,0],
          CYAN, BRITE, PHONG ZAXIS OPEN );

        extrude( ( [-30,0,8], [-30,0,-8], [30,0,-8], [30,0,8] ),
          200, [0,-1,0], [1,1,1], [0,50,90], [0,0,0],
          CYAN, MATTE, 0 );

! The propeller assembly for arm #3.

        object( [0,-100,90], [PROGRESS*-360*7,0,0] )

! Propeller shaft
        lathe( ( [-50,0,0], [-47,0,6], [-40,0,12], [35,0,12],
                 [40,0,10], [45,0,0] ),
          21, 360, 0, [1,1,1], [0,0,0], [0,0,0],
          GRAY, BRITE, PHONG XAXIS );

! Propeller blade #1
          extrude( ( [-1,7,0], [-.8,7,0], [1,-7,0],[.8,-7,0] ),
            80, [0,0,1], [1,1,1], [-37,0,0], [0,0,0],
            YELLOW, BRITE, 0 );

! Propeller blade #2
          extrude( ( [-1,-7,0], [-.8,-7,0], [1,7,0],[.8,7,0] ),
            80, [0,0,-1], [1,1,1], [-37,0,0], [0,0,0],
            YELLOW, BRITE, 0 );

        endobject  ! end of arm #3 propeller assembly

      endobject  ! end of arm #3
    endobject  ! end of arm #2
  endobject  ! end of arm # 1

! Specify the lighting.
  ambient( [0,0,0], [0.6,0.6,0.6], [0,0,1], 0, 0 );
  star( [40000,-50000,60000], [1,.9,1], 3000 );

! A gingham ground to fly over
  ground( GINGHAM, 0, 400, OFFWHITE, SHINY, BLACK, SHINY );

! A plain black background
  background( PLAIN, [0,0,0] );

  render;

nextframe  ! end of the frame loop

END
