Jump to content

  • Log In with Google      Sign In   
  • Create Account


Putting Models on Terrain Surface


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 03 October 2011 - 09:53 AM

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:
Terrain Test Model.jpg


Here is the Terrain Textured:
Solid Pattern Terrain.jpg

Here is the Terrain Rendered in OpenGL:
TerrainTestSuccessful.jpg

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

Translate House on Terrain.jpg
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?

Sponsor:

#2 Erik Rufelt   Crossbones+   -  Reputation: 3058

Like
1Likes
Like

Posted 03 October 2011 - 11:16 AM

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?


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.

#3 zacaj   Members   -  Reputation: 643

Like
1Likes
Like

Posted 03 October 2011 - 03:44 PM

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

#4 xXDreamXx   Members   -  Reputation: 114

Like
0Likes
Like

Posted 03 October 2011 - 06:09 PM

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?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS