Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > loops

Reply
Thread Tools

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
 
Reply With Quote
 
 
 
 
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
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
 
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++;
}
 
Reply With Quote
 
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.

>}


 
Reply With Quote
 
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
heading and position.
Many thanks
Michael
 
Reply With Quote
 
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple For Loops? pinod01@sympatico.ca VHDL 1 02-22-2006 03:10 PM
Etherchannel disabled = spanning tree loops... traust Cisco 0 02-21-2006 05:34 PM
Loops with loops using html-template Me Perl Misc 2 01-12-2006 05:07 PM
Perl loops should use break, not last Jeremy Morton Perl 1 01-30-2005 10:50 PM
to many FOR loops? eismaus4 VHDL 1 04-27-2004 02:54 PM



Advertisments