|
|
Am 05.04.2018 um 16:21 schrieb Sven Littkowski:
> Hi,
>
> I try to create (for the very first time) an own function, after i saw
> it inside the POV-Ray online help files. Well, i do something wrong.
>
> Basically, the purpose of my function is to create a negative or
> positive float number, that I then can use to rotate something clockwise
> or counter-clockwise. At the moment, it is my brain that is rotating
> counter-clockwise.
You can NOT use directives (such as #if..#else..#end) in functions.
Well, technically you can, but they do something entirely different than
one would naively expect - because they are evaluated only once, when
the function is initially defined.
For example, the scene code
#declare MySeed = seed(4711);
...
#declare MyFn = function(x)
{
#if(rand(MySeed) > 0.5)
x
#else
-x
#end
}
does NOT construct a function that randomly returns its parameter or the
negative thereof, but rather
randomly constructs EITHER a function that returns its parameter, OR a
function that returns the negative of the parameter.
In other words, it is completely equivalent to:
#declare MySeed = seed(4711);
...
#if(rand(MySeed) > 0.5)
#declare MyFn = function(x)
{
x
}
#else
#declare MyFn = function(x)
{
-x
}
#end
Likewise, your scene code
> #declare Number = function(MyNumber)
> {
> #declare MyAngle = rand(NySeed)*MyNumber;
> #declare MyPositive = rand(MySeed)*1.0;
> #if(MyPositive<0.5)
> MyAngle*(+1) // no #declare and no ;
> #else
> MyAngle*(-1) // no #declare and no ;
> #end
> }
is completely equivalent to
#declare MyAngle = rand(NySeed)*MyNumber;
#declare MyPositive = rand(MySeed)*1.0;
#if(MyPositive<0.5)
#declare Number = function(MyNumber)
{
MyAngle*(+1) // no #declare and no ;
}
#else
#declare Number = function(MyNumber)
{
MyAngle*(-1) // no #declare and no ;
}
#end
(which is broken in multiple ways)
Post a reply to this message
|
|