From 6182137aa4b131501c7d64e83b27188a15e5c9d3 Mon Sep 17 00:00:00 2001
From: unknown <john.schihada@hotmail.com>
Date: Thu, 23 Jan 2020 21:18:30 +0100
Subject: [PATCH] Adjusted Angle-Preview to consider possible angles first

---
 Assets/InteractionEngine/ShinyThings.cs | 30 +++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/Assets/InteractionEngine/ShinyThings.cs b/Assets/InteractionEngine/ShinyThings.cs
index 1d7c05a0..e02dfe19 100644
--- a/Assets/InteractionEngine/ShinyThings.cs
+++ b/Assets/InteractionEngine/ShinyThings.cs
@@ -162,13 +162,35 @@ public void ActivateCurveDrawing(Fact startFact)
 
     public void UpdateCurveDrawing(Vector3 currentPosition)
     {
-        
-        //Determine the Start-Point
-        Vector3 startPoint = angleMiddlePoint + curveRadius * (currentPosition - angleMiddlePoint).normalized;
+
+        //Find the nearest of all potential third points
+        PointFact nearestPoint = null;
+        foreach (Fact fact in Facts) {
+            if (fact is PointFact && fact.Id != curveDrawingStartLine.Pid1 && fact.Id != curveDrawingStartLine.Pid2 && nearestPoint == null)
+                nearestPoint = (PointFact)fact;
+            else if (fact is PointFact && fact.Id != curveDrawingStartLine.Pid1 && fact.Id != curveDrawingStartLine.Pid2 && (nearestPoint.Point - currentPosition).magnitude > (((PointFact)fact).Point - currentPosition).magnitude)
+                nearestPoint = (PointFact)fact;
+        }
+
+        Vector3 startPoint = new Vector3(0,0,0);
+
+        if (nearestPoint != null)
+        {
+            Vector3 planePoint = Vector3.ProjectOnPlane(currentPosition, Vector3.Cross((nearestPoint.Point-angleMiddlePoint), (curveEndPoint-angleMiddlePoint)));
+
+            //Determine the Start-Point for the nearest third-point
+            startPoint = angleMiddlePoint + curveRadius * (planePoint - angleMiddlePoint).normalized;
+        }
+        else
+        {
+            //Determine the Start-Point
+            startPoint = angleMiddlePoint + curveRadius * (currentPosition - angleMiddlePoint).normalized;
+        }
+
         //Determine the Center of Start-Point and End-Point 
         Vector3 tempCenterPoint = Vector3.Lerp(startPoint, curveEndPoint, 0.5f);
         Vector3 curveMiddlePoint = angleMiddlePoint + curveRadius * (tempCenterPoint - angleMiddlePoint).normalized;
-        
+
         linePositions = new List<Vector3>();
         //Start: AngleMiddlePoint -> FirstPoint of Curve
         linePositions.Add(((PointFact)Facts.Find(x => x.Id == curveDrawingStartLine.Pid2)).Point);
-- 
GitLab