loops

A

ahso

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
 
V

Victor Bazarov

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
 
A

ahso

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) % 128) + 1;
pz = ((int(dWeltAlt-1)) / 128) + 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++;
}
 
F

Fred Zwarts \(KVI\)

"ahso" wrote in message
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) % 128) + 1;
pz = ((int(dWeltAlt-1)) / 128) + 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?

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.
 
A

ahso

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<128) by incrementing x and y which are offsets to the current
heading and position.
Many thanks
Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top