POV-Ray : Newsgroups : povray.general : array.length()? : Re: array.length()? Server Time
30 Jul 2024 18:16:56 EDT (-0400)
  Re: array.length()?  
From: [GDS|Entropy]
Date: 25 Feb 2009 22:27:34
Message: <49a60c26$1@news.povray.org>
Well at this point there are no longer any issues with the multiple 
summoning of arrays as defined in previous macros, as the following example 
shows:

//      randVectorMM Macro by [GDS|Entropy]
//------
#macro randVectorMM(Array,ctr,RsA,Min,Max,Method,Object)
 #local vectorA = min_extent(Object);
 #local vectorB = max_extent(Object);
 #local i=0;
 #while (i<ctr)
  #switch (Method)
   #case (0)
    #declare Array[i] = <RRand(RsA, Min+vectorA.x, Max+vectorB.x),RRand(RsA, 
Min+vectorA.y, Max+vectorB.y),RRand(RsA, Min+vectorA.z, Max+vectorB.z)>;
   #break
   #case (1)
    #declare Array[i] = <sin(RRand(RsA, Min+vectorA.x, 
Max+vectorB.x)),RRand(RsA, Min+vectorA.y, Max+vectorB.y),tan(RRand(RsA, 
Min+vectorA.z, Max+vectorB.z))>;
   #break
   #case (2)
    #declare Array[i] = <sin(RRand(RsA, Min+vectorA.x, 
Max+vectorB.x)),atanh(RRand(RsA, Min+vectorA.y, 
Max+vectorB.y)),tan(RRand(RsA, Min+vectorA.z, Max+vectorB.z))>;
   #break
   #case (3)
    #declare Array[i] = <asin(RRand(RsA, Min+vectorA.x, 
Max+vectorB.x)),atanh(RRand(RsA, Min+vectorA.y, 
Max+vectorB.y)),tan(RRand(RsA, Min+vectorA.z, Max+vectorB.z))>;
   #break
   #case (4)
    #declare Array[i] = <acosh(RRand(RsA, Min+vectorA.x, 
Max+vectorB.x)),asinh(RRand(RsA, Min+vectorA.y, 
Max+vectorB.y)),tan(RRand(RsA, Min+vectorA.z, Max+vectorB.z))>;
   #break
   #case (5)
    #declare Array[i] = <cos(i+RRand(RsA, Min+vectorA.x, 
Max+vectorB.x)),i+RRand(RsA, Min+vectorA.y, Max+vectorB.y),sin(i+RRand(RsA, 
Min+vectorA.z, Max+vectorB.z))>;
   #break
  #end
 #set i=i+1;
 #end
#end

//surrounding macro excised before and after the following snippet
#declare sRandVectArray = array [snowCounter];
randVectorMM(sRandVectArray,snowCounter,seed(3141592654),-sFudgeFactor,sFudgeFactor,sMethod,testObject)
//------

I could go so far as to define get/set macros for everything, but in this 
case, I think that would be going a little far. :p

SDL gets easier and easier for me as I continue to learn tricks that make it 
behave like other C based languages.

There was an example file by Jean-Charles Marteau regarding Object Oriented 
POV code that I have, and can't seem to locate the download location for 
that did a pretty good job of this.

I can post the zip to p.b.i if anyone is interested.

ian

"Bill Pragnell" <bil### [at] hotmailcom> wrote in message 
news:web.49a50c3678dc09ae6dd25f0b0@news.povray.org...
>> "Bill Pragnell" <bil### [at] hotmailcom> wrote in message
>> > Just an extra thought - couldn't you globally #declare your array size
>> > when you
>> > populate it, then use this value in the second macro?
>
> "[GDS|Entropy]" <gds### [at] hotmailcom> wrote:
>> I had a version which did this, but I could only summon it once, as any
>> subsequent incarnations redefined the contents upon each call.
>
> I'm not sure I understand the problem... based on the first paragraph of 
> your
> original post, if you keep track of the number of array elements in the 
> first
> macro and #declare an array_size variable (not #local), then this number 
> will
> be available for all subsequent code, just like the array, and you will 
> know how
> many elements to loop through. If you call the same macro again, it will 
> simply
> redefine this counter to reflect the new array contents... is this not 
> what you
> want to do?
>
> I've got the vague feeling that I'm missing something, as this seems too 
> easy a
> solution compared with other replies! :-)
>
> Bill
>
>
>
>


Post a reply to this message

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