Endless POVabilities

- By Sonya Roberts 
 

The First Lesson - #DECLARE

Why #declare as the first lesson? Because the lessons that will come in succeeding columns will rely heavily on your ability to #declare variables and objects. I want to be sure that you have a firm foundation for the lessons to follow.

#declare is a very powerful command. If you aren't using it already, you'll soon be wondering just how the heck you got along without it. We'll have in fact by the end of this first lesson, written a plug-in for POV using the #declare statement!

What does #declare allow you to do? Two main things - you can use it to define variables, and you can assign your own names to objects or textures with it. You can then use these variables, objects, or textures simply by calling them by the declared name.

For example, suppose you are writing code to describe a simple rectangular room with light blue walls, a black and white checkered floor and a white ceiling. Let's start off with some code that defines this room by carving it out of a box. We'll start with a room 10 units wide by 20 units long by 10 units high (I like to use an approximate scale of 1 unit equals 1 foot (30 cm)).

object { 
union { 
difference { 
box {<-.1,0,-.1>,<10.1,10,20.1>} 
box {<0,-.1,0>,<10,10.1,20>} 
pigment {color LightBlue} 
} 
box { 
<0,10,0>,<10,10,20>
pigment {color White} 
} 
box { 
<0,-.1,0>,<10,0,20>
pigment { 
checker 
pigment {color White} 
pigment {color Black} 
} 
} 
} 
} 


Now, suppose you want to set this up so that you can re-size the room by setting variables for the width, length, and height. Here's where the #declare statement comes in handy. Let's take a look at the code with the necesary changes made:

#declare Width=10 
#declare Length=20 
#declare Height=10 
object { 
union { 
difference { 
box {<-.1,0,-.1>,<Width+.1,Height,Length+.1>} 
box {<0,-.1,0>,<Width,Height+.1,Length>} 
pigment {color LightBlue} 
} 
box { 
<0,Height,0>,<Width,Height+.1,Length>
pigment {color White} 
} 
box { 
<0,-.1,0>,<Width,0,Length>
pigment { 
checker 
pigment {color White} 
pigment {color Black} 
} 
} 
} 
} 

They've very simple, aren't they? But so very, very powerful...suddenly you can instantly resize the room in the time it takes to plug in three numbers. And just think, you could place things within the room, like a default central light source, that can be automatically re-positioned within the room based on these same variables.

#declare Width=10 
#declare Length=20 
#declare Height=10 
object { 
union { 
difference { 
box {<-.1,0,-.1>,<Width+.1,Height,Length+.1>} 
box {<0,-.1,0>,<Width,Height+.1,Length>} 
pigment {color LightBlue} 
} 
box { 
<0,Height,0>,<Width,Height+.1,Length>
pigment {color White} 
} 
box { 
<0,-.1,0>,<Width,0,Length>
pigment { 
checker 
pigment {color White} 
pigment {color Black} 
} 
} 
light_source { 
<Width/2,Height-1,Length/2>
color White 
} 
} 
} 


Part 2 of the "declare #" tutorial 

<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.