PDA

View Full Version : Curved/ Bent rectangles for track/road



billywizz7
01-30-2012, 08:58 AM
Hi i am attempting to create a game that is viewed from top down (birds eye view) and is 2D. The game is to have a track that a character will run around. I am kind of stuck on how to draw the track as it is going to be quite big and have lots of curves/ bends.

The way I am thinking of drawing the track is in sections sort of like a scalectrics track and then fitting them together. For example straight rectanglur peices and curved peices at different angles.

Please could some people let me know how they would approach this and also the best way to draw curved or bent filled rectangles.

All help much appreciated.

billywizz7
01-30-2012, 12:32 PM
Could i do this with triangle strips?

tonyo_au
01-30-2012, 02:41 PM
OpenGL does not support curves per say, you have to approximate them with triangles. If you are trying to do scaletrix type race track it is a lot easier because the curves are all parts of a circle so you can calculate the triangle corners as simply points on 2 concentric circle. You can render this with a triangle strip. You smooth the curve by having more triangles.

Have a look at code for drawing Bezier curves for more general curves.

Once you get that code to work, you could look at tesselating a quad patch which is a little more tricky but it is bascially the same code moved to the gpu.

hope that helps