Jump to content
  • Advertisement

Archived

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

Jiia

Help Slacker with Terrain Height?

This topic is 5215 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

Do I need to use line intersections for something as simple as getting the walking height of the terrain? My terrain is divided into 32.0 x 32.0 sized tiles. The tiles are pretty simple, but can contain several faces in them. None of the faces would overlap on the Y axis. All I want to do is get the Y height of a specific X,Z point in the mesh. Any help or a point in the right direction is appreciated. [edited by - Jiia on May 10, 2004 1:43:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
I suppose you can calculate it by using some linear interpolation between the y-coordinates of the edges of the tiles.

Share this post


Link to post
Share on other sites
Well I can''t say specifically how to do it without the source, but first you need to find which triangle in the terrain the point (x,z) is over. Then simply find the plane equation for that triangle which will be y = F(x,z) [to derive plane equations I usually just do something like y = (height of origin of triangle) + (slope along x-axis)*x + (slope along z-axis)*z ].

Anyways forgive me if that doesn''t make sense, but in any case I can always elaborate more.

Share this post


Link to post
Share on other sites
Assuming that your faces are triangles, I've solved this problem not too long ago using this method:

1) Identify the triangle in your mesh which your X,Z coordinates correspond to.

2) Find the surface normal vector of this triangle. If you haven't precalculated normals for your terrain, then just make two vectors (p2-p1) and (p3-p1) where p1,p2,p3 are the triangle's vertices. Take their cross product to get your normal vector. After that, make this vector's length 1 (normalize it).

3) Solve for the constant D. D = -DotProduct(p1, N) where N is the normal vector from step 2. We now have a plane equation Ax + By + Cz + D = 0 where (A,B,C) is your normal vector and (x, y, z) is any point in the plane (we used p1), and D we just solved for.

4) Back to the initial problem: you know the X,Z but don't know the Y (height) of the terrain point. Given the above equation, solve for it, giving you your height:

height = Y = -(AX + CZ + D) / B

where (A,B,C) is your normal vector, and X/Z are your query coordinates.

[edited by - Schmerm on May 10, 2004 8:20:50 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!