Sign in to follow this  
dmitriyd

finding ground height ?

Recommended Posts

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 | | ---------------------

Share this post


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

Share this post


Link to post
Share on other sites

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?

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this