// Persistence of Vision Ray Tracer Scene Description File // File: Books.inc // Vers: 3.01 Watcom Win32 // Desc: A file for the creation of rows or stacks of books // Date: April 18, 1997 // Auth: Sonya Roberts // Note: Creates simple books shapes that are meant to be // seen from a distance, not closeup; the books are // only minimally detailed. // ---------- // Modified // Date : May 19, 1997 // Auth : Luc Coiffier // Note : The code is modified to add a slight tilt to shelved books // ******************************************************************* // Date : Nov 1998 // Further modified by David Wilkinson // bugs in titles cleared and title macro added // textures made finer // macros introduced to make the program shorter & more understandable // variables initialised to give more realistic books // ******************************************************** #ifndef (Black) #include "colors.inc" #end #debug "\nBooks.inc\n" #ifndef (RowLength) #declare RowLength=1.5; #end // How long a row of books to create (X-Axis) #ifndef (RowHeight) #declare RowHeight=.40; #end // How tall a row of books to create (Y-Axis) #ifndef (RowDepth) #declare RowDepth=.30; #end // How deep a row of books to create (Z-Axis) #ifndef (NumBooks) #declare NumBooks=10; #end // Approximate number of books in the row #ifndef (VariThick) #declare VariThick=.40; #end // Decimal Percentage by which thickness of books are to vary. #ifndef (VariHeight) #declare VariHeight=.15; #end // Decimal Percenatge by which height of books are to vary. #ifndef (VariDepth) #declare VariDepth=.15; #end // Decimal Percentage by which depth of books are to vary. #ifndef (BookSeed) #declare BookSeed=seed(1); #end // Seed value to use for random numbers #ifndef (VariColours) #declare VariColours=true; #end // If true, colours of bindings are random; otherwise uses a supplied texture #ifndef (VariAlign) #declare VariAlign=.1; #end // Decimal Percentage of RowDepth by which spines of books are to misaligned #ifndef (StackStyle) #declare StackStyle=0; #end // 0=Shelved (Bottom Edges Even), 1=Nicely Stacked, 2=Messily Stacked #ifndef (FillerColour) #declare FillerColour=1; #end // 0=Plain White, 1=Gray Gradient #ifndef (ExactLength) #declare ExactLength=true; #end // false=NumBooks More Important Than RowLength, true=Vice Versa #ifndef (Titles) #declare Titles=true; #end // false=Plain Covers, true=Titles on Spines // Added by Luc Coiffier #ifndef (Tilted) #declare Tilted=true; #end // false=vertical books, true=tilted books (shelved books only) #ifndef (MaxTiltedAngle) #declare MaxTiltedAngle=10; #end // Max angle for tilted books #ifndef (VariTilted) #declare VariTilted = 0.20; #end // Decimal percentage of tilted books // Added by David Wilkinson #macro BookTitles (X1) #local Sw1=X1; #if (Sw1>10) #declare Sw1=mod(Sw1,10); #end #switch (Sw1) #case (1) #declare BookTitle="War and Peace" #break #case (2) #declare BookTitle="Anna Karenina" #break #case (3) #declare BookTitle="Pride and Prejudice" #break #case (4) #declare BookTitle="Sense and Sensibility" #break #case (5) #declare BookTitle="Moby Dick" #break #case (6) #declare BookTitle="Jude the Obscure" #break #case (7) #declare BookTitle="Middlemarch" #break #case (8) #declare BookTitle="Huckleberry Finn" #break #case (9) #declare BookTitle="David Copperfield" #break #case (10) #declare BookTitle="Great Expectations" #end // end of switch #declare TextColor=int(rand(BookSeed)*3.9); text { ttf "timrom.ttf" BookTitle 0.1,0 translate <0,-.25,0> scale rotate z*-90 translate <0,BookHeight*.95,-BookWidth/8> #switch (TextColor) #case (0) pigment {color Bindings*1.4} #break #case (1) pigment {Gold} #break #case (2) pigment {Black} #break #case (3) pigment {White} #break #end } #end // end of BookTitle macro #macro PagesEdge () box { <-(BookWidth/2),BookHeight*.025,0>, scale <.9,1,1> #switch (FillerColour) #case (0) // Default Plain White pigment {color White} finish {ambient .3} #break #case (1) // Gray Gradient texture { pigment { gradient x turbulence 0.01 color_map { [0.00 color rgb<1.000, 1.000, 1.000>] [0.05 color rgb<0.753, 0.753, 0.753>] [0.05 color rgb<0.918, 0.918, 0.918>] [0.09 color rgb<0.718, 0.718, 0.718>] [0.15 color rgb<0.816, 0.816, 0.816>] [0.21 color rgb<0.918, 0.918, 0.918>] [0.25 color rgb<0.784, 0.784, 0.784>] [0.28 color rgb<0.980, 0.980, 0.980>] [0.36 color rgb<0.710, 0.710, 0.710>] [0.42 color rgb<0.867, 0.867, 0.867>] [0.47 color rgb<0.933, 0.933, 0.933>] [0.59 color rgb<0.675, 0.675, 0.675>] [0.68 color rgb<1.000, 1.000, 1.000>] [0.75 color rgb<0.776, 0.776, 0.776>] [0.84 color rgb<0.878, 0.878, 0.878>] [0.92 color rgb<1.000, 1.000, 1.000>] [0.95 color rgb<0.784, 0.784, 0.784>] [1.00 color rgb<1.000, 1.000, 1.000>] } } finish { ambient 0.5 brilliance 1.5 } scale translate } #break #end // of case } // end of box #end #macro CoverTexture(Bindings) texture { pigment {color Bindings} normal { bumps 0.3 turbulence < 0.600, 0.600, 0.600 > scale 0.001 } finish { ambient < 0.100, 0.100, 0.100 > diffuse .3 reflection < 0.000, 0.000, 0.000 > phong .3 phong_size 8 } } #end // end of CoverTexture macro #if (VariColours=false) #declare Bindings=rgb <.35+(rand(BookSeed)*.5),.35+(rand(BookSeed)*.5),.35+(rand(BookSeed)*.5)>; #end #declare TSeed=seed(1000+int(rand(BookSeed)*1000)); #declare X1=1; #declare LengthSoFar=0; #declare SmallestRemainder=RowLength-((LengthSoFar/NumBooks)*(1+VariThick)); #declare StandardWidth=RowLength/NumBooks; union { #declare PreviousBookTilted = false; #while (LengthSoFar,<0,BookHeight,0>,BookWidth/2 scale <1,1,.25>} box {<-BookWidth/2,0,0>,} } union { cylinder {<0,0,0>,<0,BookHeight,0>,BookWidth/2 scale <1,1,.25>} box {<-BookWidth/2,0,0>,} scale <.9,1.1,1> translate <0,-BookHeight*.05,BookDepth*.1> } #if (VariColours=true) #declare Bindings=rgb <.35+(rand(BookSeed)*.5),.35+(rand(BookSeed)*.5),.35+(rand(BookSeed)*.5)>; #end CoverTexture (Bindings) // texture macro call } #if (Titles=true) BookTitles (X1) //call macro to define a title for this book #end PagesEdge () // call to macro #switch (StackStyle) #case (0) // Shelved (Bottom Edges Level, runs in the positive X direction) // Code added by Luc Coiffier #if ((Tilted=true)*(rand(BookSeed) rotate <0, 0, TiltedAngle*180/pi> translate #declare BookWidth = (BookWidth * cos(TiltedAngle)) + (BookHeight*sin(TiltedAngle)); #declare PreviousBookTilted = true; #else // Original code translate #declare PreviousBookTilted = false; #end #break #case (1) // Nicely Stacked (Varies slightly back and forth, and is vertical) rotate z*90 translate translate rotate y*((rand(BookSeed)*20)-10) #break #case (2) // Messily Stacked (Piled Up Any Which Way, also vertical) rotate z*90 translate rotate y*(rand(BookSeed)*360) #break #end } #declare X1=X1+1; #declare LengthSoFar=LengthSoFar+BookWidth; #end #if (LengthSoFar,<0,BookHeight,0>,BookWidth/2 scale <1,1,.25>} box {<-BookWidth/2,0,0>,} } union { cylinder {<0,0,0>,<0,BookHeight,0>,BookWidth/2 scale <1,1,.25>} box {<-BookWidth/2,0,0>,} scale <.9,1.1,1> translate <0,-BookHeight*.05,BookDepth*.1> } #if (VariColours=True) #declare Bindings=rgb <.35+(rand(BookSeed)*.5),.35+(rand(BookSeed)*.5),.35+(rand(BookSeed)*.5)> #end CoverTexture (Bindings) //texture macro } #if (Titles=true) BookTitles (X1) //call macro to define a title for this book #end PagesEdge () // call to macro #switch (StackStyle) #case (0) // Shelved (Bottom Edges Level, runs in the positive X direction) // Code modified by Luc Coiffier #if ((Tilted=true)*(rand(BookSeed) rotate <0, 0, TiltedAngle> translate #declare BookWidth = BookHeight*sin(TiltedAngle) + BookWidth * cos(TiltedAngle); #declare PreviousBookTilted = true; #else // Original code translate #declare PreviousBookTilted = false; #end #break #case (1) // Nicely Stacked (Varies slightly back and forth, and is vertical) rotate z*90 translate translate rotate y*((rand(BookSeed)*20)-10) #break #case (2) // Messily Stacked (Piled Up Any Which Way, also vertical) rotate z*90 translate rotate y*(rand(BookSeed)*360) #break #end } #declare LengthSoFar=LengthSoFar+BookWidth; #end }