XNA Creators Club Online
Page 1 of 1 (7 items)
Sort Posts: Previous Next

GeneratedGeometry Sample: Getting Height

Last post 3/29/2007 7:49 PM by Darkside. 6 replies.
  • 3/21/2007 4:02 AM

    GeneratedGeometry Sample: Getting Height

    Hello everyone,

    I'm in need of some guidance, can't figure out how I should go about implementing this. I use the TerrainProcessor from the GeneratedGeometry sample, to create a terrain from a height map. I would like to know if there's some way to get the height of the terrain at a particular point (i.e. get an Y value, given current X and Z), so that I can offset my camera in that point, and thus make it look like I'm "walking" on the terrain.

     

    Thanks!

    David Gouveia 

  • 3/21/2007 7:06 AM In reply to

    Re: GeneratedGeometry Sample: Getting Height

    The trick is getting the height out of the vertext data, best way is to employ a Quadtree or other tree structure.

     

    For a good example of a quadtree terrain with functions to resolve height at points in the terrain visit Clydes Quadtree project on codeplex

    hope this helps

    Darkside
    http://thegamedevspace.spaces.live.com/
  • 3/24/2007 7:59 AM In reply to

    Re: GeneratedGeometry Sample: Getting Height

    Hello!

    Thanks for answering. I was already aware of the Quadtree project from Codeplex. I don't have a complete understanding of how it works, but I am aware that it's one of the best ways to go about making big terrains; I know it divides the terrain in sectors, subdividing each node in 4 smaller nodes, and repeating that process for each new node, and at each time, only the nodes in view are drawn, increase performance greatly.

    However, my reasons for asking this question, was not to get the most effective terrain engine running (i.e. not trying to make a QuadTree) but trying, for educational puorposes, to experiment and learn with the samples provided on this site. I'm still somewhat of a begginer in 3D programming, and was impressed at how a custom processor (TerrainProcessor) enabled me to just, add a bmp to the project, and load it directly as a Model, without having to make terrain generation myself. But besides being able to render it on screen, I'm clueless about what else I can do with that model. In particular, I'm clueless about there being a way to, get the height at a particular point, with the way things are defined.


    In the GetHeight function from QuadTree project, the function had direct access to the heightdata of the terrain, and through a series of calculations, got the respective Y out of it.

    With the TerrainProcessor, in my understanding, what I get is just a Model object. How can I proceed to get the height information out of just that?

     

     Thanks!

    David Gouveia
     

  • 3/26/2007 4:56 AM In reply to

    Re: GeneratedGeometry Sample: Getting Height

    This is one of the times where my failing memory lets me down, I remember an article which had information about accessing the vertexbuffer of an XNA model.

    Problem, Can noot remember who did it and searches didn't find it, but.

    What I did find are several posts which talk about storing the vertexbuffer or heightmap data as part of the Model.tag property, this can then be access from within the runtime use of the terrain.

    One way to do this is in this post in the XNA forums, an old friend of mine leclerc9, suggests altering the content processor to add the vertex data to the Tag property.

    Also check out Riemers tutorials set which should also provide more info about interrogating Vertex/Hightmap data.

    But from the vertex data you should be able to use similar logic to resolve the height at a particular vertex.

    Hope this helps (and I'm still searching, damn)

    Darkside
    http://thegamedevspace.spaces.live.com/
  • 3/26/2007 5:47 AM In reply to

    Re: GeneratedGeometry Sample: Getting Height

    Always the way.  Here is another link to some info that should help.

    Ziggy ran a tutorial about using Vertex and Index data from a model and storing it for use

    Hope this helps!

     

    Darkside
    http://thegamedevspace.spaces.live.com/
  • 3/26/2007 12:14 PM In reply to

    Re: GeneratedGeometry Sample: Getting Height

    Thank you for your help!

     Haven't implemented it myself yet, but from reading the Ziggy article, I can see that's exactly what I needed. Along with the height data, I'll also add other relevant information to the Tag, like the terrain bumpyness and scale parameters, as well as terrain height, width, and starting x and z. That should be enough then to port the GetHeightAt algorithm from QuadTree to this project, and get what I wanted working.

     

    Thanks,

    David Gouveia 

     

  • 3/29/2007 7:49 PM In reply to

    Re: GeneratedGeometry Sample: Getting Height

    Glad to be of helpl!

    Let me know how you get on!

    Darkside
    http://thegamedevspace.spaces.live.com/
Page 1 of 1 (7 items) Previous Next