POV-Ray : Newsgroups : povray.general : while-loop in macro Server Time
17 Nov 2024 15:13:55 EST (-0500)
  while-loop in macro (Message 1 to 10 of 11)  
Goto Latest 10 Messages Next 1 Messages >>>
From: Lenx
Subject: while-loop in macro
Date: 23 Feb 2003 16:45:18
Message: <web.3e5940689d42b660de2a6cfb0@news.povray.org>
now i'm pulling out my hear on this problem
i just started with this macro to create a fence:


#macro Fence(Flength, Fheight, Fspace, Fdiam)

   #local i=0;
   #while(i< Flength/Fspace+1 )
      cylinder{ <0,0,0> <0,Fheight,0> Fdiam/2 }
      translate <i*Fspace, 0, 0>
     #local i=i+1;
   #end

#end


the macro itself is ok when rendered, but of course you only get a black
screen.
When i try to call the macro in an object as following, i get an error "no
matching '}' in object, cylinder found instead".
I allready found out the problem has to do with the #while loop. but i can't
find how to fix. Please can someone guide me throug this?


object{
   Fence(400, 150, 20, 1.5)
   pigment{ rgb .1 }
   }


Post a reply to this message

From: Jellby
Subject: Re: while-loop in macro
Date: 23 Feb 2003 16:52:00
Message: <3e59427f@news.povray.org>
Among other things, Lenx wrote:

> #macro Fence(Flength, Fheight, Fspace, Fdiam)
> 
>    #local i=0;
>    #while(i< Flength/Fspace+1 )
>       cylinder{ <0,0,0> <0,Fheight,0> Fdiam/2 }
>       translate <i*Fspace, 0, 0>
>      #local i=i+1;
>    #end
> 
> #end
> 
> 
> the macro itself is ok when rendered, but of course you only get a black
> screen.
> When i try to call the macro in an object as following, i get an error "no
> matching '}' in object, cylinder found instead".

So you finally have:

object {
  cylinder { }
  translate
  cylinder { }
  translate
  ...
}

This makes no sense, as far as I know. Try calling it as an union (instead 
of object) and moving the translate block inside the cylinder braces. So 
you have:

union {
  cylinder {
    translate
  }
  cylinder {
    translate
  }
  ...
}

-- 

Linux User #289967 (counter.li.org)
PGP Pub Key ID: 0x01A95F99 (pgp.escomplinux.org)


Post a reply to this message

From: Lenx
Subject: Re: while-loop in macro
Date: 23 Feb 2003 17:10:07
Message: <web.3e594598d27a3e2ede2a6cfb0@news.povray.org>
Jellby wrote:
>
>So you finally have:
>
>object {
>  cylinder { }
>  translate
>  cylinder { }
>  translate
>  ...
>}
>

i don't understand how you come to that :-s


>This makes no sense, as far as I know. Try calling it as an union (instead
>of object) and moving the translate block inside the cylinder braces. So
>you have:
>
>union {
>  cylinder {
>    translate
>  }
>  cylinder {
>    translate
>  }
>  ...
>}
>

calling it as a union doesn't work. but the problem is something with the
while-loop and not with the cylinder. when i remove the #while and #end,
everything works fine.
when i add that while, i get the error.
it's very strange...

thx for the reply!

lenx


Post a reply to this message

From: Vadim Sytnikov
Subject: Re: while-loop in macro
Date: 23 Feb 2003 17:27:52
Message: <3e594ae8@news.povray.org>
"Lenx" <lenx_@hotmail.com> wrote:
> i don't understand how you come to that :-s

It's called loop unrolling... He (Jellby) is right, your code is not
supposed to work; I'm surprised you say it compiles.

Enclosing this in a 'union' is not that necessary -- as long as you, at
least, put your 'translate' statements inside 'cylinder' blocks.


Post a reply to this message

From: Christopher James Huff
Subject: Re: while-loop in macro
Date: 23 Feb 2003 17:33:07
Message: <cjameshuff-A5EFF5.17294623022003@netplex.aussie.org>
In article <web.3e594598d27a3e2ede2a6cfb0@news.povray.org>,
 "Lenx" <lenx_@hotmail.com> wrote:

> Jellby wrote:
> >
> >So you finally have:
> >
> >object {
> >  cylinder { }
> >  translate
> >  cylinder { }
> >  translate
> >  ...
> >}
> 
> i don't understand how you come to that :-s

