POV-Ray : Newsgroups : povray.newusers : Simple macro question Server Time
4 Nov 2024 13:03:10 EST (-0500)
  Simple macro question (Message 1 to 3 of 3)  
From: moj34
Subject: Simple macro question
Date: 3 Jun 2003 16:45:01
Message: <web.3edd08538a40289d44a752600@news.povray.org>
I'm new to povray, and have been getting on OK with most of the programming
aspect of it, but I've run into something I can't figure out.  Here's the
relevant bit of code:


---------snip-----------


 #declare Norm = <0, 0, 0>;


#declare n = 0;




#macro Ring(Up)


        #while (n < 360)

        #declare r=<sin(radians(n)),0,cos(radians(n))>;



        #declare Pos = trace (
                  Pot,             // object to test
                  <0,Up,0>,           // starting point
                  r,              // direction
                  Norm );          // normal

// if intersection is found, normal differs from 0
        #if (Norm.x != 0 | Norm.y != 0 | Norm.z != 0)
        sphere {Pos,0.1 pigment {colour Yellow}}
        #end
        #declare n=n+10;
        #end



     #end

  object{  Pot scale 1}




  Ring(0.5)
  Ring (0.0)
  Ring (1)


------------------snip------------

I've got a patch object called Pot, and I'm using the trace() function to
put tiny yellow spheres on its surface.  The Ring() macro takes a given
height (Up) and finds the intersections with the pot every ten degrees in a
full circle at that height. (hopefully that is clearer from the code than
from my explanation).  So far, so good, but the trouble is, when I try to
do this for a number of heights (eg 0, 0.5 and 1 in the example above) only
the ring corresponding to the first instance of the macro (y=0.5) shows up.

There's probably a simple explanation; if anyone could point it out to me I
would be very grateful :-)

If it would be helpful to post the whole scene file, let me know

Thanks
moj34


Post a reply to this message

From:
Subject: Re: Simple macro question
Date: 3 Jun 2003 22:21:56
Message: <3edd57c4@news.povray.org>
Hi,

After the first call of the Ring macro, n=360, so the #while statement
of subsequent calls of this macro will abort immediately. Putting the
line with "#declare n = 0;" between "#macro Ring(Up)" and "#while"
should correct this.

"#local AngleDegrees = ...;" is even better -- "#local" avoids unwanted
side effects on variables outside the macro, "AngleDegrees" is easier
to understand, and every identifier should have at least one uppercase
letter to avoid possible conflicts with (future) keywords. (Keywords will
never have uppercase letters.)

   Sputnik

--
----------------------------

fr### [at] computermuseumfh-kielde
----------------------------


Post a reply to this message

From: moj34
Subject: Re: Simple macro question
Date: 4 Jun 2003 06:05:02
Message: <web.3eddc3ea7d90e3c4f79b9540@news.povray.org>
Thanks Sputnik, I knew it would be something like that!

moj34


Post a reply to this message

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