POV-Ray : Newsgroups : povray.advanced-users : One works one doesn't? : Re: One works one doesn't? Server Time
29 Jul 2024 18:26:54 EDT (-0400)
  Re: One works one doesn't?  
From: Tim Attwood
Date: 22 Jun 2001 06:01:46
Message: <3B331788.742FB8BE@worldnet.att.net>
Dan Johnson wrote:

> Fixed all the other known bugs in my code this weekend.  I still don't
> know why the first one of these doesn't work, and the second one does.
>
> <snip>
> > /*#macro Quaternion(Angle,Vector)   // creates a normalized rotation
> > quaternion... angle in radians
> >         #if (vlength(Vector)=0)
> >          #warning "0 vector not allowed\nUsing identity Quaternion"
> >          <1,0,0,0>
> >         #else
> >          #local A = Angle/2;
> >          #local V = sin(A)*vnormalize(Vector);
> >          <cos(A),V.x,V.y,V.z>
> >         #end
> > #end*/
> > #macro Quaternion(Angle,Vector)   //Old version
> >         #if (vlength(Vector)=0) #warning "0 vector not allowed" #end
> >         #local A = Angle/2;
> >         #local V = sin(A)*vnormalize(Vector);
> >         <cos(A),V.x,V.y,V.z>
> > #end
> <snip>

Ok, the problem is that macros aren't full subroutines like you might
expect. For example

#macro example(a)
  #if (a=0)
   <1,0,0,0>
  #else
   <0,0,0,0>
  #end
#end

Parses into this when the macro is evaluated...

  #if (a=0)
   <1,0,0,0>
  #else
   <0,0,0,0>
  #end

And at this level everything needs to be legal, it chokes.
The solution is to dump everything into #locals..

#macro Quaternion(Angle,Vector)   // creates a normalized rotation
 quaternion... angle in radians
         #if (vlength(Vector)=0)
          #warning "0 vector not allowed\nUsing identity Quaternion"
          #local A = 1;
          #local V = <0,0,0>;
         #else
          #local A = cos(Angle/2);
          #local V = sin(Angle/2)*vnormalize(Vector);
         #end
       <A,V.x,V.y,V.z>
#end

----- Tim Attwood -----


Post a reply to this message

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