POV-Ray : Newsgroups : povray.general : <no subject> : Re: <no subject> Server Time
30 Jul 2024 06:21:58 EDT (-0400)
  Re: <no subject>  
From: clipka
Date: 8 Jul 2009 19:35:01
Message: <web.4a552c146f92e856de52d56d0@news.povray.org>
"MadKairon" <nomail@nomail> wrote:
> Hello everybody, I need a little help with this.
> The following code works fine:
>
>   #macro ship ()
>     #declare n = 1;
>     #while ( n < 800 )
>              box { <0,0,0>,<1,1,1>
>              ...
>              }
>       #declare n = n + 1  ;
>     #end
>   #end
>
>   ship()
>
> but if I try: object { ship () translate <.1,0,0> } on the last line I get a
> parse error, whats wrong? thanks in advance!

Let's look at what this gives you: The macro has a loop, which creates a lot of
boxes (800, to be precise); so your macro invocation "ship()" is replaced by
something like:

    box {...}
    box {...}
    box {...}
    box {...}
    ...

At scene level, this is perfectly fine: It gives you 800 separate, individual
boxes. But the other syntax would give you:

    object {
      box {...}
      box {...}
      box {...}
      box {...}
      ...
    translate <.1,0,0> }

This doesn't work, because the object {...} statement can only deal with a
single object. What you need is a union{...} or merge{...}, i.e.:

    union { ship () translate <.1,0,0> }

Or, better yet, change the macro to include the union{} statement:

    #macro ship ()
      union {
        #declare n = 1;
        #while ( n < 800 )
                 box { <0,0,0>,<1,1,1>
                 ...
                 }
          #declare n = n + 1  ;
        #end
      }
    #end

As this is now a valid single object (even though comprised of multiple
objects), you can now invoke it as you originally intended:

    object { ship () translate <.1,0,0> }


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.