|
![](/i/fill.gif) |
Wasn't it Rick D. who wrote:
>Hi all,
>
>I have a question about the use of recursive object-unions in povray.
>
> . . .
>
>With the povray knowledge i have at this moment i would have to hard
>code each separate object. But i'm sure this sort of thing can be done
>using some kind of automated loop with variables, but i haven't been
>able to find information about this so far.
The magic word that you need to look up in the documentation is "macro".
POV supports recursive macros. You can pass parameters to a macro that
you can use to (a) create a copy of the object at a size and position
controlled by those parameters and (b) call copies of itself to handle
the next smaller size (if it's not already at the lowest level).
Here's an example
#macro Recurse(Shape, Posn, Rotn, Depth, Max_Depth)
// draw the shape at this level
object {Shape
rotate Rotn
scale 1/Depth // scale calculation
translate Posn
}
// Check to see if we need to go deeper
#if (Depth < Max_Depth)
// Call the stuff for the next level down
Recurse (Shape, Posn+x/Depth, Rotn+y*20, Depth+1, Max_Depth)
Recurse (Shape, Posn-x/Depth, Rotn+y*20, Depth+1, Max_Depth)
Recurse (Shape, Posn+y/Depth, Rotn+y*20, Depth+1, Max_Depth)
Recurse (Shape, Posn-y/Depth, Rotn+y*20, Depth+1, Max_Depth)
Recurse (Shape, Posn+z/Depth, Rotn+y*20, Depth+1, Max_Depth)
Recurse (Shape, Posn-z/Depth, Rotn+y*20, Depth+1, Max_Depth)
#end
#end
Recurse(My_Basic_Shape, <0,0,0>, <0,0,0>, 1, 5)
I call this macro with Depth=1, and it calls eight copies of itself with
Depth=2 and they each call eight copies with Depth=3 etc.
Change the scale, Posn and Rotn calculations to fit the particular
structure that you're trying to create.
If you need to use any variables in the calculations inside the macro,
use #local rather than #declare to avoid the possibility of the
variables being clobbered by other copies of the macro.
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
![](/i/fill.gif) |