From f462bcca88b5deb6ea1047e41d9eaa403637b52c Mon Sep 17 00:00:00 2001 From: "Marco Zimmer (MaZiFAU)" <marco.alexander.zimmer@fau.de> Date: Mon, 2 Aug 2021 13:30:07 +0200 Subject: [PATCH] misc: just PointerGadeget snaps on tree-roof, used 'IsApproximatelyParallel' for RayFact Equivalency --- .../Plugins/NaturePackLite/Prefabs/Tree_01.prefab | 2 +- Assets/Resources/Prefabs/Angle.prefab | 8 ++++---- Assets/Scripts/InteractionEngine/Fact.cs | 3 +-- Assets/Scripts/InteractionEngine/FactOrganizer.cs | 11 +++++++++-- Assets/Scripts/Math3d.cs | 14 ++++++++++++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab b/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab index 652b114e..d63ec606 100644 --- a/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab +++ b/Assets/Plugins/NaturePackLite/Prefabs/Tree_01.prefab @@ -141,7 +141,7 @@ SphereCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Radius: 0.4 + m_Radius: 0.5 m_Center: {x: 0, y: 0, z: 0} --- !u!33 &933372636075482527 MeshFilter: diff --git a/Assets/Resources/Prefabs/Angle.prefab b/Assets/Resources/Prefabs/Angle.prefab index 32725c94..201b2d09 100644 --- a/Assets/Resources/Prefabs/Angle.prefab +++ b/Assets/Resources/Prefabs/Angle.prefab @@ -184,7 +184,7 @@ GameObject: - component: {fileID: 3394522495515098203} - component: {fileID: 3394522495515098196} - component: {fileID: 7137147696081341476} - m_Layer: 0 + m_Layer: 12 m_Name: AngleOuter m_TagString: Untagged m_Icon: {fileID: 0} @@ -310,7 +310,7 @@ GameObject: - component: {fileID: 3394522496185282006} - component: {fileID: 3394522496185282007} - component: {fileID: 2270583313952035853} - m_Layer: 0 + m_Layer: 12 m_Name: AngleInner m_TagString: Untagged m_Icon: {fileID: 0} @@ -431,9 +431,9 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 5781467132517744785} - m_Layer: 0 + m_Layer: 12 m_Name: Angle - m_TagString: Untagged + m_TagString: Selectable m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 diff --git a/Assets/Scripts/InteractionEngine/Fact.cs b/Assets/Scripts/InteractionEngine/Fact.cs index 84c42fae..6ea47ee4 100644 --- a/Assets/Scripts/InteractionEngine/Fact.cs +++ b/Assets/Scripts/InteractionEngine/Fact.cs @@ -399,8 +399,7 @@ public override GameObject instantiateDisplay(GameObject prefab, Transform trans protected override bool EquivalentWrapped(RayFact f1, RayFact f2) { - // TODO! check for similar(float uncertanty!) Directions - if (f1.Dir != f2.Dir && f1.Dir != -f2.Dir) + if (!Math3d.IsApproximatelyParallel(f1.Dir, f2.Dir)) return false; PointFact p1f1 = (PointFact)Facts[f1.Pid1]; diff --git a/Assets/Scripts/InteractionEngine/FactOrganizer.cs b/Assets/Scripts/InteractionEngine/FactOrganizer.cs index bf83ad6b..fdaa902e 100644 --- a/Assets/Scripts/InteractionEngine/FactOrganizer.cs +++ b/Assets/Scripts/InteractionEngine/FactOrganizer.cs @@ -109,7 +109,7 @@ private bool FindEquivalent(Fact search, out Fact found) } private void WorkflowAdd(stepnote note) - // adds Workflow; updates meta struct; Invokes Events + // prunes & adds Workflow; updates meta struct; Invokes Events { PruneWorkflow(); @@ -154,6 +154,13 @@ private void PruneWorkflow() base.Remove(last.Id); MetaInf.Remove(last.Id); } + else + // update active status + { + meta inf = MetaInf[last.Id]; + inf.active = !last.creation; + MetaInf[last.Id] = inf; + } } // prune Worklfow down to marker @@ -231,7 +238,7 @@ public bool Remove(int key, bool samestep = false) // TODO: MMT: decide dependencies there (remember virtual deletions in Unity (un-redo)!) // TODO? decrease runtime from O(n/2) - private bool safe_dependencies(int key, out List<int> dependencies) + public bool safe_dependencies(int key, out List<int> dependencies) // searches for dependencies of a Fact; returns false if any dependencies are steproots // int key: Fact to be deleted // out List<int> dependencies: dependencyList diff --git a/Assets/Scripts/Math3d.cs b/Assets/Scripts/Math3d.cs index b6cf776e..73156d61 100644 --- a/Assets/Scripts/Math3d.cs +++ b/Assets/Scripts/Math3d.cs @@ -534,7 +534,7 @@ public static bool IsPointOnLine(Vector3 linePoint, Vector3 lineVec, Vector3 poi } //This function returns true if a point is approximately on a line. - //The line is regarded infinite. + //The line is regarded as being infinite. public static bool IsPointApproximatelyOnLine(Vector3 linePoint, Vector3 lineVec, Vector3 point, double precission = Math3d.vectorPrecission) { @@ -543,7 +543,17 @@ public static bool IsPointApproximatelyOnLine(Vector3 linePoint, Vector3 lineVec double t = Vector3.Dot(linePointToPoint.normalized, lineVec); - return Math.Abs(t - 1d) < precission || Math.Abs(t) < precission; + return Math.Abs(Math.Abs(t) - 1d) < precission || Math.Abs(t) < precission; + } + + //This function returns true if two Vector3s are approximately parallel + public static bool IsApproximatelyParallel(Vector3 vectorA, Vector3 vectorB, double precission = Math3d.vectorPrecission) + { + //SqrMagnitude(Abs(vectorA) - Abs(vectorB)) < precission + return Math.Pow(Math.Abs(vectorA.x) - Math.Abs(vectorB.x), 2) + + Math.Pow(Math.Abs(vectorA.y) - Math.Abs(vectorB.y), 2) + + Math.Pow(Math.Abs(vectorA.z) - Math.Abs(vectorB.z), 2) + < precission; } //This function returns a point which is a projection from a point to a line segment. -- GitLab