Implemented road & road mesh generator.
This commit is contained in:
@ -55,7 +55,7 @@ namespace TransportGame.Generator
|
||||
const float DefaultBranchProbability = 0.2f;
|
||||
const float DefaultSegmentLength = 24;
|
||||
const float SteepnessLimit = 10;
|
||||
const float SlopeLimit = (float)Math.PI / 6;
|
||||
const float SlopeLimit = (float)Math.PI / 7;
|
||||
const float RoadSegmentAngleLimit = (float)Math.PI / 4;
|
||||
const float RoadSnapDistance = 19;
|
||||
const float MinNodeDistance = 12;
|
||||
@ -154,7 +154,7 @@ namespace TransportGame.Generator
|
||||
private IEnumerable<RoadGeneratorSegment> GlobalGoals(RoadSegment segment)
|
||||
{
|
||||
Vector2 prevPos = segment.Terminal2.Position;
|
||||
Vector2 dir = (segment.Terminal2.Position - segment.Terminal1.Position).Normalized;
|
||||
Vector2 dir = segment.Direction;
|
||||
bool highway = (segment.LanesTo1 >= 3);
|
||||
bool highwayBranched = false;
|
||||
|
||||
@ -258,18 +258,14 @@ namespace TransportGame.Generator
|
||||
}
|
||||
|
||||
// Filter & sort the segments by distance
|
||||
segmentIds = segmentIds.Distinct().OrderBy(id =>
|
||||
{
|
||||
var seg = map.RoadNetwork.ArticulationSegments[id];
|
||||
var line = new LineSegment(seg.Terminal1.Position, seg.Terminal2.Position);
|
||||
return LineSegment.Distance(line, segment.Terminal2Pos);
|
||||
});
|
||||
segmentIds = segmentIds.Distinct().OrderBy(id =>
|
||||
LineSegment.Distance(map.RoadNetwork.ArticulationSegments[id].AsLineSegment(), segment.Terminal2Pos));
|
||||
|
||||
foreach (var segmentId in segmentIds)
|
||||
{
|
||||
var other = map.RoadNetwork.ArticulationSegments[segmentId];
|
||||
var line1 = new LineSegment(segment.Terminal1.Position, segment.Terminal2Pos);
|
||||
var line2 = new LineSegment(other.Terminal1.Position, other.Terminal2.Position);
|
||||
var line2 = other.AsLineSegment();
|
||||
|
||||
Vector2? inters = LineSegment.Intersect(line1, line2);
|
||||
|
||||
@ -294,7 +290,7 @@ namespace TransportGame.Generator
|
||||
// Check angle between intersecting segments
|
||||
foreach (var intersSeg in other.Terminal2.ArticulationSegments)
|
||||
{
|
||||
float cos = Vector2.Dot((line1.P1 - line1.P0).Normalized, (intersSeg.Terminal2.Position - intersSeg.Terminal1.Position).Normalized);
|
||||
float cos = Vector2.Dot(line1.Direction, intersSeg.Direction);
|
||||
if (Math.Abs(Math.Acos(cos)) < RoadSegmentAngleLimit)
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user