3

I have vertex Coordinates of Left and Right side of the road (Shown as green and black points). My terrain is an array which corners of squares represent a different height value. I was drawing my road by just giving interpolated heights to my each vertex but that doesn't give correct result (road doesn't overlap with the terrain)

Question : Is there a way in opengl that I can draw this road properly? Or I have to calculate all the intersections(blue dots) manually and tessellate my road?

Sample Image

**Edit:**This is the result if I just give each vertex an interpolated height. As seen because of height map some parts remain under terrain.

enter image description here

Berke Cagkan Toptas
  • 1,034
  • 3
  • 21
  • 31
  • 1
    Yes, insert a point into your road wherever the terrain's slope changes (which is limited to those grid lines) and assign it the terrain's height at that point. Those blue dots should be on both sides of your road though. – Andon M. Coleman Mar 15 '15 at 01:29
  • 1
    [drapeitty drape drape drape](http://vterrain.org/Misc/draping.html). [also](http://vterrain.org/Implementation/zbuffer.html) – genpfault Mar 15 '15 at 04:18

2 Answers2

1

Here is an algorithm what I've done to achieve result :

For each road:

1) Generate Initial vertexes from road Lines
2) Find Intersections Vertically and add in order to the buffer   
3) Find Intersections Horizontally and add in order to the buffer
4) Find Intersections Diagonally and add in order to the buffer
5) Find texture coordinates for each vertex in buffer

After we have vertexes in order, I passed it to the Tesselator to draw final concave polygon. Aand voilà! enter image description here

Berke Cagkan Toptas
  • 1,034
  • 3
  • 21
  • 31
0

What you're probably going to want to do, for a very simple model of the road, is just calculate each square as two triangles, find which of the two triangles the road vertex is in, and then calculate its height as a point on the plane that triangle is on.

Depending on the complexity of the road with respect to the size of the grid, you could also just average the heights of the four corners and then use that as the height value for a pair of vertexes, and then do a quad between them (they have to be coplanar, like any quad, which is a problem unless you're using an additional triangle to model a turn in the road). Other than that, use two triangles.

Take a look at this also:

http://www.opentk.com/node/3179

djvs
  • 552
  • 2
  • 11