Archived

This topic is now archived and is closed to further replies.

Terrain Im stuck please help

This topic is 5871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites