Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #13559 > unrolled thread

loops

Started byahso <ahso47@yahoo.com>
First post2012-01-24 06:25 -0800
Last post2012-01-27 11:55 -0800
Articles 8 — 4 participants

Back to article view | Back to comp.lang.c++


Contents

  loops ahso <ahso47@yahoo.com> - 2012-01-24 06:25 -0800
    Re: loops Victor Bazarov <v.bazarov@comcast.invalid> - 2012-01-24 10:53 -0500
    Re: loops Gareth Owen <gwowen@gmail.com> - 2012-01-25 06:09 +0000
    Re: loops "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-01-25 09:52 +0100
      Re: loops ahso <ahso47@yahoo.com> - 2012-01-25 01:38 -0800
        Re: loops "Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl> - 2012-01-25 11:20 +0100
          Re: loops ahso <ahso47@yahoo.com> - 2012-01-25 03:24 -0800
            Re: loops ahso <ahso47@yahoo.com> - 2012-01-27 11:55 -0800

#13559 — loops

Fromahso <ahso47@yahoo.com>
Date2012-01-24 06:25 -0800
Subjectloops
Message-ID<70285e31-38eb-47b4-8474-84db67c32fdc@k6g2000vbz.googlegroups.com>
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

[toc] | [next] | [standalone]


#13560

FromVictor Bazarov <v.bazarov@comcast.invalid>
Date2012-01-24 10:53 -0500
Message-ID<jfmk67$kr8$1@dont-email.me>
In reply to#13559
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

[toc] | [prev] | [next] | [standalone]


#13572

FromGareth Owen <gwowen@gmail.com>
Date2012-01-25 06:09 +0000
Message-ID<87ehuo8g9k.fsf@gmail.com>
In reply to#13559
ahso <ahso47@yahoo.com> writes:

> 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

// Although obviously y won't get up to 128 unless you use
// z <= 16384

for(unsigned z = 1;z <= 1386;++z){
  unsigned x = ((z-1) % 128) + 1;
  unsigned y = ((z-1) / 128) + 1;
  // Do what you need with x,y
  ...
}            

[toc] | [prev] | [next] | [standalone]


#13575

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2012-01-25 09:52 +0100
Message-ID<jfoft9$ht9$1@news.albasani.net>
In reply to#13559
"ahso"  wrote in message 
news:70285e31-38eb-47b4-8474-84db67c32fdc@k6g2000vbz.googlegroups.com...
>
>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

Maybe something like the following?

for (x=0; x<128; ++x) {
  for (y=0; y<128; ++y) {
    z=FeedInc(x,y);
    field(x,y)=z;
  }
} 

[toc] | [prev] | [next] | [standalone]


#13576

Fromahso <ahso47@yahoo.com>
Date2012-01-25 01:38 -0800
Message-ID<6c2308c6-01c9-49d8-8715-05526f91ad49@hs8g2000vbb.googlegroups.com>
In reply to#13575
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++;
	}

[toc] | [prev] | [next] | [standalone]


#13578

From"Fred Zwarts \(KVI\)" <F.Zwarts@KVI.nl>
Date2012-01-25 11:20 +0100
Message-ID<jfol1p$su9$1@news.albasani.net>
In reply to#13576
"ahso"  wrote in message 
news:6c2308c6-01c9-49d8-8715-05526f91ad49@hs8g2000vbb.googlegroups.com...
>
>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.

>}

[toc] | [prev] | [next] | [standalone]


#13580

Fromahso <ahso47@yahoo.com>
Date2012-01-25 03:24 -0800
Message-ID<94d1bbc1-940c-4a7e-bef7-ed020e63cbe1@hs8g2000vbb.googlegroups.com>
In reply to#13578
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

[toc] | [prev] | [next] | [standalone]


#13608

Fromahso <ahso47@yahoo.com>
Date2012-01-27 11:55 -0800
Message-ID<16532304-9295-4570-a2ca-6924b9b2f1dd@t7g2000vbg.googlegroups.com>
In reply to#13580
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web