Advertisement

Getting terrain height properly

Started by March 04, 2002 01:43 PM
11 comments, last by Lupson 22 years, 11 months ago
I think I understand what is going on now.
Problem 1:
Your STEP_SIZE needs to be a power of 2 (unless 12 is a typo). What is happening now, I believe, is that truncation which occurs when PointX is divided by STEP_SIZE sometimes results in nearAX and nearAY being assigned to the wrong value.
Problem 2:
Also rather than nearAX+1, nearAY+1 being used to find the other corners of the current quad, it should read nearAX+STEP_SIZE, nearAY+STEP_SIZE. With those changes, the code I originally posted should work.

Edited by - Chromebender on March 6, 2002 4:04:43 PM
Thanks again for helping out Chromebender.

Are you sure I'll should divide nearAX and nearAY with STEP_SIZE? I mean, then their values will become much smaller and that's opposite our wishes, wasn't it? If I tamper with them at the current state of code, the camera is located far beneath the ground. Not touching nearAX or nearAY but trying your other stuff it follows the ground as it should, apart from the bumpiness issue. First I set the STEP_SIZE to 16 (2^4) and then I changed your code to:
/* set x,y,z coords for nearest point 'B' */
nearPointB[0] = (float) nearAX + STEP_SIZE;
nearPointB[1] = (float) nearAY + STEP_SIZE;
nearPointB[2] = g_HeightMap[(nearAX+STEP_SIZE) + (nearAY+STEP_SIZE)*MAP_SIZE];

/* set x,y,z coords for nearest point 'C' */
nearPointC[0] = (float) nearAX;
nearPointC[1] = (float) nearAY + STEP_SIZE;
nearPointC[2] = g_HeightMap[(nearAX) + (nearAY+STEP_SIZE)*MAP_SIZE];

That code should move points B & C 16 "steps" in their respective directions. Still bumpy Im afraid. (And a strange bug; whenever STEP_SIZE is set to an power of 2 (4,8,16,32...) one of the textures doesn't load properly....all other step sizes work fine, but that's probably unrelated to this..)

My final goal with the program is to make a simple little game where you drive a little tank over the terrain. The cam is meant to be positioned above and behind the tank so I guess the bumpy issue will have to be solved before continuing with the rest. It won't do if the tank jumps up and down all the time when driving around. Then of course I'll have to calculate a lot of new stuff like positioning it so it "fits" the ground and so on, but learning is fun so...

If you or anyone else want to see the bump-bug in action or try to squash the it by yourselves (I'd be eternally grateful) I've posted the data files and .cpp & .exe on my website:
Just the essentials (.cpp .exe and data):
http://w3.adb.gu.se/~s99luppe/openGL/Lesson35/Lesson35.zip 574Kb
Essentials + VC++6.0 project files etc.
http://w3.adb.gu.se/~s99luppe/openGL/Lesson35/height.zip 826Kb

Best regards Lupson

Edited by - Lupson on March 7, 2002 11:22:29 AM
Advertisement
You''re right, I think I wrote that at some late hour of the morning and my thinking went something like this:
1. need to get the x coord of a vertex close to my X,Z value.
2. well, I want to use a vertex that is actually rendered on the screen, so that''s (int) pointX - (pointX%STEP_SIZE)
3. for some reason I decided pointX - (pointX%STEP_SIZE) == pointX/STEP_SIZE
4. actually that should have been (pointX/STEP_SIZE)*STEP_SIZE, but anyway it''s probably faster just to use nearAX = pointX-(pointX%STEP_SIZE); nearAZ = pointZ - (pointZ%STEP_SIZE); etc.
That just makes sure the near vertex used as the ''anchor'' for the coordinate of the quad surrounding your camera occurs on a STEP_SIZE boundary, so it matches a vertex on the screen.

This topic is closed to new replies.

Advertisement