From b057f217cf2d691a056ac41710fb95214d6e512a Mon Sep 17 00:00:00 2001
From: Richard Marcus <richard.marcus@fau.de>
Date: Fri, 10 Jan 2020 16:26:20 +0100
Subject: [PATCH] snapzone spanws 90degree angle to the sky

---
 Assets/FactManager.cs                         | 53 +++++++++++++++++++
 .../InteractionEngine/CommunicationEvents.cs  |  2 +-
 Assets/InteractionEngine/WorldCursor.cs       | 15 ++++--
 3 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/Assets/FactManager.cs b/Assets/FactManager.cs
index db172fc2..43dbbc74 100644
--- a/Assets/FactManager.cs
+++ b/Assets/FactManager.cs
@@ -22,6 +22,7 @@ void Start()
     {
         CommunicationEvents.ToolModeChangedEvent.AddListener(OnToolModeChanged);
         CommunicationEvents.TriggerEvent.AddListener(OnHit);
+        CommunicationEvents.SnapEvent.AddListener(Rocket);
 
         //We dont want to have this here anymore...
         //CommunicationEvents.RemoveFactEvent.AddListener(DeleteFact);
@@ -175,6 +176,42 @@ public void OnToolModeChanged(ToolMode ActiveToolMode)
         }
     }
 
+    //automatic 90 degree angle construction
+    public void Rocket(RaycastHit hit)
+    {
+
+        int idA, idB, idC;
+
+        //usual point
+        idA = this.GetFirstEmptyID();
+        CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit, idA));
+
+        //second point
+        idB = this.GetFirstEmptyID();
+        var shiftedHit = hit;
+        var playerPos = Camera.main.transform.position;
+        playerPos.y = hit.point.y;
+        shiftedHit.point = playerPos;
+        CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(shiftedHit, idB));
+
+        //third point with unknown height
+        idC = this.GetFirstEmptyID();
+        var skyHit = hit;
+        skyHit.point += Vector3.up * 20;
+        CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(skyHit, idC));
+
+        //lines
+        CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(idA, idB, this.GetFirstEmptyID()));
+        //lines
+        CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(idA, idC, this.GetFirstEmptyID()));
+
+        //90degree angle
+        CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB,idA,idC, GetFirstEmptyID()));
+
+
+
+
+    }
     public void OnHit(RaycastHit hit)
     {
         
@@ -210,6 +247,22 @@ public void OnHit(RaycastHit hit)
                     }
                 }
                 //If no Point was hit
+                else if(Input.GetKey(KeyCode.LeftShift))
+                {
+                    if (this.lineModeIsFirstPointSelected)
+                    {
+                        //Event for end of line-drawing in "ShinyThings"
+                        int id = this.GetFirstEmptyID();
+                        CommunicationEvents.AddFactEvent.Invoke(this.AddPointFact(hit,id ));
+
+                        CommunicationEvents.StopLineDrawingEvent.Invoke(null);
+                        //Create LineFact
+                        CommunicationEvents.AddFactEvent.Invoke(this.AddLineFact(this.lineModeFirstPointSelected.Id,id, this.GetFirstEmptyID()));
+                        this.lineModeIsFirstPointSelected = false;
+                        this.lineModeFirstPointSelected = null;
+                    }
+                }
+
                 else
                 {
                     if (this.lineModeIsFirstPointSelected)
diff --git a/Assets/InteractionEngine/CommunicationEvents.cs b/Assets/InteractionEngine/CommunicationEvents.cs
index 93724547..cccef20e 100644
--- a/Assets/InteractionEngine/CommunicationEvents.cs
+++ b/Assets/InteractionEngine/CommunicationEvents.cs
@@ -44,7 +44,7 @@ public class ShinyEvent : UnityEvent<Fact> {
 
 
 
-
+    public static HitEvent SnapEvent = new HitEvent();
     public static HitEvent TriggerEvent = new HitEvent();
 
     public static ToolModeEvent ToolModeChangedEvent = new ToolModeEvent();
diff --git a/Assets/InteractionEngine/WorldCursor.cs b/Assets/InteractionEngine/WorldCursor.cs
index 59ca1510..cd3e8be7 100644
--- a/Assets/InteractionEngine/WorldCursor.cs
+++ b/Assets/InteractionEngine/WorldCursor.cs
@@ -72,9 +72,18 @@ void CheckMouseButtons(bool OnSnap=false)
         if (Input.GetMouseButtonDown(0))
         {
             if (EventSystem.current.IsPointerOverGameObject()) return; //this prevents rays from shooting through ui
-       
-            CommunicationEvents.TriggerEvent.Invoke(Hit);
-           if(OnSnap) Hit.collider.enabled = false;
+
+            if (!OnSnap)
+            {
+                CommunicationEvents.TriggerEvent.Invoke(Hit);
+            }
+            else {
+                Hit.collider.enabled = false;
+                CommunicationEvents.SnapEvent.Invoke(Hit);
+            }
+                
+
+          
 
         }
     }
-- 
GitLab