POV-Ray : Newsgroups : povray.advanced-users : Macro variable checks Server Time
29 Jul 2024 06:26:10 EDT (-0400)
  Macro variable checks (Message 1 to 2 of 2)  
From: David Wallace
Subject: Macro variable checks
Date: 27 Nov 2002 21:18:54
Message: <3de57d0e@news.povray.org>
Why is POV-Ray checking for variable definitions within a macro declaration?

#macro MakeBranch(iName, Level, pos, vb, rBase, rTop, dotop, fName)
  #include iName
 #if (Level>level0-3) #debug concat("level ",str(Level,0,0),"\n") #end
 //-----------------------------------------
 // The branch is made up of segments
 // First we create the branch segments
 //-----------------------------------------
 #local nseg=max(1,nseg0-level0+Level);  // number of branch segments
 #local lbseg=lb[Level]/nseg; // length of branch segment
 #local i=0;
 #local ay= 360*(0.5-rand(rd));
 #local curpos = pos;
 #local curlev = Level-1;
 #declare Splines[curlev] = spline {
  cubic_spline
  0, curpos
  #while (i<nseg)
   //-----------------------------------------
   // Segment calculation and positionning
   //-----------------------------------------
    #declare rad0 = rBase;
      #declare rad1 = rTop;
   // calculates the force (wind, gravity) to apply to the segment
   // the force is stronger at the end of the branch
   // for trunk, vpush gets a vertical boost if dotop is true
   #local vp0 = (dotop & Level = level0) ? vpush + <0, 0.5, 0> : vpush;
   #local fp0 = (dotop & Level = level0) ? fpush + 0.2 : fpush;
   #local vp = (vlength(vp0)=0) ? vp0 : vnormalize(vp0)*i/nseg;
   // then we add the gnarledness
   #local vg=<0.5-rand(rd),0.5-rand(rd),0.5-rand(rd)>;
   #if (vlength(vg)>0) #local vg=vnormalize(vg); #end
   // now we calculate the position ; vb is the original direction of the
segment
   #local curpos =
curpos+lbseg*vnormalize(vb+vp*fp0+vg*fgnarl)*(1+(0.5-rand(rd))*stdlseg);
   // segments must be kept over the ground
   #if (curpos.y<aboveground)
    #local curpos=<curpos.x,aboveground+rand(rd)*i/nseg,curpos.z>;
   #end
   // segments must be kept under the sky !
   #if (curpos.y>belowsky)
    #local curpos=<curpos.x,belowsky-rand(rd)*i/nseg,curpos.z>;
   #end
      #local i = i + 1;
      i, curpos
  #end
 }
 MakePara(curlev, Splines[curlev], fName)

  // set up continuing branch, if applicable
  #if (Level>1)
   #local nrb = rTop;
   #local nrt = (curlev=1 ? 0 : nrb*qrb);
  #local nps = Splines[curlev](1);
  #local nvb = vecdir(Splines[curlev],1);
  MakeBranch(curlev, nps, nvb, nrb, nrt, false, fName)

  // now the others
  #local i = 1;
  #while (i<nb)
   #local i = i + 1;
   #if (rand(rd)<=branchproba)
    #local hgt=int(jb)+rand(rd)*(1-jb);
    #local azim = radians(i*360/nb + stday*(0.5-rand(rd))); // Latitude
    #local lngt = radians(ab[level] + stdax*(0.5-rand(rd))); // Longitude
    #local zdr = vecdir(Splines[curlev],hgt);
    #local xdr = vecnorm(Splines[curlev],hgt);
    #local ydr = vecortho(Splines[curlev],hgt);
    #local nps = <0,0,0>+Splines[curlev](hgt);
    #local nvb = zdr*sin(azim)+(xdr*cos(lngt)+ydr*sin(lngt))*cos(azim);
    #local nrb = rTop*(1-(1-qjb)*(1-qrb)*hgt);
    #local nrt = (curlev=1 ? 0 : nrb*qrb);
    MakeBranch(iName, curlev, nps, nvb, nrb, nrt, false, fName)
   #end
  #end
 #end

 // trunk specials
 #if (Level=Level0)
  // twigs
  #if(twigproba>0)
   #local i=0;
   #local nrb = rb[0];
   #local nrt = 0;
   #while (i<nseg)
    #if (rand(rd)<=twigproba)
     #local hgt=(i+rand(rd))/nseg;
     #local azim = pi*rand(rd)*.25; // Latitude
     #local lngt = 2*pi*rand(rd); // Longitude
     #local zdr = vecdir(Splines[curlev],hgt);
     #local xdr = vecnorm(Splines[curlev],hgt);
     #local ydr = vecortho(Splines[curlev],hgt);
     #local nps = <0,0,0>+Splines[curlev](hgt);
     #local nvb = zdr*sin(azim)+(xdr*cos(lngt)+ydr*sin(lngt))*cos(azim);
     MakeBranch(iName, 1, nps, nvb, nrb, nrt, false, fName)
     #local i = i + 1;
    #end
   #end
  #end

  // roots
  #if (rootproba>0)
   #local nps = yroot;
   #local nrb = rb[1];
   #local nrt = rb[0];
   #local i=0;
   #while (i<nroot)
    #if (rand(rd)<=rootproba)
     #local yang = i/nroot*360;
     #local nvb = vrotate(vroot,y*yang);
     MakeRoot(iName, 2, nps, nvb, nrb, nrt, fName)
     #local i = i + 1;
    #end
   #end
  #end
 #end
