From 174f8fa63b760366f0932f8c861e6fd44bb98071 Mon Sep 17 00:00:00 2001 From: "https://gl.mathhub.info/SESch93" <john.schihada@hotmail.com> Date: Sat, 26 Jun 2021 20:50:11 +0200 Subject: [PATCH] Adjusted spawning of angles: Made rotation more accurate --- .../Scripts/InteractionEngine/FactSpawner.cs | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/InteractionEngine/FactSpawner.cs b/Assets/Scripts/InteractionEngine/FactSpawner.cs index e71545e3..a4d786e8 100644 --- a/Assets/Scripts/InteractionEngine/FactSpawner.cs +++ b/Assets/Scripts/InteractionEngine/FactSpawner.cs @@ -164,29 +164,22 @@ public Fact SpawnAngle(Fact fact) this.FactRepresentation = (GameObject)Resources.Load("Prefabs/Angle", typeof(GameObject)); GameObject angle = GameObject.Instantiate(FactRepresentation); - //Place the Angle at position of point2 - angle.transform.position = point2; + //Calculate Angle: + Vector3 from = (point3 - point2).normalized; + Vector3 to = (point1 - point2).normalized; + float angleValue = Vector3.Angle(from, to); //We always get an angle between 0 and 180° here //Change scale and rotation, so that the angle is in between the two lines var v3T = angle.transform.localScale; v3T = new Vector3(length, v3T.y, length); - //Calculate Angle: - Vector3 from = (point1 - point2).normalized; - Vector3 to = (point3 - point2).normalized; - float angleValue = Vector3.Angle(from, to); //We always get an angle between 0 and 180° here - //Vector3 direction = point2 - camera.transform.position; - //float angleSign = Mathf.Sign( Vector3.Dot( direction, Vector3.Cross( from, to ) ) ); + Vector3 up = Vector3.Cross(to, from); + angle.transform.rotation = Quaternion.LookRotation(Vector3.Cross((from+to).normalized,up), up); - angle.transform.rotation = Quaternion.FromToRotation(Vector3.right, (Vector3.Lerp((point1 - point2).normalized, (point3 - point2).normalized, 0.5f))); - float signedAngle = Mathf.Atan2(Vector3.Dot((Vector3.Lerp((point1 - point2).normalized, (point3 - point2).normalized, 0.5f)), Vector3.Cross(angle.transform.GetChild(0).forward.normalized, (point1 - point3).normalized)), Vector3.Dot(angle.transform.GetChild(0).forward.normalized, (point1 - point3).normalized)) * Mathf.Rad2Deg; - if (signedAngle < 0) - { - angle.transform.RotateAround(point2, (Vector3.Lerp((point1 - point2).normalized, (point3 - point2).normalized, 0.5f)), Vector3.Angle(angle.transform.GetChild(0).forward.normalized, (point3 - point1).normalized)); - } - else - angle.transform.RotateAround(point2, (Vector3.Lerp((point1 - point2).normalized, (point3 - point2).normalized, 0.5f)), Vector3.Angle(angle.transform.GetChild(0).forward.normalized, (point1 - point3).normalized)); + //Place the Angle at position of point2 + angle.transform.position = point2; + //Set text of angle TextMeshPro[] texts = angle.GetComponentsInChildren<TextMeshPro>(); foreach (TextMeshPro t in texts) { //Change Text not to the id, but to the angle-value (from both sides) AND change font-size relative to length of the angle (from both sides) @@ -194,6 +187,7 @@ public Fact SpawnAngle(Fact fact) t.fontSize = angle.GetComponentInChildren<TextMeshPro>().fontSize * angle.transform.GetChild(0).transform.GetChild(0).localScale.x; } + //Generate angle mesh CircleSegmentGenerator[] segments = angle.GetComponentsInChildren<CircleSegmentGenerator>(); foreach (CircleSegmentGenerator c in segments) c.setAngle(angleValue); -- GitLab