From ba5cc88f93a3a8d1d213c70081e13b35fcb04574 Mon Sep 17 00:00:00 2001 From: Paul-Walcher <paulwalcher12@gmail.com> Date: Sat, 20 Jul 2024 12:54:13 +0200 Subject: [PATCH] added layers for rectangle, cuboid, cylinder and sphere --- Assets/Resources/Prefabs/Facts/Cuboid.prefab | 6 ++--- .../Resources/Prefabs/Facts/Cylinder.prefab | 6 ++--- .../Resources/Prefabs/Facts/Rectangle.prefab | 10 +++---- Assets/Resources/Prefabs/Facts/Sphere.prefab | 6 ++--- Assets/Scenes/Worlds/RiverWorld.unity | 14 +++++++++- .../FactHandling/Facts/RectangleFact.cs | 26 ++++++++++++++++++- ProjectSettings/TagManager.asset | 8 +++--- 7 files changed, 56 insertions(+), 20 deletions(-) diff --git a/Assets/Resources/Prefabs/Facts/Cuboid.prefab b/Assets/Resources/Prefabs/Facts/Cuboid.prefab index e494aa34..5098a4e3 100644 --- a/Assets/Resources/Prefabs/Facts/Cuboid.prefab +++ b/Assets/Resources/Prefabs/Facts/Cuboid.prefab @@ -10,7 +10,7 @@ GameObject: m_Component: - component: {fileID: 3390467403729316765} - component: {fileID: 6950663371922587874} - m_Layer: 15 + m_Layer: 26 m_Name: Cuboid m_TagString: Selectable m_Icon: {fileID: 0} @@ -67,7 +67,7 @@ GameObject: - component: {fileID: 5986843358289336505} - component: {fileID: 7177577245137766670} - component: {fileID: 2586578973517344970} - m_Layer: 10 + m_Layer: 26 m_Name: LabelText m_TagString: Untagged m_Icon: {fileID: 0} @@ -254,7 +254,7 @@ GameObject: - component: {fileID: 5831357366368800904} - component: {fileID: 7650278115114718330} - component: {fileID: 1525151776347487752} - m_Layer: 15 + m_Layer: 26 m_Name: Cube m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Resources/Prefabs/Facts/Cylinder.prefab b/Assets/Resources/Prefabs/Facts/Cylinder.prefab index 5c2e695f..fec452a7 100644 --- a/Assets/Resources/Prefabs/Facts/Cylinder.prefab +++ b/Assets/Resources/Prefabs/Facts/Cylinder.prefab @@ -11,7 +11,7 @@ GameObject: - component: {fileID: 6247848413542547290} - component: {fileID: 2803381884781347863} - component: {fileID: 6081132167704541829} - m_Layer: 0 + m_Layer: 25 m_Name: Cylinder m_TagString: Untagged m_Icon: {fileID: 0} @@ -93,7 +93,7 @@ GameObject: m_Component: - component: {fileID: 3390467403729316765} - component: {fileID: 6950663371922587874} - m_Layer: 15 + m_Layer: 25 m_Name: Cylinder m_TagString: Selectable m_Icon: {fileID: 0} @@ -151,7 +151,7 @@ GameObject: - component: {fileID: 5986843358289336505} - component: {fileID: 7177577245137766670} - component: {fileID: 2586578973517344970} - m_Layer: 10 + m_Layer: 25 m_Name: LabelText m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Resources/Prefabs/Facts/Rectangle.prefab b/Assets/Resources/Prefabs/Facts/Rectangle.prefab index 61f63912..591b9173 100644 --- a/Assets/Resources/Prefabs/Facts/Rectangle.prefab +++ b/Assets/Resources/Prefabs/Facts/Rectangle.prefab @@ -11,7 +11,7 @@ GameObject: - component: {fileID: 3390467403729316765} - component: {fileID: 1812690906255965161} - component: {fileID: 6950663371922587874} - m_Layer: 15 + m_Layer: 23 m_Name: Rectangle m_TagString: Selectable m_Icon: {fileID: 0} @@ -78,7 +78,7 @@ MonoBehaviour: Hint: {fileID: 2100000, guid: 8621b710d7d1d5041bc6bfd0cc37cdff, type: 2} Solution: {fileID: 2100000, guid: 2a003f0807acc1142965bb21bdc824f6, type: 2} renderer: - - {fileID: 0} + - {fileID: 6517075380011649605} --- !u!1 &7399997364077007465 GameObject: m_ObjectHideFlags: 0 @@ -90,7 +90,7 @@ GameObject: - component: {fileID: 6990040153469839674} - component: {fileID: 8042990558578607756} - component: {fileID: 5361971246579526846} - m_Layer: 0 + m_Layer: 23 m_Name: PlaneDown m_TagString: Untagged m_Icon: {fileID: 0} @@ -173,7 +173,7 @@ GameObject: - component: {fileID: 2727348597328184922} - component: {fileID: 3597909010427076542} - component: {fileID: 6517075380011649605} - m_Layer: 0 + m_Layer: 23 m_Name: PlaneUp m_TagString: Untagged m_Icon: {fileID: 0} @@ -257,7 +257,7 @@ GameObject: - component: {fileID: 5986843358289336505} - component: {fileID: 7177577245137766670} - component: {fileID: 2586578973517344970} - m_Layer: 10 + m_Layer: 23 m_Name: LabelText m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Resources/Prefabs/Facts/Sphere.prefab b/Assets/Resources/Prefabs/Facts/Sphere.prefab index db849c54..e0ae1814 100644 --- a/Assets/Resources/Prefabs/Facts/Sphere.prefab +++ b/Assets/Resources/Prefabs/Facts/Sphere.prefab @@ -11,7 +11,7 @@ GameObject: - component: {fileID: 1380396336186306334} - component: {fileID: 4239463486727728565} - component: {fileID: 1073589650764508292} - m_Layer: 15 + m_Layer: 24 m_Name: SphereVisual m_TagString: Untagged m_Icon: {fileID: 0} @@ -93,7 +93,7 @@ GameObject: m_Component: - component: {fileID: 3390467403729316765} - component: {fileID: 6950663371922587874} - m_Layer: 15 + m_Layer: 24 m_Name: Sphere m_TagString: Selectable m_Icon: {fileID: 0} @@ -150,7 +150,7 @@ GameObject: - component: {fileID: 5986843358289336505} - component: {fileID: 7177577245137766670} - component: {fileID: 2586578973517344970} - m_Layer: 10 + m_Layer: 24 m_Name: LabelText m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Scenes/Worlds/RiverWorld.unity b/Assets/Scenes/Worlds/RiverWorld.unity index c71130ff..14c94018 100644 --- a/Assets/Scenes/Worlds/RiverWorld.unity +++ b/Assets/Scenes/Worlds/RiverWorld.unity @@ -60649,7 +60649,7 @@ PrefabInstance: - target: {fileID: 2258042202925325658, guid: b07552db700124a4680401e6fb94c186, type: 3} propertyPath: factLayerMask.m_Bits - value: 6355968 + value: 132185088 objectReference: {fileID: 0} - target: {fileID: 2267088185126138740, guid: b07552db700124a4680401e6fb94c186, type: 3} @@ -63085,6 +63085,12 @@ PrefabInstance: value: objectReference: {fileID: 3080888058940174091, guid: 389563c758e86d848b3341576b90b7e4, type: 3} + - target: {fileID: 6898471569945669422, guid: b07552db700124a4680401e6fb94c186, + type: 3} + propertyPath: PrefabDataConfig.Array.data[32] + value: + objectReference: {fileID: 3080888058940174091, guid: 78a5636dd3b386a4e82a65390ad23c7d, + type: 3} - target: {fileID: 6898471569945669422, guid: b07552db700124a4680401e6fb94c186, type: 3} propertyPath: PrefabDataConfig.Array.data[33] @@ -63557,6 +63563,12 @@ PrefabInstance: value: objectReference: {fileID: 3080888058940174091, guid: 389563c758e86d848b3341576b90b7e4, type: 3} + - target: {fileID: 7743735189960969443, guid: b07552db700124a4680401e6fb94c186, + type: 3} + propertyPath: PrefabDataConfig.Array.data[32] + value: + objectReference: {fileID: 3080888058940174091, guid: 78a5636dd3b386a4e82a65390ad23c7d, + type: 3} - target: {fileID: 7743735189960969443, guid: b07552db700124a4680401e6fb94c186, type: 3} propertyPath: PrefabDataConfig.Array.data[33] diff --git a/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs b/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs index a66035f2..e53aae6e 100644 --- a/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs +++ b/Assets/Scripts/InteractionEngine/FactHandling/Facts/RectangleFact.cs @@ -40,7 +40,31 @@ protected void calculate_vectors(){ Position = B + 0.5F*((A-B) + (C-B)); - Rotation = Quaternion.LookRotation(Vector3.Cross((A-B), (C-B)), Vector3.up); + Vector3 cross = Vector3.Cross((A-B), (C-B)); + + + float epsilon = 1E-9F; + float dot = Vector3.Dot(cross.normalized, Vector3.up.normalized); + float cosangle = dot / (cross.magnitude * Vector3.up.magnitude); + if (Mathf.Abs(cosangle) < epsilon || Mathf.Abs(cosangle - 180.0F) < epsilon){ + + //vectors are parallel + Vector3 initialForward = Vector3.forward; + + // Project the normal vector onto the x-z plane + Vector3 projectedNormal = new Vector3(cross.x, 0, cross.z).normalized; + + // Compute the angle between the initial forward direction and the projected normal + float angle = Vector3.SignedAngle(initialForward, projectedNormal, Vector3.up); + + // Create the quaternion representing the rotation around the y-axis + Rotation = Quaternion.Euler(0, angle, 0); + + + } + else{ + Rotation = Quaternion.LookRotation(cross, Vector3.up); + } //Rotation = Quaternion.LookRotation(forward, new Vector3(1.0F, 0.0F, 0.0F)); } diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1c170723..1b57ab3a 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -35,10 +35,10 @@ TagManager: - SnapZone - Triangle - TriangularPrism - - - - - - - - + - Rectangle + - Sphere + - Cylinder + - Cuboid - - - -- GitLab