-1

I want to generate roads for race-car game, for example

(x = 0, y = 0), (x = 0, y = 5), (x = 0, y = 10) ... (x = 0, y = 100) its vertical lane.

(x = 0, y = 0), (x = 5, y = 0), (x = 10, y = 0) its horizontal lane.

I need examples of big lane (500 points for example) with turns and bands. It's very hard manually generate every band and smooth turn of the road. If any generator/examples/algorithm to do it simpler? I want to have a set of points forming a line of the road (the points are sequentially connected, one after another)

Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
Naduxa
  • 55
  • 1
  • 11
  • 1
    Do you have to worry about the roads intersecting themselves? i.e. does the player only ever view the roads from a driving perspective and not a map? If they don't see a map they most likely won't notice if the road actually loops back and intersects itself, as long as you are only rendering a certain amount ahead of and behind their current position – samgak Aug 03 '17 at 12:08
  • Now I need to set of lanes. Every lanes - dataset of points – Naduxa Aug 03 '17 at 13:33

2 Answers2

2

Your points definition can stay relatively short. If it's only a question of smooth rendering then you may use something like bezier surface to render smoothly curved surfaces from points definition.

There are also variations to curved surfaces, e.g. NURBS. Check out this opengl tutorial to render NURBS surface (of course it depends on what you use; which framework etc. if it's only about pure algorithm then bezier curves are still valid though).

Ivan Sivak
  • 7,178
  • 3
  • 36
  • 42
  • now is it ready tool/instrument to use it? I do not need very much accuracy, Now it me for test my racecar behavior and manually generated it's very awful – Naduxa Aug 03 '17 at 10:37
  • it will be nice from visualise form (draw manually for example one lane) from visualized lined to 2-d points format convert, really is it not service for this? – Naduxa Aug 03 '17 at 10:40
  • 1
    @Naduxa You need to be more specific here. It's not really a subject of a tool or instrument as your question is about algorithms. – Ivan Sivak Aug 03 '17 at 11:11
2

Use interpolation for this see

So each straight "lane" will be just 2 points no matter the size. On top of that you can create your path by:

  1. manual edit

    you can edit easily with mouse something like this: follow mouse and smooth the points by FIR filter (averaging).

  2. random path

    I would chose either turtle like graphics where you start with some position and direction. Add point and then randomly move where forward move would have biggest probability and turns have smaller probability.

    Or another option would be start with preset polygon path and adding random noise to it ... This is better for loops like paths. see:

    If you want something looking realistic then create random terrain height map like:

    Then chose random start at some reasonable elevation and just follow elevation (so the road will have +/- the same elevation until some dead end hit (hill ...) then decide to go up or down until "flat" zone hit again and follow that elevation again. It is similar to this:

    Terrain approach has the benefit that can use it as mesh for your game.

    And finally you can mix the approaches together ...

Spektre
  • 49,595
  • 11
  • 110
  • 380