
Endless POVabilities- By Sonya RobertsThe Fourth Lesson - More About #WHILE...#END and RAND() -- Continued Part 2 - Getting Rather More ComplexThese trees and bubbles have been created using relatively simple combinations of loops and the rand() function. Let's now make a more complex routine, one that creates a variety of related but different objects. One good example for this would be flowers; they all possess leaves, a stem, and a blossom, but the colours, shapes, and placement of these can vary greatly. For this lesson, we'll use an easy example, where each flower is a single unique grouping of objects. Each of these will include some degree of randomness in how the components making them are assembled, so that each flower is not an exact carbon copy of the other flowers in it's same "species". We'll make the flower creation routine in the form of an include file, and then add some code to our scene file that uses this include file to create a scattering of flowers in our scene. This example is going to be fairly lengthy, so rather than trying to include it all, I'm going to be using a lot of ellipses ("...") to indicate where I've skipped over things in the example file. I'll also be explaining chunks of code as I go along, rather then leaving all the explanation to the end. parts.pov
In this file we're defining a bunch of pieces that POV will use when creating the flowers. We're defining them in a seperate file from the .INC file, as otherwise POV would have to parse and re-parse these bits of code every time the .INC file was called to add in a new flower. Instead, we'll simply #include this file before the section of scene code that uses the "flowers.inc" file, and these bits and pieces will therefore be defined and ready for use when the .INC file is invoked. flowers.inc
We're starting by setting up the seed value for our random numbers, and a variable which can be used to select which "flower" to use.
These are all the definitions of the different "flower" objects we're using. If you look at the definitions, you'll see random values being used for many purposes, from varying the number of leaves and petals to perturbing their positions so that they aren't all at the same angle or position. #While loops also play an important part in these definitions; once a rand() number has decided that there will be, for example, 5 leaves, those five leaves need to be correctly positioned in relation to the stem. Since we've split up the definitions using a #case...#switch statement, the file will only create one of these flowers when called, the flower whose #case matches by the "WhichShape" variable. Finally, we need to add some code to our "items.pov" file that will include the definitions of the pieces used to create the flowers, and then create a scattering of these flowers across our ground. As with the trees and soap bubbles, we'll make this conditional, so that we can turn the flowers on and off by switching a variable in our original scene file. scene.pov
items.pov
![]()
The Next LessonIn the next lesson, we'll take a look at things that can be done with images, from the simple image map through to bump_maps, height_fields, and material_maps. |
<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.