|
![](/i/fill.gif) |
ross litscher wrote:
8< .... snip ...
> The one thing
> that is not entirely intuitive to me is this part
>
> #declare Grid_1 =
> union {
> Make_Grid(Spike, 0.5, 6)
> pigment { color Yellow }
> }
>
> object {
> Grid_1
> rotate 45*x
> translate 3*y
> }
>
> Now if I wanted two "Grids" I'd have to do another #declare Grid_2...
> etc., and another object {Grid_2 ...}. Now this is how I thought it
> would work. especially after reading (and misunderstanding, i presume)
> the section in the povray docs about macros as functions that return
> some value.
>
> #declare Grid_1 = object{ Make_Grid(Spike, 0.5, 6) }
>
> and then I hoped to be able to do something like
>
> object {
> Grid_1
> rotate 45*x
> translate 3*y
> }
>
> I'm pretty sure I tried this, and I'm pretty sure it didn't do what I
> expected. What I expected was what your initial solution did.
>
> But anyway, this is all probably just a result of me not knowing the
> language completely.
You have to be aware that in POV-Ray macros does not behave
like functions in other languages.
(Someone please correct me if I'm wrong about the following:)
Macros in POV-Ray does not return function values.
They just return text that is to be pasted in where the
macro is called.
So the macro you posted;
#macro Make_Grid (spacing, size)
#local grid = 0;
#while (grid < size)
#local zee = spacing * grid;
#local copy = 0;
#while (copy < size)
object {
my_spike
translate <spacing*copy, 0, zee>
}
#local copy = copy + 1;
#end
#local grid = grid + 1;
#end
//A cheap fix for it not putting a cone at <0,0,0>
object { my_spike }
#end
just generated a lot of "spike" objects. And these were
pasted in to the part of the code that called the macro:
#declare Grid_1 = Make_Grid(.5, 2)
Like this:
(The carriage returns, spaces and the extra .0 are
of coarse not correct.)
#declare Grid_1 = object {
my_spike
translate <0.0, 0, 0.0>
}
object {
my_spike
translate <0.5, 0, 0.0>
}
object {
my_spike
translate <0.0, 0, 0.5>
}
object {
my_spike
translate <0.5, 0, 0.5>
}
object {
my_spike
}
As you see the first spike object is assigned to
the Grid_1 variable and the others are just left
to be rendered were they now are.
(This is why there was missing a cone at <0, 0, 0>
and I believe that this lead you to do the "cheap fix":
To add a last cone at this position (origo). :)
Now the Grid_1 variable contains a single cone
object and that object is rotated and translated
when one does this:
object {
Grid_1
rotate 45*x
translate 3*y
}
So then one ends up with 5 cones:
1 rotated and translated
4 in the xz-plane.
Then I came and suggested to put the code that
called the macro into a union operator:
#declare Grid_1 =
union {
Make_Grid(.5, 2)
rotate 45*x
translate 3*y
}
This time the result of calling the macro
is this:
#declare Grid_1 =
union {
object {
my_spike
translate <0.0, 0, 0.0>
}
object {
my_spike
translate <0.5, 0, 0.0>
}
object {
my_spike
translate <0.0, 0, 0.5>
}
object {
my_spike
translate <0.5, 0, 0.5>
}
object {
my_spike
}
rotate 45*x
translate 3*y
}
The Grid_1 variable now contains a union of all
the 5 cone objects. And note that now they are
all rotated and translated away from the xz-plane
together.
Now all that is needed to make this new object
visible is to just write the name of the variable
that holds it.
Like this:
Grid_1
If you want to do further "operations" on this
object, then just put the name of the variable
inside an object declaration and apply more
"operations" to it.
E.g.:
object {
Grid_1
pigment { color Yellow }
}
or:
difference {
object { Grid_1 translate y/16 }
object { Grid_1 translate -y/16 }
pigment { color Red }
}
The fact that macros returns text instead of
function values can be exploited in other
ways than I have shown here.
E.g.:
One cane make macros that passes arrays
of 2D points to a lathe shape.
Instead of having to type in all the points
manually inside the shape statement, the
macro reads them out of an array (that is
passed to the macro) and pastes them into
the brackets of a lathe statement with all
the necessary commas.
I can show you examples of how to do
things like this with macros if you are
interested.
Hope this helped.
Regards,
Tor Olav
--
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.html
Post a reply to this message
|
![](/i/fill.gif) |