#end

#macro MakeRoot(iName, Level, pos, vb, rBase, rTop, fName)
  #include iName
 #debug concat("level ",str(Level,0,0),"\n") #end
 //-----------------------------------------
 // The root is made up of segments
 // First we create the root segments
 //-----------------------------------------
 #local nseg=max(1,nseg0-level0+Level);  // number of root segments, ERROR
IS HERE
 #local lbseg=lb[Level]/nseg; // length of root segment
 #local i=0;
 #local ay= 360*(0.5-rand(rd));
 #local curpos = pos;
 #local curlev = Level-1;
 #declare Splines[curlev] = spline {
  cubic_spline
  0, curpos
  #while (i<nseg)
   //-----------------------------------------
   // Segment calculation and positionning
   //-----------------------------------------
    #declare rad0 = rBase;
      #declare rad1 = rTop;
   // calculates the force (wind, gravity) to apply to the segment
   // the force is stronger at the end of the root
   // for trunk, vpush gets a vertical boost if dotop is true
   #local fp = 0.2;
   #local vp = -y*i/nseg;
   // then we add the gnarledness
   #local vg=<0.5-rand(rd),0.5-rand(rd),0.5-rand(rd)>;
   #if (vlength(vg)>0) #local vg=vnormalize(vg); #end
   // now we calculate the position ; vb is the original direction of the
segment
   #local curpos =
curpos+lbseg*vnormalize(vb+vp*fp+vg*fgnarl)*(1+(0.5-rand(rd))*stdlseg);
   // distant segments must be kept under the ground
      #if (curpos.y>0 & (i/nseg)>=0.3) #local curpos=curpos*<1,0,1>; #end
      #local i = i + 1;
      i, curpos
  #end
 }
 MakePara(curlev, Splines[curlev], fName)

  // set up continuing root, if applicable
 #if (Level>1)
   #local nrb = rTop;
   #local nrt = (curlev=1 ? 0 : nrb*qrb);
  #local nps = Splines[curlev](1);
  #local nvb = vecdir(Splines[curlev],1);
  MakeRoot(iName, curlev, nps, nvb, nrb, nrt, false, fName)

  // now the others
  #local i = 1;
  #while (i<nroot);
   #local i = i + 1;
   #if (rand(rd)<=rootproba)
    #local hgt=int(jb)+rand(rd)*(1-jb);
    #local azim = radians(i*360/nb + stday*(0.5-rand(rd))); // Latitude
    #local lngt = radians(ab[level] + stdax*(0.5-rand(rd))); // Longitude
    #local zdr = vecdir(Splines[curlev],hgt);
    #local xdr = vecnorm(Splines[curlev],hgt);
    #local ydr = vecortho(Splines[curlev],hgt);
    #local nps = <0,0,0>+Splines[curlev](hgt);
    #local nvb = zdr*sin(azim)+(xdr*cos(lngt)+ydr*sin(lngt))*cos(azim);
    #local nrb = rTop*(1-(1-qjb)*(1-qrb)*hgt);
    #local nrt = (curlev=1 ? 0 : nrb*qrb);
    MakeRoot(iName, curlev, nps, nvb, nrb, nrt, false, fName)
   #end
  #end
 #end
#end

The macros are never called--the error happens when the file with the macros
is first parsed.  Not even the parameters are recognized.  POV-Ray should
not check for undefined variables within a macro until it is called.  What
makes this strange is that the first macro has the same potential for the
error but does not trigger one.


Post a reply to this message

From: Warp
Subject: Re: Macro variable checks
Date: 28 Nov 2002 03:51:56
Message: <3de5d92c@news.povray.org>
David Wallace <dar### [at] earthlinknet> wrote:
>  #debug concat("level ",str(Level,0,0),"\n") #end

  The error is in that line.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

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