The online racing simulator
C++ / X-Y-Z Positioning (application/tutorial)
(17 posts, started )
C++ / X-Y-Z Positioning (application/tutorial)
SMALL UPDATE (2008-08-29):

The CInsim library was replaced with a newer version.


X-Y-Z POSITIONING v0.1

This is another application/tutorial I've written in basic C/C++ using my "CInsim" library. This time I have updated the library to support InSim TCP+UDP connection. The previous application I made can be found here: http://www.lfsforum.net/showthread.php?t=46643

All the source code is provided, of course, as well as a code::blocks project file

This application retrieves MCI packets every second and shows to each player his coordinates and the closest car at any moment while they are on track.

It provides a lot of information through the console so it's nice if you want to know what is happening and what packets are being received/what actions are being taken.


QUICK START

Just run the executable in the zip with 3 arguments: IP PORT ADMIN_PASS
(The PThreads dll must be in the same directory)

I recommend to create a Windows link and add those arguments in the properties.

Connect to the server and a welcome message should appear. You can be in the server when the application starts, but be warned that the first thing it does is end the current race/session.

Start running!


PS: I'd like these small apps I'm doing to be linked somewhere in the "My first InSim Application" thread or something like that.
Attached files
X-Y-Z Positioning v0.1.zip - 175.2 KB - 787 views
Quote from MaKaKaZo :PS: I'd like these small apps I'm doing to be linked somewhere in the "My first InSim Application" thread or something like that.

The thread is open, so there's nothing stopping you from posting in it?
Quote from the_angry_angel :The thread is open, so there's nothing stopping you from posting in it?

I'm very respectful and always ask for permission before intruding into a sticky I'll post both apps later.
Quote from MaKaKaZo :I'm very respectful and always ask for permission before intruding into a sticky I'll post both apps later.

There's no need to if it's something I've written or stickied - please do feel free just to post away

Edit: Incidentally, good work MaKaKaZo
Kinda OT, but that Code::Blocks program seems to be very nice. Seems more versatile than Visual Studio. Nice find
Quote from dawesdust_12 :Kinda OT, but that Code::Blocks program seems to be very nice. Seems more versatile than Visual Studio. Nice find

What does OT mean?

Btw, I found Code::Blocks here in this forum, in TAA's C InSim tutorial.
OT = Off Topic.

Hmm, I never noticed it then, but... I'm glad I did now
got to try the code::blocks again then, I'll take a look at this app while I am at it.
If you are going to use code::blocks I recommend using the nightly build rather than the old release. It does mean that its a bit more of a pita to setup (quite frankly no one here should struggle, however), but I do find it's better overall.
Hello Makakazo, i checked your code, since im working into similar code at the moment, so thx to show your inside brain

i add you a link to a part of the code i created to pre detect a Collision or dangerous driving for other.

I show you the code, cause i saw you have no Grid system, mean you Update and Check Pos from All Current Player...

Since a race track has many Node, we can use this to create a virtual grid with player inside, so no need to update all player but just one into same node or closer node.

into my code: Add() is called by PlayerJoin Race, Update() When i receive a MCI and Remove when player leave race.

Im just showing you the node2Grid system , is not complex, but since you don't have into your code, is maybe a good idea to add it to, for saving cpu.

So take this as a sugestion only... and thx again for showing your work.

http://pastebin.ca/1190435
Greenseed I've checked your code and I like your idea of using nodes, but in my example I just want to provide physical comparison relative to all cars present, not only the ones that are near you. So, if there are just two cars I don't care if they are really far away one from the other, I want the name of the closest one even if it's very far.

About the nodes idea... do all nodes have a similar length? For a in race usable application it would be nice to know.

I've seen in your code that your findNodeCars function repeats work all the time from previousNodeCount to nextNodeCount. I mean, it checks all cars at node previousNodeCount, then all cars again in previousNodeCount+1... and so on until nextNodeCount. Maybe you should do some change and do a simple loop that checks all cars just once, and if their node is within previousNodeCount to nextNodeCount then they're added to the List<CarMotion> carIds.

PS: I don't know C# but I think what I said makes sense
Agree about your optimization idea... thx...

Im just allways thinking like i have 2500 player to check... have to remember MAX is about 32 ... so fun

About Node length i really don't know, but there is a lot of node on a track, so probaly yes they are all divised by a static lenght, i let you do this test, since i really can't thought of something usefull with this... Maybe if you tell me more , you will attract my attention...

