
Endless POVabilities- By Sonya RobertsThe Fourth Lesson - More About #WHILE...#END and RAND()We're now ready to begin pulling together everything we've learned in the previous lessons, and use this knowledge to create some very flexible code. All of the example files used throughout this lesson are contained in scene.zip. Please note that the examples listed here do not show the light or camera or background code, though it is included within the actual example files. Part 1 - Laying Out a Simple SceneOur first step is going to be to layout a simple scene consisting of a ground plane, sky sphere, and heightfield mountains. Within this scene we're then going to create and lay out a variety of different objects, utilising the methods and techniques we've covered to date. This initial empty scene is included in the .zip file referenced above, as "scene1.pov". The heightfield used for the mountains is also included. ![]() As was mentioned in an earlier lesson, it's easy to use #if...#end statements to make our scene modular, so that we can turn different portions of the code on and off at will. We're going to make use of this in laying out this scene. We'll need to define two variables to use in our logic testing, namely "True" and "False": scene.pov
Our scene is going to contain a number of different elements, split between several different files. To make test rendering different combinations of our scene objects easier, we're going to set up our initial scene to have some variables that can be set to True or False to turn scenic elements on or off. To start with, our scene will include some distant trees and a stream of soap bubbles, both created in a subfile we'll call "items". The code we need to insert to make this "modular" is as follows:
What this allows us to do is to turn off everything within "items.pov" by setting one variable (Items) to False. Alternatively, with Items set to True, we can use additional variables to control the one/off state of each of the many items contained within "items.pov".
Once we've set up the variables and #if...#end statements in the initial file, we need to add matching #if...#end statements within "items.pov", so that the renderer will test for items to be on before parsing their code. Then, within each of these conditional statements, we'll assemble the code for the item to be added to the scene. We're going to be using random numbers in this scene, so we also need to set up seed values for these numbers. Start a new file, and call it "items.pov". At the top, add the following lines: items.pov
Let's now add some code that'll create a grouping of 10 randomly placed bubbles of glass, randomly sized from .25 to .5 units in radius - our "soap bubbles". We'll create them so that they are all placed within an area 5 units wide, tall, and deep, centered above the origin, and starting a units feet off the ground:
![]() Now, within the next conditional statement, we're going to build the definition for our line of trees. For these, we'll create a rectangular array of trees, using nested loops. Each tree will be a randomly scaled sphere-and-cylinder, which has been randomly perturbed from the regular grid of the array. The colour of the green used for the "leaves" will also be randomly varied within a small range of lighter and lighter shades. So the first thing we need to create is the loop that displaces things along the X-axis, then the one for the Y-axis, and then, within these loops, the code to create the randomly tweaked trees:
![]() Part 2 of The Fourth Lesson - More About #WHILE...#END and RAND() |
<Crystal Clarity>
<Topas Try Me's> <Povabilities> <Soap Box> <Cranky's
Corner>
<Top> <Home>
<CG Web Board> <Contact>
The Rendering Times: Design and Copyright & © 1997 -- David Chandler Spake. All rights reserved. Reproduction in whole or in part in any form or medium without the express written permission of DCS is prohibited.