opengl terrain
can someone PLEASE give me some sample source code of theirs to get smooth movement over a heightmap based terrain ?
I have been up all night and cant get smooth motion. It is all jerky and bumpy.
IF you have a working terrain with smooth motion then PLEASE let me have a peek. I have searched this sight up and down and tried all kinds of stuff i have found on here without success.
I do have the terrain rendered with no problem. But I guess just calculating the height is a bitch.
"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
Pick up the boog "OpenGL Game Programming" by a couple of the guys here. The end project in the book is a full blown (yet simple) first person shooter using a heightmap for terrain. Your local library probly has a copy. I highly recommend that book!
Worth it''s weight in twinkies!
Landsknecht
Worth it''s weight in twinkies!
Landsknecht
Sounds like your routine to get heightdata is not proper.
Are you first of all converting your current position to the correct cell location in the mesh? Secondly are you doing the correct interpolations of the 4 adjacent heights to calculate the correct in-cell height?
The interpolation can be a bit tricky, if nonplanar cells exist as in my code. You have to use the nearest 3 nodes, and in the way that your renderer will draw the cell tris, i.e. w. regard to the diagonal.
My recent PhysicZ app contest entry on this site has a mesh to run around on, but God help you in loooking at my code!
zin
zintel.com - 3d graphics & more or less
Are you first of all converting your current position to the correct cell location in the mesh? Secondly are you doing the correct interpolations of the 4 adjacent heights to calculate the correct in-cell height?
The interpolation can be a bit tricky, if nonplanar cells exist as in my code. You have to use the nearest 3 nodes, and in the way that your renderer will draw the cell tris, i.e. w. regard to the diagonal.
My recent PhysicZ app contest entry on this site has a mesh to run around on, but God help you in loooking at my code!
zin
zintel.com - 3d graphics & more or less
I used this when I needed to get the yposition on my height map.
This may not be the fastest way, but it worked perfectly for me.
First off, I broke up my height map into sectors, so that you only need to test against a few of the triangles at most. So given an x and z position, I tested to see if that is in the triangle, using the 360 degrees thing.
I then have make a line at that x and z position and solve for t (the difference between the passed y position and the new y position) using the plane equation of the triangle.
Here's the function I used, I don't comment so it may be a litle confusing:
[edited by - atcdevil on March 31, 2002 1:11:57 PM]
[edited by - atcdevil on March 31, 2002 1:14:43 PM]
This may not be the fastest way, but it worked perfectly for me.
First off, I broke up my height map into sectors, so that you only need to test against a few of the triangles at most. So given an x and z position, I tested to see if that is in the triangle, using the 360 degrees thing.
I then have make a line at that x and z position and solve for t (the difference between the passed y position and the new y position) using the plane equation of the triangle.
Here's the function I used, I don't comment so it may be a litle confusing:
GLfloat World::GetYPos(GLfloat x, GLfloat y, GLfloat z, Sector *sctr) { double yposition = -69.0f; if(x < 0.0 || x >= 100.0 || z < 0.0 || z >= 100.0) return y; int i, j, k; double angle, a, b, c, d; for(i = 0; i < sctr->vtris.size(); i++) { angle = 0.0f; for(j = 0; j < 3; j++) { if(j < 2) k = j+1; else k = 0; a = level.vertices[sctr->vtris[i]->indices[j]].v[0] - x; b = level.vertices[sctr->vtris[i]->indices[j]].v[2] - z; c = level.vertices[sctr->vtris[i]->indices[k]].v[0] - x; d = level.vertices[sctr->vtris[i]->indices[k]].v[2] - z; double length1 = sqrt((a*a) + (b*b)), length2 = sqrt((c*c) + (d*d)); if(length1 < 0.000001 || length2 < 0.000001) { angle = TWOPI; break; } double cosangle = ((a*c) + (b*d)) / (length1*length2); angle += acos(cosangle); } if(angle <= TWOPI + 0.000001 && angle >= TWOPI - 0.000001) { //Point is in this triangle Vert *v1 = &level.vertices[sctr->vtris[i]->indices[0]], *v2 = &sctr->vtris[i]->normal; double dot = (v1->v[0]*v2->v[0]) + (v1->v[1]*v2->v[1]) + (v1->v[2]*v2->v[2]); double left = (v2->v[0]*x) + (v2->v[1]*y) + (v2->v[2]*z); if(v2->v[1] == 0 ) return yposition; double t = (left - dot) / v2->v[1]; yposition = y - t; break; } } return yposition;}
[edited by - atcdevil on March 31, 2002 1:11:57 PM]
[edited by - atcdevil on March 31, 2002 1:14:43 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement