Jump to content
  • Advertisement
Sign in to follow this  
dreamslayerx

OpenGL Putting Models on Terrain Surface

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

Hi guys. I am new to OpenGL. I am trying to figure out a way to make my models be on my terrain. I am kind of confused on how to approach the situation. My terrain is actually an .obj file, so it is easy to apply textures to it. I am wondering should I store every point in the terrain, and try to find the relevant coordinates that are in the same area as my object, then translate it? Or is there an easier way to calculate the top of my terrain, and make some type of collision detection so that the no geometry can go below the terrain?

Here is a picture of the terrain's geometry and its UV map:
[attachment=5655:Terrain Test Model.jpg]


Here is the Terrain Textured:
[attachment=5656:Solid Pattern Terrain.jpg]

Here is the Terrain Rendered in OpenGL:
[attachment=5657:TerrainTestSuccessful.jpg]

Here is a house on the terrain, but it is not automatically calculated by the program:

[attachment=5658:Translate House on Terrain.jpg]
[attachment=5659:Translate House on Terrain2.jpg]

My goal is develop something to automatically place the models directly on the surface of the terrain. How would I go about doing that anyone?

Share this post


Link to post
Share on other sites
Advertisement

I am wondering should I store every point in the terrain, and try to find the relevant coordinates that are in the same area as my object, then translate it?


Yes that's usually a good idea.


Or is there an easier way to calculate the top of my terrain, and make some type of collision detection so that the no geometry can go below the terrain?[/quote]

You could simply take a ray that goes from above the model straight down through the terrain, and collision-check it against the model triangles. It's probably more difficult, unless you use a physics library. A physics library can automatically handle those things for you and accurately simulate your dynamic objects on the terrain.

For placing houses etc. I would definitely start with keeping the terrain as a height-map in memory and get the coordinates from that, like you suggested. For a regular terrain it should be enough to simply store the height in a 2D image, as the other directions are evenly spaced.

Share this post


Link to post
Share on other sites
As long as you can choose just one point on your model to be its 'bottom,' using the ray casting technique is actually really simple to write. Just look up 'point in triangle test' and test your triangles top down, interpolating the heights of the three corners of the triangle you find

Share this post


Link to post
Share on other sites
So basically this is what I am getting from you guys. Its a good idea to store my terrain data. I will store my terrain data as x, y, z coordinates, where y is my height. Then say if I have a model. My model data is read in as x, y, z , but I only check one point on my model which is the bottom most point of the model as the bottom surface. So I can have a check that checks my x and z coordinates, if those coordinates are the same as the house or model have it translate to the surface of the terrain,

i.e.
gltranslatef(0.0, distance between model and terrain, 0.0);

But the question is what is ray, and how can I make use of it to check to see where the terrain and model x and z coordinates intersect? I am unfimilar with rays, what are they exactly?
How would I go about writing the conditional statement to tell the program that the model needs to be translated?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!