/**********************************************************************************/
// Persistence of Vision Ray Tracer Scene Description File
// File name   : RandWall_mcr.pov		Version 2
// Version     : 3.6
// Description : Macro for building a stone wall with random-sized and -rotated stones
// Date        : August/30/2003
// Update			 : November 2004
// Author      : Thomas A. M. de Groot
// E-mail      : t.degroot@inter.nl.net
 
// Copyright (C) 2004. All rights reserved.
/**********************************************************************************/

#version 3.6;

#ifndef (Standalone)	#declare Standalone = true;	#end // see after macro definition

#include "rand.inc"

global_settings {
  assumed_gamma 1.0
  noise_generator 2
}
default {texture {pigment { rgb <1,0,0> }}}

//=========================================================================================================
// Macro definition:
#macro RandWall (TotLength, TotHeight, MinStoneHeight, MaxStoneHeight, StoneWidth, MinWidth, MaxWidth, Space, Cdepth, Object1, Object2, Object3, Object4, StoneTex, Cement, Moray, Stream)

  #local Seed = seed (Stream);
  #local Y = RRand(MinStoneHeight, MaxStoneHeight, Seed);
  #local MinStoneLength = 3*Y;
  #local MaxStoneLength = 13*Y;
  #local MinRot = -0.5;
  #local MaxRot =  0.5;
  #local StoneMin = 1;
  #local StoneMax = 5;
  #local L = 0;
  #local H = 0;

  #declare Wall = union {
    box {<0, 0, Cdepth>, <TotLength, TotHeight, StoneWidth-Cdepth> material {Cement} }

    #while (H < TotHeight)
    
      #while (L < TotLength)

        #local StoneLength = RRand (MinStoneLength, MaxStoneLength, Seed);
        #local StoneRot = RRand (MinRot, MaxRot, Seed);
        #local L1 = L + StoneLength + Space;
        
        //---------------------------------------------- selection of stone --------------------------------------
        #local T = RRand(StoneMin, StoneMax, Seed);
        #local T = int(T);
        #switch (T)
        #case (1)
          #local Stone = object {Stone1}
        #break
        #case (2)
          #local Stone = object {Stone2}
        #break
        #case (3)
          #local Stone = object {Stone3}
        #break
        #case (4)
          #local Stone = object {Stone4}
        #end
        //--------------------------------------------------------------------------------------------------------
      
        #if (L1 > TotLength)
          #local StoneLength = TotLength - L;
          object {Stone 
            scale <StoneLength, Y, StoneWidth> 
            translate <StoneLength/2, Y/2, StoneWidth/2>					// shift origin to centre 
            rotate StoneRot 
            translate <-(StoneLength/2), -(Y/2), -(StoneWidth/2)> // shift origin back to front-lower-left corner
            translate <L, H, RRand (MinWidth, MaxWidth, Seed)> 
            material {StoneTex translate rand(Seed)}
          }
        #else
          object {Stone 
            scale <StoneLength, Y, StoneWidth> 
            translate <StoneLength/2, Y/2, StoneWidth/2>					// shift origin to centre  
            rotate StoneRot 
            translate <-(StoneLength/2), -(Y/2), -(StoneWidth/2)> // shift origin back to front-lower-left corner 
            translate <L, H, RRand (MinWidth, MaxWidth, Seed)> 
            material {StoneTex translate rand(Seed)}
          }
        #end  //end if L1
      
        #local L = L1;
        //#debug concat("Stone", str(T,1,0), " length ", str(StoneLength,0,2), " L ", str(L,0,2), " \n")

      #end  //end while L
    
      #local H1 = H + Y + Space;
    
      #if (H1 > TotHeight)
        #local Y = TotHeight - H;
        #local L = 0;
      #else
        #local Y = RRand (MinStoneHeight, MaxStoneHeight, Seed);
        #local L = 0;

      #end  //end if H1
    
      #local H = H1;
    
    #end  //end while H
  }  //end Wall union

  // Transform for Moray.
  #if (Moray)
    #declare Wall =
      object {Wall
        scale <1,1,-1>
        rotate <90,0,0>
      }
  #end //end if Moray

#end //end of macro

//=========================================================================================================
#if (Standalone)
#include "colors.inc"

camera {
  location  <0.0, 5, -30.0>
  direction 1*z
  right     x*image_width/image_height
  look_at   <0.0, 5,  0.0>
}

sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 rgb <0.6,0.7,1.0>]
      [0.7 rgb <0.0,0.1,0.8>]
    }
  }
}

light_source {
  <0, 0, 0>            // light's position (translated below)
  color rgb <1, 1, 1>  // light's color
  translate <-30, 30, -30>
}

// ----------------------------------------
plane {
  y, 0
  pigment { color rgb <0.7,0.5,0.3> }
}

// ----------------------------------------
#declare Grnt6 =
texture {
pigment
 {granite
  turbulence 0.5
  color_map
   {[0.000, 0.153   color rgbt <0.545, 0.380, 0.345, 0.000>
                    color rgbt <0.588, 0.475, 0.333, 0.000>]
    [0.153, 0.398   color rgbt <0.588, 0.475, 0.333, 0.000>
                    color rgbt <0.675, 0.478, 0.404, 0.000>]
    [0.398, 0.559   color rgbt <0.675, 0.478, 0.404, 0.000>
                    color rgbt <0.757, 0.635, 0.522, 0.000>]
    [0.559, 0.729   color rgbt <0.757, 0.635, 0.522, 0.000>
                    color rgbt <0.659, 0.549, 0.443, 0.000>]
    [0.729, 1.001   color rgbt <0.659, 0.549, 0.443, 0.000>
                    color rgbt <0.545, 0.380, 0.345, 0.000>]
   }
 }
 }

