POV-Ray : Newsgroups : povray.advanced-users : macro inside a loop Server Time
25 Nov 2024 23:34:07 EST (-0500)
  macro inside a loop (Message 1 to 4 of 4)  
From: Arie L  Stavchansky
Subject: macro inside a loop
Date: 19 Oct 2001 02:31:46
Message: <3bcfc8d2$1@news.povray.org>
I have the following:

//macro to make a tube of rings of spheres
#macro sphereTube(height, tubeRadius, elements, bottomSurface, topSurface,
place)

 #declare i = 10;
 #declare shift = <0, 0, 0>;

 #while (i < height)

  objectRing(

   tubeRadius, //radius of ring
   elements, //number of objects in ring
   bottomSurface, //start texture of object
   topSurface, //end texture of object
   place + shift //place away from origin

  )

  #declare shift = shift + <0, ballRadius(tubeRadius, elements)*2*i, 0>;
  #declare i = i+1;

 #end

#end

The problem is that the macro inside the loop (which functions properly) is
not being called more than once.  In fact, even the message I am given says
there are only a certain amount of frame level objects, as opposed to a
certain amount of frame level objects times the height (which is the loop
condition).

If you replace the macro inside the loop with a simple prmitive, such as a
sphere, then you will see the many spheres.  Why is the macro not being
called multiple times?

Thanks for your help,
Arie


Post a reply to this message

From: Chris Colefax
Subject: Re: macro inside a loop
Date: 19 Oct 2001 02:56:58
Message: <3bcfceba@news.povray.org>
Arie L. Stavchansky <ari### [at] bellatlanticnet> wrote:
> I have the following:
[snip]
> The problem is that the macro inside the loop (which functions properly)
is
> not being called more than once.  In fact, even the message I am given
says
> there are only a certain amount of frame level objects, as opposed to a
> certain amount of frame level objects times the height (which is the loop
> condition).
>
> If you replace the macro inside the loop with a simple prmitive, such as a
> sphere, then you will see the many spheres.  Why is the macro not being
> called multiple times?

Check that your objectRing macro is actually returning the objects you want
in the scene, rather than declaring them as object variables.  Otherwise, it
might help to see the code for that macro as well...


Post a reply to this message

From: Mike Williams
Subject: Re: macro inside a loop
Date: 19 Oct 2001 03:32:40
Message: <B$i7SBABN9z7Ew+p@econym.demon.co.uk>
Wasn't it Arie L. Stavchansky who wrote:
>I have the following:
>
>//macro to make a tube of rings of spheres
>#macro sphereTube(height, tubeRadius, elements, bottomSurface, topSurface,
>place)
>
> #declare i = 10;
> #declare shift = <0, 0, 0>;
>
> #while (i < height)
>
>  objectRing(
>
>   tubeRadius, //radius of ring
>   elements, //number of objects in ring
>   bottomSurface, //start texture of object
>   topSurface, //end texture of object
>   place + shift //place away from origin
>
>  )
>
>  #declare shift = shift + <0, ballRadius(tubeRadius, elements)*2*i, 0>;
>  #declare i = i+1;
>
> #end
>
>#end
>
>The problem is that the macro inside the loop (which functions properly) is
>not being called more than once.  In fact, even the message I am given says
>there are only a certain amount of frame level objects, as opposed to a
>certain amount of frame level objects times the height (which is the loop
>condition).
>
>If you replace the macro inside the loop with a simple prmitive, such as a
>sphere, then you will see the many spheres.  Why is the macro not being
>called multiple times?
>
>Thanks for your help,
>Arie
>
>

Since it works with simple primitives, I'd guess that one of the macros
you call "ballRadius" or "objectRing" is clobbering the value of your
counter variable "i".

The way to fix this is to change your #declares into #locals. This
allows each macro to have its own copy of the variable which then won't
interfere with similarly names variables in the calling macro or in the
top level of the scene file.

When you use "#declare i" you are changing the value of the global
variable called "i". So, if objectRing() uses "i" as its counter, and
counts up to "elements", when control returns out from objectRing() into
sphereTube(), the value of "i" has been changed from 10 to elements. If
elements+1 is greater than height, the while clause of sphereTube() is
satisfied, and the macro terminates.

If this is the case, then you're lucky that height is less than
elements+1, otherwise it could easily have gone into an infinite loop.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Arie L  Stavchansky
Subject: Re: macro inside a loop
Date: 19 Oct 2001 13:04:05
Message: <3bd05d05@news.povray.org>
That was it Mike!  I had not declared them as local.  I didn't know that
directive existed.  Thanks for the help!

Arie

"Mike Williams" <mik### [at] nospamplease> wrote in message
news:B$i7SBABN9z7Ew+p### [at] econymdemoncouk...
> Wasn't it Arie L. Stavchansky who wrote:
> >I have the following:
> >
> >//macro to make a tube of rings of spheres
> >#macro sphereTube(height, tubeRadius, elements, bottomSurface,
topSurface,
> >place)
> >
> > #declare i = 10;
> > #declare shift = <0, 0, 0>;
> >
> > #while (i < height)
> >
> >  objectRing(
> >
> >   tubeRadius, //radius of ring
> >   elements, //number of objects in ring
> >   bottomSurface, //start texture of object
> >   topSurface, //end texture of object
> >   place + shift //place away from origin
> >
> >  )
> >
> >  #declare shift = shift + <0, ballRadius(tubeRadius, elements)*2*i, 0>;
> >  #declare i = i+1;
> >
> > #end
> >
> >#end
> >
> >The problem is that the macro inside the loop (which functions properly)
is
> >not being called more than once.  In fact, even the message I am given
says
> >there are only a certain amount of frame level objects, as opposed to a
> >certain amount of frame level objects times the height (which is the loop
> >condition).
> >
> >If you replace the macro inside the loop with a simple prmitive, such as
a
> >sphere, then you will see the many spheres.  Why is the macro not being
> >called multiple times?
> >
> >Thanks for your help,
> >Arie
> >
> >
>
> Since it works with simple primitives, I'd guess that one of the macros
> you call "ballRadius" or "objectRing" is clobbering the value of your
> counter variable "i".
>
> The way to fix this is to change your #declares into #locals. This
> allows each macro to have its own copy of the variable which then won't
> interfere with similarly names variables in the calling macro or in the
> top level of the scene file.
>
> When you use "#declare i" you are changing the value of the global
> variable called "i". So, if objectRing() uses "i" as its counter, and
> counts up to "elements", when control returns out from objectRing() into
> sphereTube(), the value of "i" has been changed from 10 to elements. If
> elements+1 is greater than height, the while clause of sphereTube() is
> satisfied, and the macro terminates.
>
> If this is the case, then you're lucky that height is less than
> elements+1, otherwise it could easily have gone into an infinite loop.
>
> --
> Mike Williams
> Gentleman of Leisure


Post a reply to this message

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