Terrain Im stuck please help

Started by
6 comments, last by boldyman 22 years, 5 months ago
Hi I am trying for 2 months now , to get the height of a terrain at ANY x/z position. But i can''t get it to work or work correctly. I used the getheight method from opengl game programming book but this gives a bumppie effect. And if the hill is to high i can get the y pos and i walk right through the hill. Can someone PLEASE explain to me how i can get the ypos at any point on the terrain. (Or even better some code or pseudo code). Or use lesson 35 to explain it to me. Some details of the method i use, almost the same as in ogl game programming: I give up the mapx mapx and mapscale. I read the terrain from a heightmap. It is stored in a terraindata[mapx][mapz][3]. Calculating the height points: terraindata[x][z][0]= float(x)*mapscale terraindata[x][z][1]= (float)heightmap[z*mapz+x)*3] terraindata[x][z][2]= -float(z)*mapscale The vertices are drawn in this order 0---->1 / / 2---->3 And render it using GL_TRIANLE_STRIP Thanks Boldyman
Advertisement
hi pls explain what you really want.
You want some type of collision detection thats is as you move through the terrain your camera y-position is automatically adjusted to keep you above the terrain ?

manni
manni
if that is the problem then do the following
Make a function which takes the x-pos & z-pos of the camera and returns the height of the terrain at that point. use that height (plus someoffset) as y-pos of the camera. If you got it tell me you are always wellcome.
Good luck bye

manni
manni
I have done that. The function getheight from opengl game programming does the same, but this does not work properly.
If i walk on low ground it works, if i walk up a mountain it
doesn''t. Halfway up the mountain i fall through the mountain.

One other thing : The demo in the book uses glulookat, i use
glrotate en gltranslate to calulate camera and my position. Could this be the problem ?
Does the getheight function do interpolating? If not, that may be the cause of your bumpiness.
Yeah, for example if you have a 2 points 10,14,10 and 10,20,10, and you check points 14,and 20, then the area between those is where you fall off... so you need to take that into account. It also depends on how many tesselations you do, and so on.
I also used the GetHeight(..) from the book and had problems.
I played with the direction of the corners and it worked!!
I don''t have the code with me, but try to play with the corners of the rectangel u''r on.

good luck
Just write your own function to return the height of the terrain directly below the camera. When loading your terrain, generate and store the normal for all the polygons of the terrain. Now every frame you can calculate exactly which triangle the camera is above, cast a ray downward a set distance, and check to see if the two end points of the ray are on opposite sides of the triangle. If they are, then the camera will collide with the terrain, and you can set its height to the height of the terrain (or a bit above if you wish). If it doesnt, let the camera "fall" as to simulate gravity. Itll be a poor simulation of gravity, but it adds to the feel of the engine a bit.
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack

This topic is closed to new replies.

Advertisement