POV-Ray : Newsgroups : povray.general : Array scope/persistance and vtransform Server Time
5 Nov 2024 07:20:22 EST (-0500)
  Array scope/persistance and vtransform (Message 1 to 4 of 4)  
From: [GDS|Entropy]
Subject: Array scope/persistance and vtransform
Date: 1 Feb 2009 08:40:12
Message: <4985a63c$1@news.povray.org>
I am trying to fill an array with vectors from inside the loop which builds 
the vectors, to be used outside of that loop (by a macro which tests ray 
intersection, and if so draws a glow).
So far I have been completely unsuccessful, having tried setting the array 
up two different ways each producing a different error stating that the one 
thing or another is uninitialized.

I have read the FM regarding arrays, but still fail to see their usefulness 
if the data they contain isn't portable outside the scope of the loop which 
populates them.
I just want a List<T> right about now...

What I am trying to do is this (pseudo code to save space):

declare array

macro
loop
 fill array
endloop
endmacro

use array

If I had my List<T> I could just do:

List<vector> myList = new List<vector>();
while (n < 6)
{
 myList.Add(<Math.Sin(n),n,Math.Cos(n)>)
 n++;
}

foreach(vector v in myList)
{
 testRay(v,cam_pt,myObject)
}

Is there a way to do this in povray?

My second question: I have an object constructed thusly-I translate an 
object(a) into an "object(b) of objects(a)" in one loop, then translate that 
"object(b)" into an "object(c) of objects(b)". Is there a way using an array 
as specified above, to determine the end position in object(c) of each 
object(a) using vtransform (or something)? Am I close?

I've used pov for years, but never consistantly enough to know how to do 
either of these two things in SDL.

I am half considering just writing a freaking C# program to dump my vectors 
into a file, which I could import into povray...but thats a really ugly 
solution.

I would really appreciate any help with this, as these two problems have 
plagued me for years in various incarnations across many WIP, including my 
most recent. >_<'

thanks,
ian


Post a reply to this message

From: Chris B
Subject: Re: Array scope/persistance and vtransform
Date: 1 Feb 2009 09:52:35
Message: <4985b733$1@news.povray.org>
"[GDS|Entropy]" <gds### [at] hotmailcom> wrote in message 
news:4985a63c$1@news.povray.org...
>I am trying to fill an array with vectors from inside the loop ... snip ...
> What I am trying to do is this (pseudo code to save space):
>
> declare array
>
> macro
> loop
> fill array
> endloop
> endmacro
>
> use array
>
> Is there a way to do this in povray?
>

Yes:

--------

// Define the macro
#macro YourMacro()
  #local I=0;
  #while (I<6)
    #declare Data[I]=<sin(I),I,cos(I)>;
    #local I=I+1;
  #end
#end

// Declare your Array
#declare Data = array [9];

// Call the Macro to populate the array
YourMacro()

// Use the Array (in this case I simply write a
// vector value into the message stream)
#debug concat("Data element 3: <",vstr(3,Data[3],",",3,3),">\n")

-------

Using the #declare directive gives the array global scope wherever it is 
declared (so you could equally well declare it within your macro).

> My second question: I have an object constructed thusly-I translate an 
> object(a) into an "object(b) of objects(a)" in one loop, then translate 
> that "object(b)" into an "object(c) of objects(b)". Is there a way using 
> an array as specified above, to determine the end position in object(c) of 
> each object(a) using vtransform (or something)? Am I close?
>

If you assign the various translations to variables (or to elements of 
arrays), then you can calculate cumulative values. For example, if ObjectA 
is translated by a value assigned to array element Data[3], and if ObjectA 
is added to a union of objects called ObjectB, which is then translated by a 
value assigned to variable ObjectBTranslationVector, then the total 
translation is Data[3]+ObjectBTranslationVector.

You can also do something similar with rotation vectors, using the vrotate 
function to calculate the total rotation.
Another option is to store entire tranformations (translations, rotations 
and scale factors) against identifiers (e.g. as array elements). Entire 
transformations can be 'accumulated' using 'transform'.

