|
 |
In article <38F1196B.30A6CB16@fcmail.com>, CMcCabe
<dea### [at] fcmail com> wrote:
> When I run this I get a scene containing four floor objects, although
> I thought that there would be many more floor objects than that. So
> it seems to me that the while loops are executing once and only once.
> Any ideas as to why would be greatly appreciated.
Well, someone else mentioned that you need to reset the loop counter
variables. There are some serious problems with your code in addition to
this.
The first two problems stem from the fact that you are initializing your
loop counters before everything else. Since they are not reset within
the inner loops, those loops complete on the first runthrough and are
skipped after that. The best solution is to put the counter
initialization immediately in front of the #while command.
The second problem is that you declare your Floor object to depend on
the current position, but outside of the loop. Since XPos and ZPos are
0, and you only translate in the y direction inside the loop, you will
end up with a bunch of boxes occupying the same space. It will appear
like one building. You need to declare your Floor object independant of
position, or declare it inside the loop(in which case you might as well
use it directly, no need to declare it).
Third, you assign a random number to a variable, and then use that
variable a bunch of times within the loop. Since you only call rand()
once, in the declaration, you will only get one number. All your
buildings will be the same height. You need to get a new value from
rand() each time you want a new random number.
And finally, unless you intend to use the array of data later in other
code, you don't even need an array. Your code assigns a value to a
position in the array, and then immediately uses that value. You can use
the value directly, and save memory and parse time.
You seem to have a basic misunderstanding of how loops work. Only the
portion between #while and it's matching #end is repeated, and the
counter values only change in that portion. Counter variables are not
reset after the loop.
This is what I think you want:
camera {
location < 1, 5,-16>*10
look_at < 0, 4, 0>
}
light_source {<-10, 20,-15>*1000 color White}
light_source {< 1, 5,-16>*10 color White*0.15}
#declare SNum = seed(8);
#declare Floor =
box {<0,0,0>, <9,8,9> pigment {Blue}}
#declare XPos=0;
#while(XPos<100)
#declare ZPos=0;
#while(ZPos<100)
#declare FCount=0;
#while(FCount<int(10*rand(SNum)))
object{Floor
translate <XPos,FCount*8,ZPos>
}
#declare FCount=FCount+1;
#end// while fcount
#declare ZPos=ZPos+10;
#end// while zpos
#declare XPos=XPos+10;
#end// while xpos
--
Christopher James Huff - Personal e-mail: chr### [at] yahoo com
TAG(Technical Assistance Group) e-mail: chr### [at] tag povray org
Web page: http://chrishuff.dhs.org/
Post a reply to this message
|
 |