POV-Ray : Newsgroups : povray.advanced-users : Implicit loops in function(x,y,z) : Re: Implicit loops in function(x,y,z) Server Time
3 Jul 2024 04:48:37 EDT (-0400)
  Re: Implicit loops in function(x,y,z)  
From: Warp
Date: 14 Jul 2008 12:14:24
Message: <487b7b60@news.povray.org>
slehar <sle### [at] gmailcom> wrote:
> Do you mean that you cannot #declare temporary variables in a function?

  The SDL and a user-defined function are completely separate namespaces.
You cannot mix them.
  The only thing you can do with SDL is to generate content for the function,
but the SDL doesn't see the function in any way or form.

  It's a big like if you used #write commands to generate a program in C.
The C program knows nothing about the SDL, and the SDL knows nothing about
C. Their only relation was that the SDL was used to generate the C source
code.

  It's not much different with user-defined functions: They don't know
anything about each other (even though you can use SDL to generate the
contents of a function).

  Yes, I know it's a bit confusing because these two distinct languages
look a bit alike (both use, for example, mathematical functions named
in the same way).

  You cannot have any kind of variables (besides the function parameters)
in functions, because the function syntax doesn't support them.

> #declare densityfunc = function( px, py, pz) {
>   #declare pxVal = px;
>   #declare pyVal = py;
>   atan2(pyVal, pxVal)
> }

  When POV-Ray finds the #declare, it jumps to the SDL parser (until
the #declare ends in the semi-colon). In that context it doesn't know
what 'px' or 'py' means because they don't exist in the SDL namespace.

  If you assigned pxVal and pyVal something else, eg. 1 and 2, then
it would work. However, what is happening is that you are simply generating
the function contents using SDL (in other words, POV-Ray substitutes pxVal
with 1 and pyVal with 2 when it encounters them, and then the function
parser sees them as numeral values).

> You can only use the values directly?

  You can only use function parameter names in the function because
those are the only things defined inside the function's namespace.

-- 
                                                          - Warp


Post a reply to this message

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