// todo: make smarter, should use driveways of buildings of void paths private void updateApproachRoute(Sequence <PathDescription> pathSequence) { Vector3 start, startTangent, end, endTangent; var startTransform = CurrentTransform; start = startTransform.MultiplyPoint3x4(Vector3.zero); startTangent = startTransform.MultiplyVector(Vector3.forward); var pathDesc = pathSequence[0]; var path = pathDesc.Path; path.LoftPath.SnapTo(start, out end, out var distance); var approachProgress = path.GetDistanceFromLoftPath(distance); var transform = path.GetTransform(approachProgress); pathSequence[0] = new PathDescription(path, approachProgress / path.GetLength(), 1); endTangent = -transform.MultiplyVector(Vector3.forward); var loft = new BiArcLoftPath(start, startTangent, end, endTangent); var approachPath = new AgentAIPath(loft); var descr = new PathDescription(Path: approachPath, Start: 0, End: 1); pathSequence.Insert(0, descr); }
public void TestBiArc() { var biArc = new BiArcLoftPath(new Vector3(-1, 0, -1), new Vector3(0, 0, -1), new Vector3(1, 0, 1), new Vector3(0, 0, -1)); var points = string.Join(" ", Enumerable.Range(0, 100).Select(i => i / 100.0f).Select(i => biArc.GetTransformedPoint(i * biArc.Length, Vector3.zero)) .Select(t => "(" + t.x.ToString(CultureInfo.InvariantCulture) + "," + t.z.ToString(CultureInfo.InvariantCulture) + ")")); var point1 = new Vector3(-1, 0, 0); var point2 = new Vector3(1, 0, 0); biArc.SnapTo(point1, out var snapped1, out float distance1); biArc.SnapTo(point2, out var snapped2, out float distance2); var sqrt2inv = 0.70710678818f; //var inc = biArc.Length / 100; //var items = new StringBuilder(); //for (float i = 0; i <= biArc.Length; i += inc) //{ // var v = biArc.GetTransform(i).MultiplyPoint3x4(Vector3.zero); // items.AppendLine($"{v.x.ToString(CultureInfo.InvariantCulture)}, {v.z.ToString(CultureInfo.InvariantCulture)}"); //} var pointExpected1 = new Vector3(-sqrt2inv, 0, sqrt2inv - 1); Assert.AreEqual(pointExpected1.Round(0.0001f), snapped1.Round(0.0001f)); var pointExpected2 = new Vector3(sqrt2inv, 0, 1 - sqrt2inv); Assert.AreEqual(pointExpected2.Round(0.0001f), snapped2.Round(0.0001f)); }
// todo: make smarter, should use driveways of buildings instead of void paths private void updateDepartRoute(Sequence <PathDescription> pathSequence) { Vector3 start, startTangent, end, endTangent; var index = pathSequence.Count - 1; var pathDesc = pathSequence[index]; var path = pathDesc.Path; path.LoftPath.SnapTo(Destination, out start, out var distance); var departProgress = path.GetDistanceFromLoftPath(distance); var endProgress = departProgress / path.GetLength(); pathSequence[index] = new PathDescription(path, 0, endProgress); end = Destination; startTangent = -path.GetTransform(departProgress).MultiplyVector(Vector3.forward); endTangent = (start - end).normalized; var loft = new BiArcLoftPath(start, startTangent, end, endTangent); var departPath = new AgentAIPath(loft); var desc = new PathDescription(departPath, 0, 1); pathSequence.Add(desc); }
public void TestJShape() { var tangentStart = new Vector3(0, 0, 1); var tangentEnd = new Vector3(1, 0, 0); var start = new Vector3(0, 0, 2); var end = new Vector3(-1, 0, 0); var a = new BiArcLoftPath(start, tangentStart, end, tangentEnd); var points = string.Join(" ", Enumerable.Range(0, 100).Select(i => i / 100.0f).Select(i => a.GetTransformedPoint(i * a.Length, Vector3.zero)) .Select(t => "(" + t.x.ToString(CultureInfo.InvariantCulture) + "," + t.z.ToString(CultureInfo.InvariantCulture) + ")")); }
public void TestSShape() { // data from actual bogus case: var tangentStart = new Vector3(1, 0, 0); // fromString3("AACAvw== AAAAgA== AAAAgA=="); var tangentEnd = new Vector3(1, 0, 0); // fromString3("AACAPw== AAAAgA== AAAAgA=="); var start = new Vector3(0, 0, 2); // fromString3("AMAuRA== AAAAAA== VVXtQg==") - new Vector3(699,0,116.6667f); var end = new Vector3(0, 0, -2); // fromString3("AMAuRA== AAAAAA== VVXlQg==") - new Vector3(699, 0, 116.6667f); var a = new BiArcLoftPath(start, tangentStart, end, tangentEnd); var p1 = a.GetTransformedPoint(a.Length / 4, Vector3.zero); var p2 = a.GetTransformedPoint(a.Length / 2, Vector3.zero); var p3 = a.GetTransformedPoint(a.Length / 4 * 3, Vector3.zero); var points = string.Join(" ", Enumerable.Range(0, 100).Select(i => i / 100.0f).Select(i => a.GetTransformedPoint(i * a.Length, Vector3.zero)) .Select(t => "(" + t.x.ToString(CultureInfo.InvariantCulture) + "," + t.z.ToString(CultureInfo.InvariantCulture) + ")")); Assert.AreEqual(new Vector3(-1, 0, 1).Round(precision), p1.Round(precision)); Assert.AreEqual(new Vector3(0, 0, 0).Round(precision), p2.Round(precision)); Assert.AreEqual(new Vector3(1, 0, -1).Round(precision), p3.Round(precision)); }
public NodeAIPath[] Create(AINode node) { var nodeRadius = 10; var segments = node.Segments.Select(t => t.Segment).OfType <AISegment>().Where(t => t.Start != null && t.End != null).ToArray(); var nodePaths = new List <NodeAIPath>(); for (int iA = 1; iA < segments.Length; iA++) { for (int iB = 0; iB < iA; iB++) { var segA = segments[iA]; var loftA = segA.LoftPath; var segB = segments[iB]; var loftB = segB.LoftPath; var isAStart = segA.End?.Node == node; var isBStart = segB.Start?.Node == node; var offsetA = isAStart ? nodeRadius : loftA.Length - nodeRadius; var offsetB = isBStart ? nodeRadius : loftB.Length - nodeRadius; var headingA = isAStart ? segA.Start.GetHeading() : segB.End.GetHeading(); var headingB = isBStart ? segB.Start.GetHeading() : segB.End.GetHeading(); var pointA = loftA.GetTransformedPoint(offsetA, Vector3.zero); var pointB = loftB.GetTransformedPoint(offsetB, Vector3.zero); var loft = new BiArcLoftPath(pointA, headingA, pointB, headingB); //nodePaths.Add() } } return(nodePaths.ToArray()); }
public void TestReverseCShape() { // data from actual bogus case: var tangentStart = new Vector3(1, 0, 0); var tangentEnd = new Vector3(-1, 0, 0); var start = new Vector3(0, 0, 2); var end = new Vector3(0, 0, -2); var a = new BiArcLoftPath(start, tangentStart, end, tangentEnd); var p1 = a.GetTransformedPoint(a.Length / 4, Vector3.zero); var p2 = a.GetTransformedPoint(a.Length / 2, Vector3.zero); var p3 = a.GetTransformedPoint(a.Length / 4 * 3, Vector3.zero); var points = string.Join(" ", Enumerable.Range(0, 100).Select(i => i / 100.0f).Select(i => a.GetTransformedPoint(i * a.Length, Vector3.zero)) .Select(t => "(" + t.x.ToString(CultureInfo.InvariantCulture) + "," + t.z.ToString(CultureInfo.InvariantCulture) + ")")); var s2 = Mathf.Sqrt(2); Assert.AreEqual(new Vector3(-s2, 0, s2).Round(precision), p1.Round(precision)); Assert.AreEqual(new Vector3(-2, 0, 0).Round(precision), p2.Round(precision)); Assert.AreEqual(new Vector3(-s2, 0, -s2).Round(precision), p3.Round(precision)); }
public AgentAIPath(BiArcLoftPath loft) { this.LoftPath = loft; }
private void IsValid(BiArcLoftPath value) { IsValid(value.Arc1); IsValid(value.Arc2); }