POV-Ray : Newsgroups : povray.general : Problem making macro work right : Re: Problem making macro work right Server Time
8 Aug 2024 06:16:33 EDT (-0400)
  Re: Problem making macro work right  
From: Warp
Date: 19 Feb 2001 09:49:38
Message: <3a913282@news.povray.org>
I had to reindent the code in order to understand. You should really
work on this side :)

  What you are creating in your macro is a bunch of unions. This means that
when you make this:

object {Grid(<2,2,2>,1,.1) pigment{Green}}

it generates code that looks like this:

object
{ union { ... }
  union { ... }
  union { ... }
  ...
}

  You can't have several unions inside an object block.

  By the way, I think that you are missing some #breaks in your #switch.

  Here is the code after I indented it (well, actually I didn't indent it,
I just let emacs to do it automatically):

#include "colors.inc"

light_source {<20,100,-150> rgb 2}
camera {location <0,0,-6> look_at 0}

#macro Arrange_3d (Dimentions_vector,N)
  #local A = Dimentions_vector.x;
  #local B = Dimentions_vector.y;
  #local C = Dimentions_vector.z;
  #local Error_loop = 1;
  #while (Error_loop <= 3)
    #switch (Error_loop)
      #case (1)
        #local Vect = A; #break
      #case (2)
        #local Vect = B; #break
      #case (3)
        #local Vect = C; #break
    #end
    #if (abs(Vect)<1)
      #local Input_error = yes;
    #end
    #if (Vect-int(Vect.x)>0)
      #local Input_error = yes;
    #end
    #if ((Vect/abs(Vect))<0)
      #local Input_error = yes;
    #end
    #local Error_loop = Error_loop + 1;
  #end
  #ifdef (Input_error)
    #if (Input_error = yes)
      #error "Dimentions_vector has a number that is not a natural
      number"
    #end
  #end

  ( (mod(N+A-1,A))*x + (B-mod(div(N+A-1,A)+B-1,B))*y +
    (mod(div(N+B*A-1,B*A)+C-1,C))*z -<A-1,B+1,C-1>/2)
#end  // use only natural numbers aka 1,2,3,4,5,6... no fractions 0 or negative
numbers


#macro Grid (Dimentions_vector,Marker_interval,Marker_scale)

  #local N = 1;
  #while (N <= (((Dimentions_vector.x * 2) +
    1)*((Dimentions_vector.y * 2) +1)*((Dimentions_vector.z * 2) + 1)))
    #local Grid_vector = Arrange_3d(<(Dimentions_vector.x *
      2) + 1,(Dimentions_vector.y * 2) +1,(Dimentions_vector.z * 2) + 1>,N) *
Marker_interval;
    union
    { sphere {0,.5}
      text
      { ttf "timrom.ttf"
        concat("<",str(Grid_vector.x,1,0),",",str(Grid_vector.y,1,0),",",
          str(Grid_vector.z,1,0),">")
        .5 0  translate 1
      }
      scale Marker_scale
      translate Grid_vector
    }
    #local N = N+1;
  #end
#end

object {Grid(<2,2,2>,1,.1) pigment{Green}}


-- 
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

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