POV-Ray : Newsgroups : povray.newusers : Returning values from macros Server Time
28 Mar 2024 07:28:26 EDT (-0400)
  Returning values from macros (Message 1 to 10 of 24)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Returning values from macros
Date: 30 May 2016 09:45:00
Message: <web.574c42c785b41ebb5e7df57c0@news.povray.org>
I'm playing with some power transmission towers that I decided to cobble
together.

No idea why - they just suddenly captured my interest, and a recent post about
catenary curves seemed to fuel my need to play with power lines in POV-Ray.

Anyway,  I'd like to be able to collect the coordinates of the attachment points
for the power lines so I can string the towers together...

However - yet again I got myself into a roundabout in a cul-de-sac and am
getting annoyed and frustrated (mostly with myself).

Searching the web and the forums doesn't yield much in terms of specific
examples, explanation, or instruction - which ideally would include caveats
about what doesn't work, will likely cause problems, and what should be avoided.
  Some good old fashioned "here's *WHY* you do it _this way_ and NOT _that way_"
would be best all around for clarity and longevity for folks who will be wanting
to understand the solution to this problem in the future.

Could someone please post a small, simple macro that results in a scalar, a
vector, and an array getting passed "out" to the global SDL world?

I want to collect a one-dimensional array as a "line" of a 2D array, thus
generating a list of connection points in one dimension, with the object they
are attached to being represented by the 2nd dimension - if that makes sense.
(PointArray[1][1] would be an endpoint on one object, and PointArray[2][1] would
be the analogous point on the second object, etc. )

Thanks!


Post a reply to this message

From: Cousin Ricky
Subject: Re: Returning values from macros
Date: 30 May 2016 12:20:00
Message: <web.574c67d776b80bcd71c9a5f20@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Could someone please post a small, simple macro that results in a scalar, a
> vector, and an array getting passed "out" to the global SDL world?

You can pass them back through the macro arguments by declaring the formal
parameters with the final results.  For example:

  #macro MyMacro (S, V, A)
    #declare S = 1;
    #declare V = <2, 3, 4>;
    #declare A = array[5]
    #for (I, 0, 4)
      #declare A[I] = pow (I, 2);
    #end
  #end

The argument identifiers would need to be declared with dummy values before
passing them to the macro.

Be careful with this technique.  It is frowned upon in structured programming,
but without heterogeneous data structure capability, POV-Ray SDL leaves you
little choice.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 12:35:01
Message: <web.574c6a9876b80bcd5e7df57c0@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > Could someone please post a small, simple macro that results in a scalar, a
> > vector, and an array getting passed "out" to the global SDL world?
>
> You can pass them back through the macro arguments by declaring the formal
> parameters with the final results.  For example:
>
>   #macro MyMacro (S, V, A)
>     #declare S = 1;
>     #declare V = <2, 3, 4>;
>     #declare A = array[5]
>     #for (I, 0, 4)
>       #declare A[I] = pow (I, 2);
>     #end
>   #end
>
> The argument identifiers would need to be declared with dummy values before
> passing them to the macro.
>
> Be careful with this technique.  It is frowned upon in structured programming,
> but without heterogeneous data structure capability, POV-Ray SDL leaves you
> little choice.

I see what you're doing - I'd call that "redeclaring" the values of existing
variables.
Could you perhaps illuminate me as to how say, array A, on a line all its own,
gets passed out of a macro?
I have both sucessfuly and unsuccessfully done it that way, but I can't clearly
see what happens to make it work or not work.

So, for instance:
#macro MyMacro (Input)
  #declare Output = pow (Input, 2);
  Output
#end

#declare Variable = MyMacro (2);

Can I have several lines such as
Output1
Output2
Output3   ?

Can I have SDL inside the macro that creates a sphere and then returns Input^2 ?

I'm trying to understand the "mechanics"  and all too often failing.


Thanks for your assistance   :)


Post a reply to this message

