loops

Discussion in 'C++' started by ahso, Jan 24, 2012.

  1. ahso

    ahso Guest

    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
     
    ahso, Jan 24, 2012
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Jan 24, 2012
    #2
    1. Advertising

  3. ahso

    ahso Guest

    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++;
    }
     
    ahso, Jan 25, 2012
    #3
  4. "ahso" wrote in message
    news:...
    >
    >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?

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

    >}
     
    Fred Zwarts \(KVI\), Jan 25, 2012
    #4
  5. ahso

    ahso Guest

    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
     
    ahso, Jan 25, 2012
    #5
  6. ahso

    ahso Guest

    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/14154/OpenGL-Terrain-Generation-An-Introduction
    but without success.
    Thanks
     
    ahso, Jan 27, 2012
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eismaus4

    to many FOR loops?

    eismaus4, Apr 27, 2004, in forum: VHDL
    Replies:
    1
    Views:
    690
  2. Jeremy Morton

    Perl loops should use break, not last

    Jeremy Morton, Jan 29, 2005, in forum: Perl
    Replies:
    1
    Views:
    5,148
    Big and Blue
    Jan 30, 2005
  3. Multiple For Loops?

    , Feb 22, 2006, in forum: VHDL
    Replies:
    1
    Views:
    473
    john Doef
    Feb 22, 2006
  4. =?Utf-8?B?Um9iIE8nQ29w?=

    RedirectFromLoginPage and loops

    =?Utf-8?B?Um9iIE8nQ29w?=, Oct 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    412
    =?Utf-8?B?Um9iIE8nQ29w?=
    Oct 25, 2004
  5. Me
    Replies:
    2
    Views:
    247
Loading...

Share This Page