i just completed the code i showed you, into Drive_LFSS project, proud to tell that my Back Pre Collision detection from Bad Ass Driver is working, not yet perfect but ho! shit! Player without brake will found that one not so amusing as before

P.S. hope the "shit!" word is not a ofend! im trying to be better into english, i notised "shit" and "****" are very important verb (juts trying to add little joke!)
Quote from Greenseed :About Node length i really don't know, but there is a lot of node on a track, so probaly yes they are all divised by a static lenght, i let you do this test, since i really can't thought of something usefull with this... Maybe if you tell me more , you will attract my attention...

Path nodes are approximately as long as 0.2 seconds of time when driving a car.

That is because the original path nodes are created by driving a car smoothly around the track, then connecting the resulting path as a loop. A path node is created 5 times per second, with the position and direction of the car.

But that depends which car was used, so that's why the 0.2 seconds is just a rough guide. Anyway this means the path nodes are more spread out at higher speed sections of track.
Quote from Scawen :Path nodes are approximately as long as 0.2 seconds of time when driving a car.

That is because the original path nodes are created by driving a car smoothly around the track, then connecting the resulting path as a loop. A path node is created 5 times per second, with the position and direction of the car.

But that depends which car was used, so that's why the 0.2 seconds is just a rough guide. Anyway this means the path nodes are more spread out at higher speed sections of track.

That's cool, in that case they can be used as a distance factor when you consider "regular racing". Maybe I'll use it for an InSim application that would be used during our destrcution derby-like team matches where wrong way driving, ramming and driving off track to avoid incoming cars is a must.

By the way... regarding nodes and our crazy game something just came up to me. We've been playing this game for a while now, and as I say wrong way driving is an essential technique. We play on AS2 and this is what happens:

While some people are driving to win the 3 laps race, others constantly go to pits and start directly exiting the pits in the wrong way (we use /cruise yes to avoid wrong way messages). When this happens in the first lap I think that the drivers that start from the pits to wrong way appear in the positions list as 1st, 2nd, etc. like they are leading the race, when they actually aren't as they went to pits and started wrong way.

I think this might be because everyone is noted as being on their first lap, but the guys going wrong way are in nodes higher than the ones that are racing for the win, so the game thinks they are leading. Can anyone confirm if that would be the reason?

I'm interested in this because in my InSim app I'd need to know who's the first driver of each team to make a GPS-like device that would tell team members how far (in nodes) they are to the other team leader, because in the minimap you see many "yellow cars" but you are never sure of who is the one you are aiming at. If you can't tell who's first in the first lap I'd start the tracking on the second, that's no problem, but I'd prefer it to start in the second.
Not sure i follow you... but if you wan to know if a driver is turning clockWise or not on a track, can be done with checking the y tangen angle from car x,y to 0,0 if you got : 51,52,53,54 mean i got clockwise if you got 54,53,52,51 mean counter clockWise. all track, Star/Stop are connected so work allways good, it just a way, i thought of some other.

Is that what you are looking for?
Quote from Greenseed :Not sure i follow you... but if you wan to know if a driver is turning clockWise or not on a track, can be done with checking the y tangen angle from car x,y to 0,0 if you got : 51,52,53,54 mean i got clockwise if you got 54,53,52,51 mean counter clockWise. all track, Star/Stop are connected so work allways good, it just a way, i thought of some other.

Is that what you are looking for?

Easier than that would be to check if the nodes the car is in are increasing or decreasing, wouldn't it?
ho yeah! was just trying to expose other solution...

Node calculation is much faster then tangen offcourse

But me i work with Angle allready, so into my code i think i will use this... but in fact i won't too , since i wan to build track_template data, my system is ready, but still empty Data

exemple: node[2] has this data: Neutral Angle -123.4 , Speed Max for a Curve, Script Trigger, ...

Neutral angle is offcourse the ~Trajectory Angle if your Strait in the middle of the track.

This check will be the one i can think of has the fastest and more flexible system, since tracjectory angle is allready calculated by the LFSS and much place so people add custom script trigger and keep the search for it limited to the same node.

I read very ofent ppl wan to put virtual Square or Circle to trigger script or action, for me all this is part of the same system.

C++ / X-Y-Z Positioning (application/tutorial)
(17 posts, started )
FGED GREDG RDFGDR GSFDG