Endless POVabilities

- By Sonya Roberts 


The First Lesson - #DECLARE (continued)

Now, suppose you wanted to add the same sort of funcationality to the textures used within the room, so that you can change them instantly too. We can #declare a variable to contain things more complex than just a single number. We can make them contain entire textures, light sources, camera set ups, objects, and more...but for now, we'll just stick to textures and objects. Let's move our three textures out of the object and into three variables, and let's also assign our room object to a variable.

#declare Width=10 
#declare Length=20 
#declare Height=10 

#declare RoomWalls= 
texture { 
pigment {color LightBlue} 
} 

#declare RoomCeiling= 
texture { 
pigment {color White} 
} 

#declare RoomFloor= 
texture { 
pigment { 
checker 
pigment {color White} 
pigment {color Black} 
} 
} 

#declare Room= 
object { 
union { 
difference { 
box {<-.1,0,-.1>,<Width+.1,Height,Length+.1>} 
box {<0,-.1,0>,<Width,Height+.1,Length>} 
texture {RoomWalls} 
} 
box { 
<0,Height,0>,<Width,Height+.1,Length
texture {RoomCeiling} 
} 
box { 
<0,-.1,0>,<Width,0,Length
texture {RoomFloor} 
} 
light_source { 
<Width/2,Height-1,Length/2
color White 
} 
} 
} 


Since we've now #declare'ed our object to a variable, we can also use it multiple times by simply calling it by name. As with any object, we can scale it, rotate it, and transform it at will:

object {Room} 
object {Room translate <15,0,0>} 
object {Room rotate y*-90} 
object {Room scale 2} 
object { 
Room 
rotate y*45 
scale 2 
translate <10,15,-20
} 

However, suppose we want to be able to use multiple different instances of our room object. Using the current example code, we'd have to copy the entire block a second time, changing the variables as necessary to create the new room. And repeat this for every different room we want.

But there's a *MUCH* easier way to do this: make our room into an includable file. Includable (*.inc) files have the advantage of being able to repeat a section of code, without retyping it every time. Seperate and save the following section of code out into a file of it's own - name it room.inc:

object { 
union { 
difference { 
box {<-.1,0,-.1>,<Width+.1,Height,Length+.1>} 
box {<0,-.1,0>,<Width,Height+.1,Length>} 
texture {RoomWalls} 
} 
box { 
<0,Height,0>,<Width,Height+.1,Length
texture {RoomCeiling} 
} 
box { 
<0,-.1,0>,<Width,0,Length
texture {RoomFloor} 
} 
light_source { 
<Width/2,Height-1,Length/2
color White 
} 
} 
} 

Now let's make the following changes to the remaining section of our original code:

#declare Width=10 
#declare Length=20 
#declare Height=10 

#declare RoomWalls= 
texture { 
pigment {color LightBlue} 
} 

#declare RoomCeiling= 
texture { 
pigment {color White} 
} 

#declare RoomFloor= 
texture { 
pigment { 
checker 
pigment {color White} 
pigment {color Black} 
} 
} 

object { 
#include "room.inc" 
} 

So far, this creates exactly the same object that the previous code block did. But we can now change as many or as few of our variables as we want, include the file again, and have a whole new room! Add the following code onto the end of what we have so far:

#declare Width=15 
#declare Length=30 
#declare Height=80 
object { 
#include "room.inc" 
translate <11,0,0> 
} 

#declare RoomWalls= 
texture { 
pigment {color PaleGreen} 
} 
object { 
#include "room.inc" 
translate <11,9,0> 
} 


We've successfully used the #declare statement to create variables and a simple includable file. In the next issue, we'll look at making the includable file smarter, by having it automatically use default values if the user forgets to set them, and make simple decisions based on these variables. For those who wish to forge ahead on their own, we'll be doing it using the #ifndef, #if, #else and #end statements

<Crystal Clarity> <Topas Try Me's> <Povabilities> <Soap Box> <Cranky's Corner>
<Top> <Back> <Home> <CG Web Board> <Contact>


 
The Rendering Times: Design and Copyright © 1997  -- DCS & WorkForce Graphics.  All rights reserved.  Reproduction in whole or in part in any form or medium without the express written permission of DCS and/or WorkForce Graphics is prohibited.