Your macro:
#macro Fence(Flength, Fheight, Fspace, Fdiam)
   #local i=0;
   #while(i< Flength/Fspace+1 )
      cylinder{ <0,0,0> <0,Fheight,0> Fdiam/2 }
      translate <i*Fspace, 0, 0>
     #local i=i+1;
   #end
#end

It loops over a cylinder and translate statement. You then call it in an 
object block...and get the expected result.
Since your translate statement is apparently intended to translate the 
cylinder, it should go in the cylinder block. And an object block can 
only contain one object, you need to put either the macro call or the 
loop itself in a union.

BTW, your "i" variable is poorly named. It is a good idea to always use 
at least one upper-case letter in a variable name, which will prevent 
conflicts with future keywords.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: while-loop in macro
Date: 23 Feb 2003 17:45:22
Message: <cjameshuff-6FB941.17420123022003@netplex.aussie.org>
In article <3e594ae8@news.povray.org>,
 "Vadim Sytnikov" <syt### [at] rucom> wrote:

> It's called loop unrolling... He (Jellby) is right, your code is not
> supposed to work; I'm surprised you say it compiles.

Huh? He didn't. Nobody mentioned anything compiling, which is good, 
because POV doesn't compile anything. He did say it didn't work.


> Enclosing this in a 'union' is not that necessary -- as long as you, at
> least, put your 'translate' statements inside 'cylinder' blocks.

Putting it in a union has the advantage that the entire group of 
cylinders can be transformed and textured as a single object. Not 
strictly necessary, but more flexable.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Vadim Sytnikov
Subject: Re: while-loop in macro
Date: 23 Feb 2003 18:27:30
Message: <3e5958e2@news.povray.org>
"Christopher James Huff" <cja### [at] earthlinknet> wrote:
>
> Huh? He didn't. Nobody mentioned anything compiling, which is good,
> because POV doesn't compile anything. He did say it didn't work.

I was referring to his words that "the macro itself is ok when rendered, but
of course you only get a black screen.". That is, it seemed like he was
complaining about the macro not working in some particular case. Maybe I
just misundertood him.


Post a reply to this message

From: Christopher James Huff
Subject: Re: while-loop in macro
Date: 23 Feb 2003 18:48:10
Message: <cjameshuff-0B0D6F.18444923022003@netplex.aussie.org>
In article <3e5958e2@news.povray.org>,
 "Vadim Sytnikov" <syt### [at] rucom> wrote:

> > Huh? He didn't. Nobody mentioned anything compiling, which is good,
> > because POV doesn't compile anything. He did say it didn't work.
> 
> I was referring to his words that "the macro itself is ok when rendered, but
> of course you only get a black screen.". That is, it seemed like he was
> complaining about the macro not working in some particular case. Maybe I
> just misundertood him.

Ah, I see...I understood this as "when I don't call the macro". His 
macro will parse fine, as long as it isn't actually called. It won't 
parse if it is called outside an object block, which might be what you 
meant. (I don't think it will parse anywhere)

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

From: Lenx
Subject: Re: while-loop in macro
Date: 24 Feb 2003 12:55:02
Message: <web.3e5a5c25d27a3e2e293f3c960@news.povray.org>
thanks Christopher, you made it clear to me.

i was complaining about the macro, working on itsself, but not working when
called in an object.
so the macro renders without errors, but called in an object it gives error.

thanks to you all!


//code is now:
#macro Fence(Flength, Fheight, Fspace, Fdiam)

   union{
   #local I=0;
   #while(I< Flength/Fspace+1 )
         cylinder{
            <0,0,0> <0,Fheight,0> Fdiam/2
            translate <I*Fspace, 0, 0>
            }
      #local I=I+1;
   #end
   }

#end


Post a reply to this message

From: Christopher James Huff
Subject: Re: while-loop in macro
Date: 24 Feb 2003 16:30:16
Message: <cjameshuff-FB8598.16263324022003@netplex.aussie.org>
In article <web.3e5a5c25d27a3e2e293f3c960@news.povray.org>,
 "Lenx" <lenx_@hotmail.com> wrote:

> i was complaining about the macro, working on itsself, but not working when
> called in an object.
> so the macro renders without errors, but called in an object it gives error.

When a macro is just defined, very little parsing is done. The contents 
of the macro only really exist to the parser when the macro is called

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: chr### [at] tagpovrayorg
http://tag.povray.org/


Post a reply to this message

Goto Latest 10 Messages Next 1 Messages >>>

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