|
|
Lets say that I have an array of vectors, and that I wish to use its
elements a variable number of times (which might be different for each
element) and then remove the used element from the array.
The only thing that I can come up with would be to use a 3D array like this:
// randVectorMMR Macro by [GDS|Entropy]
// For element reuse capability
//------
#macro randVectorMMR(Array,ctr,Min,Max,rMin,rMax)
#local i=0;
#while (i<ctr)
#declare Array[i][0][0] = <RRand(RsA, Min, Max),RRand(RsA, Min,
Max),RRand(RsA, Min, Max)>;
#declare Array[i][1][0] = <0,0,0>;
#declare Array[i][1][1] = <0,RRand(RsA, rMin, rMax),0>;
#set i=i+1;
#end
#end
//------
// RRand Macro by Chris Huff
#macro RRand(RS, Min, Max)
(rand(RS)*(Max-Min) + Min)
#end
// Round macro by [GDS|Entropy]
// Adapted from Trevor G Quayle function
//------
#macro Round(Number,RoundTo)
#if (Number >= 0)
1*int(abs(Number)*pow(10,RoundTo)+0.5)/pow(10,RoundTo)
#else
-1*int(abs(Number)*pow(10,RoundTo)+0.5)/pow(10,RoundTo)
#end
#end
//------
// VRound macro by [GDS|Entropy]
#macro VRound(Vector,RoundTo)
<Round(Vector.x,RoundTo),Round(Vector.y,RoundTo),Round(Vector.z,RoundTo)>
#end
//------
#declare ctr = 10;
#local maxReuse = 10;
#local minReuse = 1;
#declare myArray = array[ctr][2][2];
randVectorMMR(myArray,ctr,1,5,minReuse,maxReuse)
#local i = 0;
#while (i < dimension_size(myArray,1))
#local pos = myArray[i][0][0];
#local use = myArray[i][1][0];
#local ass = VRound(myArray[i][1][1],0);
#debug concat("Array Value: ", vstr(3,pos,",",3,3)," ")
#debug concat("Assigned Reuse : ", vstr(3,ass,",",3,3)," ")
#debug concat("Used: ", vstr(3,use,",",3,3)," times \n")
#if (use.y < maxReuse & use.y < ass.y)
object {
foo
translate pos
}
#declare myArray[i][1][0] = myArray[i][1][0] + 1;
#local i = i;
#else
#local i = i + 1;
#end
#end
#undef myArray
That way sucks, and it doesn't remove the element from the array.
Whats a better way of doing this?
ian
Post a reply to this message
|
|