Velocity Reviews > C++ > loops

# loops

ahso
Guest
Posts: n/a

 01-24-2012
Hi
i get z values by feeding/incrementing x and y. So i have for ex.
1-1386 z values and the question how to output those to a field of
128x128? (x/y)
Many thanks

Victor Bazarov
Guest
Posts: n/a

 01-24-2012
On 1/24/2012 9:25 AM, ahso wrote:
> i get z values by feeding/incrementing x and y. So i have for ex.
> 1-1386 z values and the question how to output those to a field of
> 128x128? (x/y)

Haven't you asked something like that before?

A solution might be two nested loops, one for x, the other for y (or
vice versa). Inside the inner loop feed the x and y values to your
whatever gives you back the z, and immediately output. I am not sure
what "a field" is, but if it's something similar to "number of rows with
a certain number of positions in each row", then make sure your "output"
(whatever that is) goes to the next "row" before incrementing the outer
loop.

And if you happen to have a C++ *language* question, go ahead and ask it.

V
--

ahso
Guest
Posts: n/a

 01-25-2012
Hmm I'm trying as below without success. I need to move/copy the
struct values into terrainMap arrays to draw later in OpenGL.
Many thanks indeed
Michael

for( int xx=0; xx < 16384; xx++ ){

Buffr[xx]->dLaenge = dWeltLat;
Buffr[xx]->dBreite = dWeltLon;
Buffr[xx]->dHoehe = dWeltAlt;

px = ((int(dWeltLat)-1) % 12 + 1;
pz = ((int(dWeltAlt-1)) / 12 + 1;

terrainMap[xx][py][0] = px;//dWeltLat; //float(x)*MAP_SCALE/
1000-0.2;
terrainMap[xx][py][1] = dWeltAlt/10; //(float)dWeltAlt/1000; //
altitude
terrainMap[xx][py][2] = pz;//dWeltAlt; //-float(z)*MAP_SCALE/
1000-2; //backwards
py++;
}

Fred Zwarts \(KVI\)
Guest
Posts: n/a

 01-25-2012
"ahso" wrote in message
news:(E-Mail Removed)...
>
>Hmm I'm trying as below without success. I need to move/copy the
>struct values into terrainMap arrays to draw later in OpenGL.
>Many thanks indeed
>Michael
>
>for( int xx=0; xx < 16384; xx++ ){
>
>Buffr[xx]->dLaenge = dWeltLat;
>Buffr[xx]->dBreite = dWeltLon;
>Buffr[xx]->dHoehe = dWeltAlt;

Are dWeltLat, dWeltLon, dWeltAlt constant for the loop, or are they
calculated from xx?

>
> px = ((int(dWeltLat)-1) % 12 + 1;
> pz = ((int(dWeltAlt-1)) / 12 + 1;

I don't understand this calculation.
If dWeltLat and dWeltAlt are constant for the loop, then px and pz are
constant too.
Why don't you calculate py from dWeltLon?
What is the value of py for the first iteration?

>
> terrainMap[xx][py][0] = px;//dWeltLat; //float(x)*MAP_SCALE/1000-0.2;
> terrainMap[xx][py][1] = dWeltAlt/10; //(float)dWeltAlt/1000;
> //altitude
> terrainMap[xx][py][2] = pz;//dWeltAlt; //-float(z)*MAP_SCALE/1000-2;
> //backwards

Has the comment any relation with the code?

> py++;

if py starts at 0, then py equals xx, right?
So, why don't you write terrainMap[xx][xx] instead of terainMap[xx][py]
(or terrainMap[xx][xx%256] if py is an unsigned byte?)
this would make the code more clear.

>}

ahso
Guest
Posts: n/a

 01-25-2012
Hi Fred
no lots of faults but it should only take the elevation dWeltAlt
from the struct into the array float terrainMap[128]128][3]. The
struct got that z value from a terrain/altitude probe function loop
(xx<12 by incrementing x and y which are offsets to the current
Many thanks
Michael

ahso
Guest
Posts: n/a

 01-27-2012
for(loopz=0 ; loopz< MapReso; loopz++ ){
same for x...
function returning z WeltAlt
terrainMap[x][loopz][0] = x;
terrainMap[x][loopz][1] = dWeltAlt/100; //altitude
terrainMap[x][loopz][2] = -loopz;

I only need to get dWeltAlt into terrainMap[128][128][3] but
something is wrong....any ideas? Basically I'm following:
http://www.codeproject.com/Articles/...n-Introduction
but without success.
Thanks