1. ## Simple driving game

After many unsuccessful attempts at doing a simple perspective racing game I have finally figured out the algo.

Essentially you have a road in 3D vertexes. You only need as many vertexes to make the road look like it stretches into the distance.

The vertex z components never change for these and neither do the y. Only the x component changes.

This essentially splits the road into horizontal sections.

For any of you that have done the fire effect or any kind of texture cascading you will understand this. First you need to setup a loop that transfers one segment of road offset on x to the next segment. Basically you are handing the offset value off to the next segment.

The offset value is to simulate curves. After all if we are in 3D and all vertexes have the same x value....the road will be perfectly straight. The only thing that would cause a bend is if one vertex was offset on x some distance from the previous vertex x. And since everything scrolls from max z to min z (for forward movement) all you have to do is change the first vertex or the most distant one's offset. This will be transferred all the way down the chain.

So how to you store the road data?

Simple:
• Neutral offset on x means you will have a straight road.
• Negative offset means the road is curving to the left, or recovering from a right turn
• Positive offset means the road is curving to the right, or recovering from a left turn
So in your editor for the game you simply allow the user to add in curves. All you must do is decide on a sampling size and find out how much each vertex is offset from the center of the curve.

So one section of road might look like this in memory.

0 --> we start here on straight road
0 --> straight
0 --> straight
0 --> straight
0 --> straight
.1 --> road is curving to the right a bit
.4 --> road is curving more to the right
.7 --> road is prob at right side of screen
-.4 --> road is coming back to the left
-.1 --> road is still moving left
0 --> road is straight again
0
0
0
0

This would be a straight away with a sharp curve to the right followed by another straightaway.

You will move through the track data at player.speed/some_constant.

Code:
```Arraypos+=(player.speed)/some_constant;

{
}```

I had to share that with the board because it was so simple it eluded me for years.

I will try to post a simple demo here soon of like Indy 500 track or something.

Of course with this method you won't be able to turn around....for that you need pure 3D.

If you wanted to add hills....simply change the y offset of the top vertex and transfer that y offset down the chain. The hill will gradually come to you. Don't alter the top vertex y though or you will get weird looking stuff. Only alter (1+top)->end of list.

Also one caveat of the algo is that you must move the same amount in the opposite direction to come out of a hill or curve. This will return all vertexes to their original positions. If you continue to move away from center...the road will go off screen and cause major issues.

2. Thankyou for watching another dissertation by Bubba. Any questions may be forwared to him at this address:

http://cboard.cprogramming.com/showt...059#post379059

Maybe we should just start posting Bubba's dissertations on the Tutorials page.

3. Or maybe he could write some tutorials and submit them to this site? Hmmm?

4. Actually its not a dissertation, it's an algo I'm going to try. Maybe it will help those trying to make a racing game but don't know where to start.

I just don't have a demo yet so no screenshots.

But we do need tutorials on effects and algos like these: Fire, Water, Particle Effects, Billboards, clouds, etc., etc.

All of this is extremely useful in game dev. Perhaps some of us could contribute to the tutorial board on these topics.

5. What sort of racing game are we talking about here? Outrun, or something hardware accelerated?

6. This is for a simple 2D racing game that appears to be 3D. It is a first person driving algo but it does not allow you to turn around and go the opposite direction.

So yes, I think Outrun would probably fit into this category. With good graphics and hardware acceleration I think that someone could come up with a very good arcade racer using this algo.

Of course if you want full 3D then you will have to design a 3D engine to handle it.

Just wanted to show how it can be done.

7. Working on a new algo. This one does not work as planned.

I wonder how they did it old school like on the Atari 2600. There is no way they were doing pure 3D on that 26K system.

Stumped.