POV-Ray : Newsgroups : povray.general : <no subject> Server Time
30 Jul 2024 08:25:59 EDT (-0400)
  <no subject> (Message 1 to 6 of 6)  
From: MadKairon
Subject: <no subject>
Date: 8 Jul 2009 05:30:00
Message: <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!


Post a reply to this message

From: MadKairon
Subject: Re: <no subject>
Date: 8 Jul 2009 05:35:00
Message: <web.4a5467c36f92e8565fbac4ff0@news.povray.org>
woops... sorry about the "no subject" thing.

NOTE: if I remove the while-end loop code works fine.


Post a reply to this message

From: Chris B
Subject: Re: <no subject>
Date: 8 Jul 2009 05:48:20
Message: <4a546b64$1@news.povray.org>
"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

From: MadKairon
Subject: Re: <no subject>
Date: 8 Jul 2009 06:20:00
Message: <web.4a5472896f92e8565fbac4ff0@news.povray.org>
>"Chris B" <nom### [at] nomailcom> 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

From: Chris B
Subject: Re: <no subject>
Date: 8 Jul 2009 06:40:04
Message: <4a547784$1@news.povray.org>
"MadKairon" <nomail@nomail> wrote in message 
news:web.4a5472896f92e8565fbac4ff0@news.povray.org...
> >"Chris B" <nom### [at] nomailcom> 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

From: clipka
Subject: Re: <no subject>
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.