#declare Grnt6_alt =
texture {
pigment
 {granite
  turbulence 0.5
  color_map
   {[0.000, 0.153   color rgbt <0.300, 0.300, 0.300, 0.000>
                    color rgbt <0.300, 0.300, 0.300, 0.000>]
    [0.153, 0.398   color rgbt <0.300, 0.300, 0.300, 0.000>
                    color rgbt <0.300, 0.300, 0.300, 0.000>]
    [0.398, 0.559   color rgbt <0.300, 0.300, 0.300, 0.000>
                    color rgbt <0.300, 0.300, 0.300, 0.000>]
    [0.559, 0.729   color rgbt <0.300, 0.300, 0.300, 0.000>
                    color rgbt <0.300, 0.300, 0.300, 0.000>]
    [0.729, 1.001   color rgbt <0.300, 0.300, 0.300, 0.000>
                    color rgbt <0.300, 0.300, 0.300, 0.000>]
   }
 }
 }

#declare Grnt10a =
texture {
pigment
 {granite
  turbulence 0.6
  color_map
   {[0.000, 0.179   color rgbt <0.843, 0.655, 0.655, 0.455>
                    color rgbt <0.886, 0.769, 0.627, 0.608>]
    [0.179, 0.368   color rgbt <0.886, 0.769, 0.627, 0.608>
                    color rgbt <0.906, 0.820, 0.714, 0.392>]
    [0.368, 0.538   color rgbt <0.906, 0.820, 0.714, 0.392>
                    color rgbt <0.851, 0.671, 0.671, 0.659>]
    [0.538, 0.744   color rgbt <0.851, 0.671, 0.671, 0.659>
                    color rgbt <0.890, 0.792, 0.675, 0.392>]
    [0.744, 0.983   color rgbt <0.890, 0.792, 0.675, 0.392>
                    color rgbt <0.827, 0.612, 0.612, 0.706>]
    [0.983, 1.001   color rgbt <0.827, 0.612, 0.612, 0.706>
                    color rgbt <0.843, 0.655, 0.655, 0.455>]
   }
 }
 }

#declare Stone4 =
texture {Grnt6   scale <1.5, 3, 2> rotate <0, 0, 40>
        finish{diffuse 0.5}
}
texture {Grnt10a scale <1, 3, 2> rotate <0, 0, -30>
        //finish{phong 1.0 phong_size 90}
}
#declare AltStone = texture {Stone4}

#declare Stone4a =
texture {Grnt6_alt   scale <1.5, 3, 2> rotate <0, 0, 40>
        finish{diffuse 0.5}
}

// ----------------------------------------
#declare BrickStandalone = false; // this switches off the standalone feature of Bricks.pov
#declare BrickTex = texture {Stone4} // texture for mesh2 object(s)
#include "Bricks.pov" // this is the file with mesh2 bricks
// the original stone should be a cube with its origin at the front lower left corner.
// make necessary transformations here.
#declare Stone0 = object {Irregular_brick scale <0.5, 2, 1>}
// here, the same object is used 4x:
#declare Stone1 = object {Stone0 translate 0.5}
#declare Stone2 = object {Stone0 rotate 180*y translate 0.5}
#declare Stone3 = object {Stone0 rotate 180*z translate 0.5}
#declare Stone4 = object {Stone0 rotate <0,180,180> translate 0.5}

// ----------------------------------------
// alternative, simple example:
//#declare Stone0 = box {<0, 0, 0>,<1, 1, 1> }
//#declare Stone1 = object {Stone0}
//#declare Stone2 = object {Stone0}
//#declare Stone3 = object {Stone0}
//#declare Stone4 = object {Stone0}
// ----------------------------------------

// in case you do not use mesh2 objects, you need this:
#declare Tex1 = material {texture {AltStone} }

// texture for the cement between the stones:
#declare Tex2 = material {texture {Stone4a}}

#declare Length = 100;

//usage:
  RandWall (Length,     // TotLength: Total length of the wall
            17.0,       // TotHeight: Total height of the wall
            0.5,        // MinStoneHeight: Minimum stone height
            1.8,        // MaxStoneHeight: Maximum stone height
            1.0,        // StoneWidth: Width of the stone
            -0.1,				// MinWidth: Minimum shift of stone in z-direction
            0.01,				// MaxWidth: Maximum shift of stone in z-direction
            0.1,        // Space: Space between stones
            0.1,        // Cdepth: Cement depth
            Stone1,     // Object: Type of stone
            Stone2,     // Object: Type of stone
            Stone3,     // Object: Type of stone
            Stone4,     // Object: Type of stone
            Tex1,       // StoneTex: Texture of the individual stones (not mesh2)
            Tex2,       // Cement: Texture of the cement between the tones
            false,      // Moray: Transformation for Moray yes or no
            7432        // Stream: Random number seed
   )

object {Wall 
  scale 1 
  translate <-Length/2, 0, 0>
  rotate 20*y 
}

#declare TotHeight = 17.6;

/*
cylinder {
  <0, 0, -1>, <0, TotHeight+2, -1>,  0.1
}
cylinder {
  <-100, TotHeight, -1>, <2, TotHeight, -1>,  0.1
}
*/

#end //end of Standalone