finding ground height ?

Started by
3 comments, last by dmitriyd 14 years, 10 months ago
I have my world with vertices (V[0], V[1] , V[2]) and respective normal (normal), my player's position is (position), can anyone describe me an algoritm to "find height" from player postition to the ground ? I have used plane distance ecuation: Ax+Bx+Cx+D = 0, but I just confussed with that... _O_ | / \ --- | | h | | ---------------------
Advertisement
Your plane equation is wrong. Should be:

Ax + By + Cz + D = 0

Do you know how to compute the plane equation for your ground plane?

So, to find the height, let's say your player is at some point, say, <45, 100, 115>. To find the "height" above the ground, do the following. I am assuming that your "up" direction is positive Z.

1) Compute the ground elevation, the ground's Z value, at the player's xy location. Solving algebraically:

z_ground_below_player = -(D +Ax +By) / C;

You know everything on the right-hand-side, so can solve for z

2) The "height" above terrain is:

height_above_ground = z_player - z_ground_below_player

Or, in this case:

height_above_ground = 115 + ((D + Ax + By) / C);

Hope that helps!
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net

I dont need to compute the ground normals to do that ?
How do I compute A ,B C and D of plane ecuation? Can you help me?
Actually, for the plane equation, you do need a normal. So, the A, B, and C are the plane normal = (A,B,C). If the ground is horizontal and positive Z is "up", then (A,B,C) = (0,0,1). If the ground is sloped, then you have to have the ground defined in some way that you know the slope.

To find D, you have to know a point that is on the plane. So, if, say, positive Z is up and the ground is at z = 15, then the point (0,0,15) is on the plane and so:

Ax+By+Cz+D = 0 = 0x+0y+1z+D = z+D

So, then z+D = 0 and D = -z, or

D = -15

That gives you a final equation of::

0x+0y+1z-15 = 0, or z = 15 for all xy. This makes sense for a horizontal ground plane, that z is the same no matter what xy you are at. If you have a sloped ground then (A,B,C) will be different and it will be a bit more interesting.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Thank you very much, here is my mail: programar3d@yahoo.com.ar

This topic is closed to new replies.

Advertisement