-
Notifications
You must be signed in to change notification settings - Fork 49
Mapping Information
Now that there's a program that can take SCS' data and build a real map out of it, the following is being documented.
Each road has a "start node" and an "end node". A large road consists of several small roads, connected via these nodes. Based on the nodes' start and end position, we can calculate the actual curvature of the road via the following logic (TsMap:216-229):
var sx = startNode.X;
var sz = startNode.Z;
var ex = endNode.X;
var ez = endNode.Z;
var radius = Math.Sqrt(Math.Pow(sx - ex, 2) + Math.Pow(sz - ez, 2));
var tanSx = Math.Cos(-(Math.PI * 0.5f - startNode.Rotation)) * radius;
var tanEx = Math.Cos(-(Math.PI * 0.5f - endNode.Rotation)) * radius;
var tanSz = Math.Sin(-(Math.PI * 0.5f - startNode.Rotation)) * radius;
var tanEz = Math.Sin(-(Math.PI * 0.5f - endNode.Rotation)) * radius;
for (var i = 0; i < 8; i++)
{
var s = i / (float)(8 - 1);
var x = (float)TsRoadLook.Hermite(s, sx, ex, tanSx, tanEx);
var z = (float)TsRoadLook.Hermite(s, sz, ez, tanSz, tanEz);
newPoints.Add(new PointF(x, z));
}
The red lines indicate where each node in the road is.
Prefabs are a bit different as you cannot simply calculate the curvature. Currently, TsMap uses the AI traffic lanes to determine how the prefab is built.
Roads in OSM are built by creating a way
, which is a collection of nodes
(each node
has a latitude and longitude... or in ETS2/ATS' case, its coordinates). Unlike ETS2/ATS' roads, OSM's roads do not have curvature between nodes; they are straight lines
Random thought on prefabs with OSM: Perhaps we can just take each "point" in the prefab as an OSM node?
edoaxyz/ts-map apparently has a navigation sample using Dijkstra's algorithm. Additionally, nlhans also has an A* implementation over at https://github.com/nlhans/ets2-map/blob/master/Ets2Map/Ets2Map/Ets2NavigationRoute.cs#L39