Forums

Full Version: How to get the track tangent angle and middle line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Trying to develop an AI driver by following Berniew's robot tutorial for TORCS. Currently my code spawns an opponent car, shift to 1st gear and apply some gas. The car is moving forward slow and happy, but in a straight line.

Now comes to the steering part, and i'm lost.

How can i get the tangent angle of the track at the car's current position, and the middle line at that position?
This is really cool that you're working on this, it's something we really need. I'm not sure about how to get the track information from the game. TORCS has a nice Robots API that provides this information to the programmer writing AI, but we have no such API.

TORCS tracks are built sort of like this. First they start as an XML file defining road segments and such. From this a 3D model of the road is generated. Then the scenery is manually added to the model. When the track is loaded, the XML is used to define the track's road segments, and this information is given to the robots. Then the track model is loaded, which the player and robots drive on.

The way VDrift tracks are built is different. We start with a fully modeled track, with scenery and surrounding objects and everything. Then we open it in our simple track editor and trace the track itself. This is saved so the game knows which parts of the model are the track and should be smooth. The game loads the track definition and interprets it as a bezier patch. Then the model is loaded much like in TORCS.

So the big difference is that in VDrift, we do not have this track definition XML file. It may be possible however to get the same information from the bezier curves which define the track. However I don't know if or exactly how this would be done...

Joe wrote the track code and could probably enlighten us on this issue. Joe, what do you think? Would it be possible to provide a TORCS-like robots API from the track data we already have? Or would we need something more?
If you provide me with a list of functions that you would want to be able to develop an AI, I can work on adding them. I should be able to manage to provide most of them, with a bit of math.
After studying the code, i think i might be able to do the following. Please help to validate whether it is workable.

1. Looks to me track is just a bunch of connected bezier patches. Using TRACK::GetLapSequence (Car::GetSector()) I should be able to get the current patch the car is on. And TRACK::GetLapSequence (Car::GetSector()+1) should give me the next patch.

<edit>Ok. My understanding of GetLapSequence() is wrong. I need a way to get the patch the car is currently on, and the next patch on the road. Can you provide such functions, Joe?

2. I can get the center position of the next patch using BEZIER::SurfCoord(0.5,0.5).

3. I can get the current position and orientation of the car chassis by doing Car::chassis().position(), and Car::chassis().orientation().

<edit> One more question here, does 1st column of the orientation matrix contains a vector pointing in the car's forward direction?

4. The steering goal of the AI driver will be to steer the car towards the center of the next patch. So the desired orientation should be along the vector formed by (center of next patch - current chasis position).

5. The steering command can be calculated base on the angle difference between current orientation and desired orientation.
Joe, Berniw's tutorial on making TORCS robots is the best resource on the robots API I know of. It's here: http://www.berniw.org/

If this is not sufficient then we could go to the TORCS code for more info, I'm sure.