POV-Ray : Newsgroups : povray.general : Array scope/persistance and vtransform : Re: Array scope/persistance and vtransform Server Time
30 Jul 2024 12:23:57 EDT (-0400)
  Re: Array scope/persistance and vtransform  
From: Chris B
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

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