|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Hello everybody,
I need to understand exactly how can I specify in POV-RAY a
user-defined-function...I read many guide and tutorial and I have not
understand if it's possible or not...for example: I need to define a
function that take 3 parameters (a,b,c) and give in output sqrt
(a^2+b^2+c^2)...Can somebody send me an example and tell me exactly where I
have to put this function's code in a povray source file?
Thanks a lot,
Leo
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
web.43c4e70d47b9b0fe72071f7b0@news.povray.org...
> Hello everybody,
>
> I need to understand exactly how can I specify in POV-RAY a
> user-defined-function...I read many guide and tutorial and I have
> not
> understand if it's possible or not...for example: I need to define a
> function that take 3 parameters (a,b,c) and give in output sqrt
> (a^2+b^2+c^2)...Can somebody send me an example and tell me exactly
> where I
> have to put this function's code in a povray source file?
#macro myFunction(a,b,c)
sqrt(a*a+b*b+c*c)
#end
...
#declare foo=myFunction(3,4,5);
hope that help,
klp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Leo80s <nomail@nomail> wrote:
> I need to understand exactly how can I specify in POV-RAY a
> user-defined-function...I read many guide and tutorial and I have not
> understand if it's possible or not...for example: I need to define a
> function that take 3 parameters (a,b,c) and give in output sqrt
> (a^2+b^2+c^2)...Can somebody send me an example and tell me exactly where I
> have to put this function's code in a povray source file?
#declare MyFunction = function(a,b,c) { sqrt(a*a+b*b+c*c) };
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
kurtz_le_pirate <kur### [at] yahoofr> wrote:
> #macro myFunction(a,b,c)
> sqrt(a*a+b*b+c*c)
> #end
There's a difference between macros and user-defined functions.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Warp <war### [at] tagpovrayorg> wrote:
> kurtz_le_pirate <kur### [at] yahoofr> wrote:
> > #macro myFunction(a,b,c)
> > sqrt(a*a+b*b+c*c)
> > #end
>
> There's a difference between macros and user-defined functions.
>
> --
> - Warp
Can you explain exactly in what macros and user defined function are
different, lease?
thanks Leo
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Hello , I need an help...
I can't understand the way I could specify the value returned by a function
(or a macro?!)...isn't there something similar a return statement?!?!
for example, how can I write a function that take an integer as parameter
and give in output the value of this integer if it's positive and 0
otherwise???
Leo
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Wasn't it Leo80s who wrote:
>
>how can I write a function that take an integer as parameter
>and give in output the value of this integer if it's positive and 0
>otherwise???
#declare myFunction = function(a){select (a, 0, a)}
--
Mike Williams
Gentleman of Leisure
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
In article <43c4fd96@news.povray.org>, Warp <war### [at] tagpovrayorg>
wrote:
> kurtz_le_pirate <kur### [at] yahoofr> wrote:
> > #macro myFunction(a,b,c)
> > sqrt(a*a+b*b+c*c)
> > #end
>
> There's a difference between macros and user-defined functions.
oooops, you'r right... read too quick, answer too quick :))
klp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Leo80s <nomail@nomail> wrote:
> Can you explain exactly in what macros and user defined function are
> different, lease?
Macros are a lot more generic entities than functions. While a macro
can be used as if it was a function (except in certain cases), it can be
used for a lot more. For example, you can make a macro which creates an
object (something which a user-defined function cannot do).
In a way, you can think about a macro as if it was a subroutine call
in a programming language.
A user-defined function resembles a lot more a mathematical function:
It takes numerical parameters and it returns a numerical value (based on
mathematical operations performed on these input values), and it basically
cannot do anything else. You cannot use a user-defined function for example
to create an object.
For example:
#macro CreateSphere(Location, Radius)
sphere { Location, Radius }
#end
This is not a mathematical function. It doesn't even return a numerical
value. It just creates a sphere. Macros don't really have a return value
per se.
Macros work almost like substitution macros in C: It's almost as if
the macro call was substituted by the contents of the macro.
You can't do that with user-defined functions. These can only be used
for calculating a mathematical operation, and the return value of such
function is the result of the operation in question.
You can often simulate a function with a macro. For example:
#macro Length(A, B, C)
sqrt(A*A+B*B+C*C)
#end
This will work a lot like a function. You can call it like Length(1,2,3)
(you can think about it as if the call in question is substituted by the
contents of the macro).
That is basically the equivalent of:
#define Length = function(A,B,C) { sqrt(A*A+B*B+C*C) };
Then what is the difference? Why have user-defined functions at all
since macros can be used for the same thing?
For one, user-defined functions are a whole lot faster. If you need to
call such a function millions of times, it's a whole lot faster to do it
with a user-defined function than with a macro.
Secondly, user-defined functions can be used in some render-time
features, more specifically isosurfaces and parametric surfaces, while
macros cannot (macros are purely parse-time entities and they simply
don't exist at render time).
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Leo80s <nomail@nomail> wrote:
> I can't understand the way I could specify the value returned by a function
> (or a macro?!)...isn't there something similar a return statement?!?!
The return value of the function is directly the evaluated expression
inside it. You don't have to "return" it explicitly.
If you write:
#declare Func = function(A) { A*A };
then the return value of Func will be its parameter squared.
With macros things get slightly more complicated. If you have just
a simple mathematical expression as the body of the macro, that serves
as its "return value". For example:
#macro Func(A)
A*A
#end
If the macro contains control flow commands, you have to use a small
trick to put a "return value". It works for example like this:
#macro Func(A)
#if(A < 0)
#local Result = -A;
#else
#local Result = A;
#end
A
#end
The value of the last line of this macro is what is ultimately used as
the "substitution" of the macro call, which is practice is its "return
value".
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |