Sign in to follow this  

directx landscapes

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

i was wondering if anybody can help me. i want to load a landscape from an x file into my program, but i don't know how to find the coords of the grid. i need to know them so i can walk around and stuff. could anybody help me? i can give more info, but i don't know what i should give, so just tell me what i should give. i already had an object loaded from an x file, but i just want the landscape now and know where to find the coords

Share this post


Link to post
Share on other sites
To start out:

What do you load the x file into? A mesh?
Is the mesh rectangular (in the x-z plane ) or some non-rectangular shape?

Using a non-rectangular shape will be a bit more difficult than the method described below.

Assuming the x,z coordinates are the east/west-north/south locations (y is the terrain elevation at x,z coordinates):

If the mesh is fairly regular in shape, after you've loaded it in (presumably into something like a mesh from which you can access a vertex buffer), you can lock the vertex buffer, iterate through the buffer and calculate a bounding box by checking all the x and z coords and determining the minimum x & z values and the maximum x & z values. (You can check the min-max y values also if you don't know any of the terrain elevations) Unlock the buffer.

You now have a rectangle that surrounds the mesh.

You can now pick an eyept location somewhere inside that bounding rectangle. For instance, if the bounding rectangle is x from -100 to +100 and z from -200 to +500, pick x=0, z=0 as a starting location for your eyepoint.

To find the elevation at the eyept, determine the intersection of the mesh (say, with D3DXIntersect) with a direction ray of (0,-1,0) located at a position of ( eyept.x, 10000.0f, eyept.z ). The "10000.0f" is just some elevation that you know is above the mesh. Use something greater than the max Y value determined above if you need to.

Your location is now ( eyept.x, y_elev_at_xz, eyept.z ).

Is that getting you started in the right direction?

Share this post


Link to post
Share on other sites

This topic is 3591 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.

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