POV-Ray : Newsgroups : povray.binaries.scene-files : Recursive Macro Problem Server Time
2 Sep 2024 16:21:37 EDT (-0400)
  Recursive Macro Problem (Message 1 to 5 of 5)  
From: Chris S 
Subject: Recursive Macro Problem
Date: 3 Jun 2000 21:58:41
Message: <3939b7d1@news.povray.org>
I've hit a bit of a rock I haven't been able to climb over.  The recursive
macro below is *supposed* to generate a linear sphere_sweep, generating 10
sphere positions for the sweep.  It then uses the last coordinate as the
starting point for two other sweeps.

The coordinate calculations have a random element added to them to visualize
a contorted cone, essentially the segment of a root.  My final objective is
to generate a complex root system.  I added a color element, taken from
Samuel Benge's altered pyramid.pov example, to differentiate recursion
levels.

The problem I've run into is that the first recursion runs through the
coordinates used to position the first sphere in the next sphere_sweep but
doesn't reset them for the subsequent recursion.  As a result, when the root
"branches" the first branch will appear to connected to the original branch,
and it's first branch connected to it, but the second branch will appear at
the different position then the end of the former branch...

Sound confusing?  Sorry, but it has me stumped...  This pov file is ready to
render so it should explain the problem better then I.  It's my first
toy-around with a recursive macro so any help would be appreciated.

Thanks,
-Chris-

#version unofficial MegaPov 0.5;

background{color rgb 1}

light_source{<200, 200, 200> color rgb<1, 1, 1>}
light_source{<-10, 8, 100> color rgb<1, 1, 1>}

camera{location<0, 0, 50> sky<0, 0, 1> right<-4/3, 0, 0> angle 50 look_at<0,
0, 0>}

//X,Y,Z - initial sphere positions
//R - initial radius
//L - recursion level
//Next - incrementer for sphere position while loop, higher the Next, longer
the sphere_sweep
#macro Tree_Root(X,Y,Z,R,L,Next)

    #declare counter=0;
    sphere_sweep {
      linear_sphere_sweep,
      10,
      #while(Next>0)
        <X,Y,Z>,R
        #declare R=R/1.05;
        #local X=X-rand(Rand01);
        #local Y=Y-rand(Rand01);
        #local Z=Z-rand(Rand01);
        #declare Next=Next-1;
        #declare counter=counter+1;
      #end
    }

    #if(L>0)
      #local New_L = L-1;
      #local New_R=R;
      #local PX=X;
      #local PY=Y;
      #local PZ=Z;

      #local Co=1;#local Co=Co/L;
      union{
        union{//first recursion
          Tree_Root(X,Y,Z,New_R,New_L,10)  // first works
          translate<-PX,-PY,-PZ>
          rotate 35/L*z
          translate<PX,PY,PZ>

        }
        union{//second recursion
          Tree_Root(X,Y,Z,New_R,New_L,10) // secone doesn't work
          translate<-PX,-PY,-PZ>
          rotate -35/L*z
          translate<PX,PY,PZ>
        }
        pigment{rgb<Co,Co,Co>}
      }
    #end

#end

union{
Tree_Root(0,0,0,2,2,10)
pigment{color rgb <1,1,0>}
}


Post a reply to this message


Attachments:
Download 'recursive.pov.txt' (2 KB)

From: Margus Ramst
Subject: Re: Recursive Macro Problem
Date: 5 Jun 2000 11:47:25
Message: <393BBDBE.845BC1EA@peak.edu.ee>
This seems to work.

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg


Post a reply to this message


Attachments:
Download 'recursive.pov.txt' (2 KB)

From: Jerry
Subject: Re: Recursive Macro Problem
Date: 5 Jun 2000 12:04:06
Message: <jerry-56435F.09040505062000@news.povray.org>
In article <3939b7d1@news.povray.org>, "Chris S." 
<chr### [at] bluelectrodecom> wrote:
>#macro Tree_Root(X,Y,Z,R,L,Next)
>
>    #declare counter=0;
>        #declare R=R/1.05;
>        #declare Next=Next-1;
>        #declare counter=counter+1;

Remember that "declare"s are sort of global. You might want "local" for 
those. I don't really understand the macro, but I notice that you are 
both passing "Next" and "R" and "declare"ing them, so possibly those two 
aren't globals. But you are setting "counter" to zero every time you 
call your macro, which might be causing problems if you expect each 
incarnation of the macro to have its own counter.

Jerry


Post a reply to this message

From: Chris S 
Subject: Re: Recursive Macro Problem
Date: 5 Jun 2000 13:11:43
Message: <393bdf4f@news.povray.org>
Infinite thanks.  Works perfectly!  I was thinking of a fix like duplicating
the variables but didn't believe that would solve the problem over 2
recursions.  Is there a use for the mymacros.inc file?  It wasn't included,
but the file still seems to work without it.

Again, thanks:)

-Chris-


Margus Ramst <mar### [at] peakeduee> wrote in message
news:393BBDBE.845BC1EA@peak.edu.ee...
> This seems to work.
>
> --
> Margus Ramst
>
> Personal e-mail: mar### [at] peakeduee
> TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg


Post a reply to this message

From: Margus Ramst
Subject: Re: Recursive Macro Problem
Date: 6 Jun 2000 19:21:21
Message: <393D5F27.92BB7D50@peak.edu.ee>
"Chris S." wrote:
> 
> Is there a use for the mymacros.inc file?  It wasn't included,
> but the file still seems to work without it.
> 

It's just a bunch of utility macros I use regularly. One lets me easily #debug a
3D vector.
If you want I can mail you the file - but beware, it's mainly for personal use
so it's not 100% documented or guaranteed to work...

-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg


Post a reply to this message

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