nested for/while loops

A

ahso

Hi
a function returns Z (height) after giving X and Y location. How
would those two for (or while?) loops look like if I need all z points
in a rectangle.
Many thanks
Michael
 
R

ralph

Hi
a function returns Z (height) after giving X and Y location. How
would those two for (or while?) loops look like if I need all z points
in a rectangle.
Many thanks
Michael

I'm probably missing something as that question doesn't make any
sense.

Even assuming each "X" and "Y" describes a point. Everything else
would be simple linear addition or substraction.

Need more info.

-ralph
 
N

Nick Keighley

Hi
 a function returns Z (height) after giving X and Y location. How
would those two for (or while?) loops look like if I need all z points
in a rectangle.
Many thanks
Michael

you need to work out how X,Y gets turned into Z
 
A

ahso

Ok it's a little more complicated:
---
Probes the terrain. Pass in the XYZ coordinate of the probe point...
Other fields are filled in if we hit terrain, and a probe result
* is returned.
----
So i give that function x,y,z coordinates and if it hits terrain I get
a result. Now I see why i only get a few points to draw as it hits
around the viewer but loses ground contact in the mountains etc.
I want to get the z (ground contact) within a 128x128 square around my
position, for a heightmap. (color z in different colors)
Many thanks indeed as I'm stuck...
Regards Michael
 
A

ahso

Getting closer, now I have lines from top left to bottom right:

for( int x=0; x< 16384; x++ ){
draw x,y,z

I need also a y for loop?
Thanks
Michael
 
V

Victor Bazarov

Getting closer, now I have lines from top left to bottom right:

for( int x=0; x< 16384; x++ ){
draw x,y,z

I need also a y for loop?
Thanks
Michael

Michael,

You need to sit down and write your algorithm with a pencil on a piece
of paper. "I have lines from top left to bottom right" - what does that
mean? We have no idea. It's not a description of an algorithm.
Perhaps you need to think about the algorithm for a while. Perhaps you
should also look into some *formality* in your activities. So far your
posts indicate that your work is very hap-hazard. Step back from
programming for an hour and think what actions you would take if you
were the computer and you needed to accomplish whatever goal you're
setting for it.

To make tea, what do you need? You need a cup, water source, dry tea
(loose or in a bag) and a way to heat the water to the boiling point.
Water source is in the kitchen (or the bathroom). So, as part of the
algorithm for making tea you need to ensure you're in one of those
locations. To boil water you need some energy source. A microwave
would do (make sure it's plugged into an electrical outlet). And so on.
You write down preconditions, then you write down your actions. It
becomes the algorithm for accomplishing your goal.

Same thing with making calculations. Or drawing a shape. Or
controlling a nuclear reactor. You need the algorithm first, THEN you
can put it in terms of the language you've chosen to implement it.

V
 
W

Werner

Getting closer, now I have lines from top left to bottom right:

        for( int x=0; x< 16384; x++ ){
draw x,y,z

I need also a y for loop?
Thanks
Michael

Michael,

What you have given us is not code... It
is not even psuedo code.

Function...

Output [Appropriate Name] (All necessary input parameters).

is already a start...

Kind regards,

Werner
 
N

Nick Keighley

Look for yourself, your comments are all sick...

smart move. Ask for advice then criticise it...

you said

****
So i give that function x,y,z coordinates and if it hits terrain I
get
a result. Now I see why i only get a few points to draw as it hits
around the viewer but loses ground contact in the mountains etc.
I want to get the z (ground contact) within a 128x128 square around
my
position, for a heightmap. (color z in different colors)
Many thanks indeed as I'm stuck...
***

you really do nedd to sit down and think about the problem. What is a
"rectangle"? What is "terrain". What is a "result"?

also: viewer, ground contact, mountains, heightmap, color...

you add new terminology faster tahn you generate sensible requirements

to me this sounds like you might be taking a "slice" though the
terrain. In general this will yield a series of closed curves. And
then finding the point on one of these closed curves that is nearest
to your X,Y position. but I'm doing a *lot* of guessing.
 
A

ahso

now I did a vector[x/y][rgb]
x or y and the color seems ok now how to draw this?

for( int laty=0; laty< Terrain_Size; laty++ ){
for( int lonx=0; lonx< Terrain_Size; lonx++ ){
draw in opengl colored points
}
}
doesn't obviously work. how should those for loops look like?
Thanks
 
F

Fred Zwarts \(KVI\)

"ahso" wrote in message
now I did a vector[x/y][rgb]
x or y and the color seems ok now how to draw this?

for( int laty=0; laty< Terrain_Size; laty++ ){
for( int lonx=0; lonx< Terrain_Size; lonx++ ){
draw in opengl colored points
}
}
doesn't obviously work. how should those for loops look like?
Thanks

I don't understand your "obviously". Can you explain why it doesn't work?
 
V

Victor Bazarov

now I did a vector[x/y][rgb]
x or y and the color seems ok now how to draw this?

for( int laty=0; laty< Terrain_Size; laty++ ){
for( int lonx=0; lonx< Terrain_Size; lonx++ ){
draw in opengl colored points
}
}
doesn't obviously work.

"Obviously"?... Well, yes, the

draw in opengl colored points

is not C++ code (unless those are names of some macros that, when
substituted, produce compilable C++ code). Try replacing it with, say,

printf("point: %d %d\n", laty, lonx);

and see if it "works" then.
how should those for loops look like?

The loops look OK, *given* certain assumptions. But my assumptions can
be totally different from yours. State yours, and we can verify.

Also visit: http://catb.org/~esr/faqs/smart-questions.html and
http://www.parashift.com/c++-faq-lite/how-to-post.html

V
 

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,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top