!---------------------------------------------------------------
!
! TUTORIAL23 - RayDance tutorial script #23.
!
! This script demonstrates replicas and haze.
!
! Concepts include :
!
!  o Replicas
!  o Haze
!  o Boundary volumes
!
! NOTE: Be sure to click on the HAZE gadget in the Command
! Window of the user interface.
!
!---------------------------------------------------------------

? "TUTORIAL23 - This script uses replicas to create several\n",
  "rows of columns.  Atmospheric haze is specified so they\n",
  "fade off into the distance.\n\n",
  "NOTE: Be sure HAZE is enabled on the Command Window!\n\n";

! Variables
real  Y;

! Load the maps
BRICKS_TXA : texturemap( "bricks4.ilbm" );
BRICKS_BMA : bumpmap( "brickbumps4b.ilbm" );

! Create colors
YELLOW : color( RGB, [.8,.8,.1] );

! Create surfaces for our stuff.
MATTE : surface(PHONG, 0.4,.8, 0, 0, 0,0,0, 0, 0 );
SHINY : surface(PHONG, 0.4,.8,.4,30, 0,0,0, 0, 0 );

! Create the bump and texture maps for the ground plane.  Note
! that the width and height parameters must be the same or it
! won't work right.
TXTURE : texture( PLANE, BRICKS_TXA, [0,0,0],
  [0,0,1], [1,0,0], 100,100,100, 1,1, REPEAT SMOOTH3 );

BUMPS : bump( PLANE, BRICKS_BMA, MATTE, 1.0, [0,0,0],
  [0,0,1], [1,0,0], 100,100,100, 1,1, REPEAT );

! Our ground is covered with bricks.
GROUND( PLAIN, 0, TXTURE, BUMPS );  ! Below sea level

! Build the first object using the an imported outline and two
! lathe statements.  Enclose this object in a NAMED boundary for
! later use in the REPLICAS
COLUMN_OUTLINE : outline( "column_outline.geo", [1,1,4], xz );

COLUMN : boundary( [200,0,0] )  ! a named and positioned boundary

! Column base
  lathe( ( [0,0,0], [20,20,0], [20,20,4], [0,0,4] ),
    4, -360, 0, [ 2,2,2], [200,0,0], [0,0,0],
    YELLOW, SHINY, ZAXIS );

! Column proper
  lathe( ( column_outline ),
    25, -360, 0, [2,2,2], [200,0,4], [0,0,0],
      YELLOW, SHINY, PHONG ZAXIS );

endboundary


! Now use looping to create rows of columns...
Y = 0;
while (Y < 5000) {
!           parent    pos      rotation
  if (Y > 500) {
    replica( COLUMN, [-1000,Y,0], [0,0,0] );
  }
  replica( COLUMN, [-600,Y,0], [0,0,0] );
  replica( COLUMN, [-200,Y,0], [0,0,0] );
  if (Y > 0) {
    replica( COLUMN, [200,Y,0], [0,0,0] );
  }
  replica( COLUMN, [600,Y,0], [0,0,0] );
  if (Y > 500) {
    replica( COLUMN, [1000,Y,0], [0,0,0] );
  }
  Y = Y + 500;
}

! 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], 300 );

! A sky background.  Horizon will be quite light and hazy.
! The zenith will be darker,
!                hor color   zen color   nad color  factor
BACKGROUND( SKY, [.8,.7,.7], [.1,.3,.6], [.8,.7,.7], .7 );

! The haze will derive its color from the background (sky).
!         mode       zen    hor   nad   change start max
!                    vis    vis   vis    rate   dis  haze
SETHAZE( BACKGROUND, 10000, 5000, 10000, .8,    0,    1 );

! The camera looks up the positive y axis
CAMERA'POS = [0,-1000,250];
CAMERA'TARGET = [0,0,250];

RENDER;

END
