| 
|  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | Hello everybody, I need a little help with this.
The following code works fine:
  #include "colors.inc"
  background { color rgb <.5, .4, .3> }
  #declare Rnd_1 = seed (1153);
  camera {
    location <3, 2, -3>
    look_at  <0, 0,  0>
  }
  light_source {<100,200,-100> colour rgb 1}
  #macro ship ()
    #declare n = 1;
    #while ( n < 800 )
             box { <0,0,0>,<1,1,1>
             pigment{rgb .5}
             finish { phong 1 }
             scale <rand(Rnd_1)/5,rand(Rnd_1)/2,rand(Rnd_1)*1.5>
             translate <rand(Rnd_1)/2,rand(Rnd_1)/2,rand(Rnd_1)*4>
             }
      #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!
Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | woops... sorry about the "no subject" thing.
NOTE: if I remove the while-end loop code works fine.
 Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | "MadKairon" <nomail@nomail> wrote in message 
news:web.4a546647c23a6d95fbac4ff0@news.povray.org...
> Hello everybody, I need a little help with this.
> The following code works fine:
>
>  #include "colors.inc"
>  background { color rgb <.5, .4, .3> }
>  #declare Rnd_1 = seed (1153);
>
>
>
>  camera {
>    location <3, 2, -3>
>    look_at  <0, 0,  0>
>  }
>
>  light_source {<100,200,-100> colour rgb 1}
>
>  #macro ship ()
>    #declare n = 1;
>    #while ( n < 800 )
>             box { <0,0,0>,<1,1,1>
>             pigment{rgb .5}
>             finish { phong 1 }
>             scale <rand(Rnd_1)/5,rand(Rnd_1)/2,rand(Rnd_1)*1.5>
>             translate <rand(Rnd_1)/2,rand(Rnd_1)/2,rand(Rnd_1)*4>
>             }
>      #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!
With the #while loop in place your macro returns a number of objects (800 
boxes) rather than an object, so when it hits the second object it should 
complain. You can use a union:
union { ship () translate <.1,0,0> }
or you could wrap your #while loop in a union statement within the macro, in 
which case it returns a single consolidated object which is a union of your 
800 boxes and your object statement should then work fine.
Regards,
Chris B.
Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | >"Chris B" <nom### [at] nomail com> wrote:
> "MadKairon" <nomail@nomail> wrote in message
> news:web.4a546647c23a6d95fbac4ff0@news.povray.org...
>
> or you could wrap your #while loop in a union statement within the macro, in
> which case it returns a single consolidated object which is a union of your
> 800 boxes and your object statement should then work fine.
>
> Regards,
> Chris B.
.... and I keep learning stuff about object oriented programming, i just wanted
to render some boxes lol. wraping the loop in a union statement works great!
Thanks for the fast answer!! Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | "MadKairon" <nomail@nomail> wrote in message 
news:web.4a5472896f92e8565fbac4ff0@news.povray.org...
> >"Chris B" <nom### [at] nomail com> wrote:
>> "MadKairon" <nomail@nomail> wrote in message
>> news:web.4a546647c23a6d95fbac4ff0@news.povray.org...
>>
>> or you could wrap your #while loop in a union statement within the macro, 
>> in
>> which case it returns a single consolidated object which is a union of 
>> your
>> 800 boxes and your object statement should then work fine.
>>
>> Regards,
>> Chris B.
>
> .... and I keep learning stuff about object oriented programming, i just 
> wanted
> to render some boxes lol. wraping the loop in a union statement works 
> great!
> Thanks for the fast answer!!
>
Strictly speaking it's procedural programming/scripting with POV-Ray 
objects, the term Object Oriented programming carrying a whole lot of other 
connotations ;). Post a reply to this message
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |  |  
|  |  | "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
 |  |  |  |  |  |  |  |  
|  |  |  |  |  |  |  |  |  |