From: Le Forgeron
Subject: Re: Returning values from macros
Date: 30 May 2016 13:40:29
Message: <574c7b0d$1@news.povray.org>
Le 30/05/2016 18:30, Bald Eagle a écrit :
> "Cousin Ricky" <rickysttATyahooDOTcom> wrote:
>> "Bald Eagle" <cre### [at] netscapenet> wrote:
>>> Could someone please post a small, simple macro that results in a scalar, a
>>> vector, and an array getting passed "out" to the global SDL world?
>>
>> You can pass them back through the macro arguments by declaring the formal
>> parameters with the final results.  For example:
>>
>>   #macro MyMacro (S, V, A)
>>     #declare S = 1;
>>     #declare V = <2, 3, 4>;
>>     #declare A = array[5]
>>     #for (I, 0, 4)
>>       #declare A[I] = pow (I, 2);
>>     #end
>>   #end
>>
>> The argument identifiers would need to be declared with dummy values before
>> passing them to the macro.
>>
>> Be careful with this technique.  It is frowned upon in structured programming,
>> but without heterogeneous data structure capability, POV-Ray SDL leaves you
>> little choice.
> 
> I see what you're doing - I'd call that "redeclaring" the values of existing
> variables.
> Could you perhaps illuminate me as to how say, array A, on a line all its own,
> gets passed out of a macro?
> I have both sucessfuly and unsuccessfully done it that way, but I can't clearly
> see what happens to make it work or not work.
> 
> So, for instance:
> #macro MyMacro (Input)
>   #declare Output = pow (Input, 2);
>   Output
> #end
> 
> #declare Variable = MyMacro (2);
> 
> Can I have several lines such as
> Output1
> Output2
> Output3   ?
> 
> Can I have SDL inside the macro that creates a sphere and then returns Input^2 ?

Do not see macro as a function calls, but as text substitution.

It might help.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 14:15:00
Message: <web.574c82a476b80bcd5e7df57c0@news.povray.org>
Le_Forgeron <jgr### [at] freefr> wrote:

> Do not see macro as a function calls, but as text substitution.
>
> It might help.

Thanks Jerome - it does help - sometimes, but it still gets complicated as the
contents of the macro get larger and more complex.

I'd still like to see a few working code examples that would act as a good
reference source when trying to write and debug my own macros.

THIS you can do, THAT you can't - really helps to demonstrate it, rather than
general, generic "explanations" like in the documentation.

"Seeing" what makes or breaks a chunk code helps in having that "a-HA!" moment
that's so often needed.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Returning values from macros
Date: 30 May 2016 14:50:01
Message: <web.574c8a6d76b80bcd71c9a5f20@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I'd still like to see a few working code examples that would act as a good
> reference source when trying to write and debug my own macros.

There are two very good sources of such examples: The default include directory
and the Object Collection.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 17:15:01
Message: <web.574cac5f76b80bcd5e7df57c0@news.povray.org>
"Cousin Ricky" <rickysttATyahooDOTcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > I'd still like to see a few working code examples that would act as a good
> > reference source when trying to write and debug my own macros.
>
> There are two very good sources of such examples: The default include directory
> and the Object Collection.

Right on.   I'll take a look through those and see if I can get a better grip on
the things I'd like to do.

So naughty, cleverly hiding those macros right under my nose!   :O


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 17:25:00
Message: <web.574cae7f76b80bcd5e7df57c0@news.povray.org>
I've debugged a fair amount of stuff, and gotten a decent first draft of what I
was shooting for.

Has anyone used PM 2Ring's catenary macro?
I have TWO such include files - one takes 6 arguments, and the other like 11.
I couldn't get the larger one to work, and the smaller one has some issues I'm
trying to resolve.

First, the macro doesn't seem to bring the Link objects right to the endpoints,
so there's dead space - unless there's some parameter I need to tweak, or
there's a specific way to define the link object.

Second, for certain values of SLACK, and certain distances between endpoints,
the macro inverts the catenary so that it looks like anti-gravity just kicked
in.

Apparently there's a similar macro written by Mike Williams that I need to find.


I also found this rope macro, but the referenced link doesn't wind up getting
displayed properly in my browser (Chrome) - it looks like the source HTML, with
all of the tags visible, and not properly formatted as HTML.   Does anyone else
have this problem?

http://lib.povray.org/collection/rope/chrisb%201.0/rope.html


Post a reply to this message

From: jr
Subject: Re: Returning values from macros
Date: 30 May 2016 17:56:30
Message: <574cb70e$1@news.povray.org>
hi,

On 30/05/2016 22:19, Bald Eagle wrote:
> I also found this rope macro, but the referenced link doesn't wind up getting
> displayed properly in my browser (Chrome) - it looks like the source HTML, with
> all of the tags visible, and not properly formatted as HTML.   Does anyone else
> have this problem?
> 
> http://lib.povray.org/collection/rope/chrisb%201.0/rope.html

looking at that page, the <style> tag belongs inside the <head>, perhaps
that's the cause?

jr.


Post a reply to this message

From: Bald Eagle
Subject: Re: Returning values from macros
Date: 30 May 2016 18:20:01
Message: <web.574cbba576b80bcd5e7df57c0@news.povray.org>
jr <cre### [at] gmailcom> wrote:

> looking at that page, the <style> tag belongs inside the <head>, perhaps
> that's the cause?
>
> jr.

Good eye, Junior   ;)

I copied all, pasted, and cut & pasted the <head> tag above the style, and that
fixed it (locally).


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

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