regards,
Chris B.


Post a reply to this message

From: clipka
Subject: Re: Array scope/persistance and vtransform
Date: 1 Feb 2009 15:45:00
Message: <web.498609837696691ff8450bd80@news.povray.org>
"[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
> I just want a List<T> right about now...

Yeah, I know that feeling ;) Some "foreach" would come in handy, too... oh, I
see you mention that in your post as well...


> List<vector> myList = new List<vector>();

#declare mySize = 6;
#declare myArray = array[mySize];

> while (n < 6)
> {

#declare n = 0;
#while (n < mySize)

>  myList.Add(<Math.Sin(n),n,Math.Cos(n)>)

  #declare myArray[i] = <sin(n),n,cos(n)>;

>  n++;

  #declare n = n + 1;

> }

#end


> foreach(vector v in myList)
> {

#declare n = 0;
#while (n < mySize)
  #declare v = myArray[n];

>  testRay(v,cam_pt,myObject)

  testRay(v,cam_pt,myObject)

> }

  #declare n = n + 1;
#end


> Is there a way to do this in povray?

See above. It *should* to the job, although I might have added some typos.

It gets somewhat problematic if you need to later add more elements to the array
though: There simply isn't such a thing as a List<T> in POV SDL.

> My second question: I have an object constructed thusly-I translate an
> object(a) into an "object(b) of objects(a)" in one loop, then translate that
> "object(b)" into an "object(c) of objects(b)". Is there a way using an array
> as specified above, to determine the end position in object(c) of each
> object(a) using vtransform (or something)? Am I close?

I must confess I haven't a clue what you intend to do. Can you try to rephrase
that?


> I am half considering just writing a freaking C# program to dump my vectors
> into a file, which I could import into povray...but thats a really ugly
> solution.

I think at times it's a much more beautiful one ;)


Post a reply to this message

From: [GDS|Entropy]
Subject: Re: Array scope/persistance and vtransform
Date: 4 Feb 2009 11:03:54
Message: <4989bc6a$1@news.povray.org>
Just wanted to say thank you to Chris B and clipka, you guys solved it. :-)

ian

"[GDS|Entropy]" <gds### [at] hotmailcom> wrote in message 
news:4985a63c$1@news.povray.org...
>I am trying to fill an array with vectors from inside the loop which builds 
>the vectors, to be used outside of that loop (by a macro which tests ray 
>intersection, and if so draws a glow).
> So far I have been completely unsuccessful, having tried setting the array 
> up two different ways each producing a different error stating that the 
> one thing or another is uninitialized.
>
> I have read the FM regarding arrays, but still fail to see their 
> usefulness if the data they contain isn't portable outside the scope of 
> the loop which populates them.
> I just want a List<T> right about now...
>
> What I am trying to do is this (pseudo code to save space):
>
> declare array
>
> macro
> loop
> fill array
> endloop
> endmacro
>
> use array
>
> If I had my List<T> I could just do:
>
> List<vector> myList = new List<vector>();
> while (n < 6)
> {
> myList.Add(<Math.Sin(n),n,Math.Cos(n)>)
> n++;
> }
>
> foreach(vector v in myList)
> {
> testRay(v,cam_pt,myObject)
> }
>
> Is there a way to do this in povray?
>
> My second question: I have an object constructed thusly-I translate an 
> object(a) into an "object(b) of objects(a)" in one loop, then translate 
> that "object(b)" into an "object(c) of objects(b)". Is there a way using 
> an array as specified above, to determine the end position in object(c) of 
> each object(a) using vtransform (or something)? Am I close?
>
> I've used pov for years, but never consistantly enough to know how to do 
> either of these two things in SDL.
>
> I am half considering just writing a freaking C# program to dump my 
> vectors into a file, which I could import into povray...but thats a really 
> ugly solution.
>
> I would really appreciate any help with this, as these two problems have 
> plagued me for years in various incarnations across many WIP, including my 
> most recent. >_<'
>
> thanks,
> ian
>
>


Post a reply to this message

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