Jump to content
  • Advertisement
Sign in to follow this  

Tips for programming a road building tool

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


I am fairly new to game programming and I am trying to build a simple system where I can construct a road on a plane. I would like to implement a road building tool similar to Cities XL's road tool where you can click and drag the mouse to create curved roads on a terrain.

At this point I know how to get the coordinates of the on the plane according to the mouse click by casting a ray and gathering the result. My first thought is to collect the coordinates and create an array of road models and place them between the mouse clicks, I just don't know how to implement the curve. I googled various curve algorithms but I don't know how to implement them and I don't know if this is the best approach to solving the problem. I'm just looking for advise on how to approach this. Thanks in advance.

Share this post

Link to post
Share on other sites
Curves are definetely one way of implementing the road system. One way is to use Catmull-Rom splines. Here is the function I use:

Vector CatmullRomSpline(const Vector &P1,const Vector &P2,const Vector &P3,const Vector &P4,float t)
float t2 = t * t;
float t3 = t * t2;

return ((P2 * 2.0f) + (-P1 + P3) * t + (P1 * 2.0f - P2 * 5.0f + P3 * 4.0f - P4) * t2 + (-P1 + P2 * 3.0f - P3 * 3.0f + P4) * t3) * 0.5f;

It requires four position vectors along the path (p1-p4) and an interpolator between 0.0 - 1.0. The curve is calculated between the points P2 and P3. This function allows you to calculate a smooth curve for your road. After you have created the desired curve, you may offset the curve by the half road width along the normals of the curve.


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!