|
![](/i/fill.gif) |
Tim Attwood wrote:
<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 -----
Seems to work, haven't tested what happens when I use a zero vector.
Thanks.
--
Dan Johnson
http://www.geocities.com/zapob
Post a reply to this message
|
![](/i/fill.gif) |