The online racing simulator
Ways to calculate positions with OutSim
Hi folks,

does anyone have an idea on how to calculate the position with the data provided from the OutSim API?

I'm trying to figure out the position of each player in DiRT2 programmatically and would be interested if someone already has made a similar (successfull) attempt.

Thanks,
SpeeDaa
Ok, I recorded the OutSimPack.Pos.X / Y data for about 2 minutes while racing on a map and saved them to a file. I then used the numbers in an Excel sheet and created a diagram which showed me the actual map I was racing before.



Now, I'm not really a genius in math and always kind of need a while to figure those things out. So do one of you already have an idea how to retrieve the position from each player with the x, y coordinates? Any suitable algorithms in mind?

Of course I could now calucate the positions having the average coordinates of the track, but I'm trying to look for an unified way / algorithm which would allow me to get those infos without having to come up with extra calucations for each map.

Thanks!
Quote from SpeeDaa :how to retrieve the position from each player with the x, y coordinates? Any suitable algorithms in mind?

I don't know if DiRT2 is different from LFS, but LFS' OutSim implementation only gives you the information of the currently viewed vehicle. Under LFS you'd want to be using the car tracking stuff - thats part of InSim and gives you information about all the vehicles.

Regarding your question I'm not understanding - if its a translation problem then I apologise, but what exactly are you trying to do? The x,y,z coordinates are the exact position of the vehicle. You can't really get much more specific than that. Are you trying to plot each vehicle's position on a map, or are you trying to map the other vehicles relative to your vehicle (i.e. building a spotter application)?

If its a case of plotting positions on a map, you can either translate from the given coordinates to those you can use on top of a static image, or you can plot them as you have been doing, with the coordinates you get straight from the API, and make it so that each track knows how to center/rotate itself beneath the graphing.

If you're trying to figure out the relative position (i.e. for a spotter program) of other people to you, then it's a case of calculating the distances and then using trigonometry to work out the direction.
Hi the_angry_angel,

Sorry, I forgot to mention that each client in the network (talking about multiplayer) would actually collect those coordinates for their vehicle and send it to a server which compares all of the collected information. So just assume that I have all coordinates from each single player.

I'm actually "just" trying to get the ranking positions (e.g. those which are listed in the upper right box while racing). It doesn't even have to be via OutSim, just need those ranks...

Thanks again for your answer!
Mm, if the OutSim packets are the only data you can get from DiRT2 then I'd probably try it something like this:

* For each track define the start-finish line coordinates. Also setup a set of points at a specific interval on the track - say every few meters - and give each point it's own id number. You can use these to determine the vehicles current position on the track.

* Store the current x,y location and heading for each vehicle, the number of laps and the point they've just passed. Everytime they pass the start-finish line increment the number of laps.

* To display the positions in a table it's just a case of ordering the list of players by the number of laps and which point they've just driven past. For any 2 vehicles on the same point you can compare their coordinates and heading vectors to determine whos in front.

It does mean that you'll need a fair bit of information about each track.

There are a couple of other solutions to the same problem. For example you could instead split the track into sections and record their rough direction of travel for each section. For example on a hairpin you might have 3 sections, and on a straight you'd have one. You could then record how many laps they've driven and what section of the track they're in. For each section you just compare the vehicles coordinates in context of the expected heading to determine the positions. That's probably less accurate, but it could well be quicker for long tracks that get people spread out very quickly. For tracks where people stick together it could be a lot slower as you'll be frequently checking coordinates rather than points.

Hopefully that's given you a few ideas?
Hey there,

Wow, now that's what I call support. You totally gave me some good ideas! I'll work something out and post it when it's finished.

Thanks a lot!
SpeeDaa
Hi again,

I'm currently working on checkpoints with a specified radius.
I would like to include the heading data I get from the OutSimPack, but since its area is something between -3,1 and 3,1 I can't really convert it into degrees (0 - 360), which would make things a lot easier. Any ideas on how to proceed?

Edit:
As I mentioned before, math is cool but I don't really have a hand for it
1 degree = 0.0174532925
That says it all, eh?

SpeeDaa
Are you trying to go for point in circle collision to see if the car hit a radius? Or are you trying to find the angle between the direction a check point is and the direction the car is heading.

I do assume you know a bit about vectors here, but as follows;


bool PointInCircle(const Vector3 &vPointPos, const Vector &vCirclePos, const float fCircleRadius)
{
Vector d = vCirclePos - vPointPos;
float length = d.Magnitude(); //Or Length()
if (fLength > (fCircleRadius * fCircleRadius)
return true;
return false;
}

and also the dot product of two vectors gives you the cosine of the angle between the vectors;


bool NearDirection(const Vector &vCarDirection, const Vector &vCheckDirection)
{
float fDot = DotProduct(vCarDirection, vCheckDirection);
if (fDot > 0.98f) //,98 is a made up number that you will play with
return true;
return false;

//Other cases that might be useful to know if you don't already.
if (fDot > 0.0f) //We are somewhere within 180 degrees of the check direction
return false;
if (IsZero(fDot)) //IsZero checks a range; return true is (abs(fDot) < 0.0001)
return false; //Heading perpendicular, 90 degree angle fron check direction.
if (fDot < 0.0f)
return false; //Heading backwards, against check direction
}

All my code is untested and I may be off on something, although I believe its good.
Hope it helps.

FGED GREDG RDFGDR GSFDG