POV-Ray : Newsgroups : povray.advanced-users : Function logic? : Function logic? Server Time
28 Jul 2024 16:17:48 EDT (-0400)
  Function logic?  
From: Tim Nikias
Date: 6 Dec 2004 09:33:11
Message: <41b46da7$1@news.povray.org>
Could someone explain to me, why I have to include an #if-switch into my
macro?

First, the explanation of the macro:
I'm building a function that I later use for a heightfield. As the
heightfield is generated from the xy-plane, I need to align the pigment
which I "build" on the xz-plane for better visualization in my head, but I
have removed that part from the macro for simplification. I have made
"pigment-stamps" for the steps, and just position a step, feed it to the
macro, and it multiplies the original snow-field with the new step, and
voila! I've got another footprint in the snow. The old snow-function is
replaced with the new one, all temporary function-conversions released via
#undef and I'm prepared for the next print (or snowball ;-).

So, here's the Macro:
#macro Add2SnowFunction(_Pigment1)
  #ifndef (_SnowAdded) #declare _SnowAdded = 0; #end
  #declare _Temp1Function = function{pigment{_Pigment1}}
  #if (_SnowAdded=0)
    #declare _Temp2Function = function{SnowFunction(x,y,z).x *
_Temp1Function(x,y,z).x}
  #else
    #declare _Temp2Function = function{SnowFunction(x,y,z) *
_Temp1Function(x,y,z).x}
  #end
  #undef SnowFunction
  #declare SnowFunction = _Temp2Function;
  #undef _Temp1Function
  #undef _Temp2Function
  #declare _SnowAdded = 1;
#end

Now to the problem: Why is it that I have to put a ".x" after the function
the first time I use it, but not afterwards? Fact is, if I don't use it the
first time, I get an error message, and if I use it every time, I get an
error message. Hence, I need to write a check into my Macro to look if it
has already been called once. And even with this switch, if I decide to
modify the function "by hand" (without the use of the macro) the switch
won't work. And #ifdef doesn't do the job, obviously, #ifdef tells me that
SnowFunction is declared, be it first time of use or 100th time of use, so
it's no help. Explanations or a better, working, ingenious way for the
switch appreciated.

Regards,
Tim

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

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