From 04fa018f699cd23df50711b22f04da6c9ce9d964 Mon Sep 17 00:00:00 2001 From: unknown <john.schihada@hotmail.com> Date: Thu, 16 Jan 2020 16:51:06 +0100 Subject: [PATCH] Adjusted the AngleMode from 2 Lines to 3 Points AND Adjusted the AnglePreview for it, because we now can't assume to have Lines between the points --- Assets/FactManager.cs | 103 +++++++++++++----------- Assets/InteractionEngine/FactSpawner.cs | 3 +- Assets/InteractionEngine/ShinyThings.cs | 35 ++++---- Assets/InventoryStuff/Inventory.meta | 8 -- 4 files changed, 73 insertions(+), 76 deletions(-) delete mode 100644 Assets/InventoryStuff/Inventory.meta diff --git a/Assets/FactManager.cs b/Assets/FactManager.cs index 46ff94ac..719db5d0 100644 --- a/Assets/FactManager.cs +++ b/Assets/FactManager.cs @@ -14,8 +14,10 @@ public class FactManager : MonoBehaviour public Fact lineModeFirstPointSelected = null; //Variables for AngleMode distinction - public bool angleModeIsFirstLineSelected = false; - public Fact angleModeFirstLineSelected = null; + public bool angleModeIsFirstPointSelected = false; + public Fact angleModeFirstPointSelected = null; + public bool angleModeIsSecondPointSelected = false; + public Fact angleModeSecondPointSelected = null; // Start is called before the first frame update void Start() @@ -142,16 +144,16 @@ public void OnToolModeChanged(ToolMode ActiveToolMode) } break; case ToolMode.CreateAngleMode: - //If CreateAngleMode is activated we want to have the ability to select Lines for the Angle - //but we don't want to have the ability to select Points or Angles + //If CreateAngleMode is activated we want to have the ability to select Points for the Angle + //but we don't want to have the ability to select Lines or Angles foreach (Fact fact in Facts) { GameObject gO = fact.Representation; - if (gO.layer == LayerMask.NameToLayer("Point") || gO.layer == LayerMask.NameToLayer("Angle")) + if (gO.layer == LayerMask.NameToLayer("Line") || gO.layer == LayerMask.NameToLayer("Angle")) { gO.GetComponentInChildren<Collider>().enabled = false; } - else if (gO.layer == LayerMask.NameToLayer("Line")) + else if (gO.layer == LayerMask.NameToLayer("Point")) { gO.GetComponentInChildren<Collider>().enabled = true; } @@ -213,6 +215,7 @@ public void Rocket(RaycastHit hit) CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB,idA,idC, GetFirstEmptyID())); } + //Creating 90-degree Angles public void SmallRocket(RaycastHit hit, int idA) { //enable collider to measure angle to the treetop @@ -316,7 +319,6 @@ public void OnHit(RaycastHit hit) } } - //If no Point was hit else { @@ -334,67 +336,72 @@ public void OnHit(RaycastHit hit) break; //If Left-Mouse-Button was pressed in CreateAngleMode case ToolMode.CreateAngleMode: - //Check if an existing Line was hit - if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Line")) + //Check if an existing Point was hit + if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point")) { Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id]; - if (this.angleModeIsFirstLineSelected) + //If two points were already selected and now the third point got selected + if (this.angleModeIsFirstPointSelected && this.angleModeIsSecondPointSelected) { - //Event for end of line-rendering in "ShinyThings" + //Event for end of curve-drawing in "ShinyThings" CommunicationEvents.StopCurveDrawingEvent.Invoke(null); //Create AngleFact - //Check if selected Lines are the same -> if true -> cancel - if (!(angleModeFirstLineSelected.Id == tempFact.Id)) + //Check if new Point is equal to one of the previous points -> if true -> cancel + if (!(angleModeFirstPointSelected.Id == tempFact.Id || angleModeSecondPointSelected.Id == tempFact.Id)) { - //Check if selected Lines have a common Point = id2 for AngleFact - if (((LineFact)angleModeFirstLineSelected).Pid1 == ((LineFact)tempFact).Pid1) - { - CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(((LineFact)angleModeFirstLineSelected).Pid2, ((LineFact)tempFact).Pid1, ((LineFact)tempFact).Pid2, GetFirstEmptyID())); - } - else if (((LineFact)angleModeFirstLineSelected).Pid1 == ((LineFact)tempFact).Pid2) - { - CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(((LineFact)angleModeFirstLineSelected).Pid2, ((LineFact)tempFact).Pid2, ((LineFact)tempFact).Pid1, GetFirstEmptyID())); - } - else if (((LineFact)angleModeFirstLineSelected).Pid2 == ((LineFact)tempFact).Pid1) - { - CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(((LineFact)angleModeFirstLineSelected).Pid1, ((LineFact)tempFact).Pid1, ((LineFact)tempFact).Pid2, GetFirstEmptyID())); - } - else if (((LineFact)angleModeFirstLineSelected).Pid2 == ((LineFact)tempFact).Pid2) - { - CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(((LineFact)angleModeFirstLineSelected).Pid1, ((LineFact)tempFact).Pid2, ((LineFact)tempFact).Pid1, GetFirstEmptyID())); - } - else - { - //TODO: Hint that the selected Lines have no common point - } + CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(((PointFact)angleModeFirstPointSelected).Id, ((PointFact)angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id, GetFirstEmptyID())); } - this.angleModeIsFirstLineSelected = false; - this.angleModeFirstLineSelected = null; + this.angleModeIsFirstPointSelected = false; + this.angleModeFirstPointSelected = null; + this.angleModeIsSecondPointSelected = false; + this.angleModeSecondPointSelected = null; } + //If only one point was already selected + else if (this.angleModeIsFirstPointSelected && !this.angleModeIsSecondPointSelected) { + //Check if the 2 selected points are the same: If not + if (this.angleModeFirstPointSelected.Id != tempFact.Id) + { + this.angleModeIsSecondPointSelected = true; + this.angleModeSecondPointSelected = tempFact; + + //Event for start of curve-drawing in "ShinyThings" + //Create new LineFact with the 2 points + LineFact tempLineFact = new LineFact(); + tempLineFact.Pid1 = this.angleModeFirstPointSelected.Id; + tempLineFact.Pid2 = this.angleModeSecondPointSelected.Id; + CommunicationEvents.StartCurveDrawingEvent.Invoke(tempLineFact); + } + else { + this.angleModeFirstPointSelected = null; + this.angleModeIsFirstPointSelected = false; + } + } + //If no point was selected before else { - //Activate CurveDrawing for preview - this.angleModeIsFirstLineSelected = true; - this.angleModeFirstLineSelected = tempFact; - //Event for start line-rendering in "ShinyThings" - CommunicationEvents.StartCurveDrawingEvent.Invoke(this.angleModeFirstLineSelected); + //Save the first point selected + this.angleModeIsFirstPointSelected = true; + this.angleModeFirstPointSelected = tempFact; } } + //No point was hit else { - //TODO: If Point was hit: Angle Drawing with Selecting 3 Points - if (this.angleModeIsFirstLineSelected) + if (this.angleModeIsFirstPointSelected && this.angleModeIsSecondPointSelected) { - //Deactivate CurveDrawing and first line selection - this.angleModeIsFirstLineSelected = false; - this.angleModeFirstLineSelected = null; - //Event for end of line-drawing in "ShinyThings" + //Event for end of curve-drawing in "ShinyThings" CommunicationEvents.StopCurveDrawingEvent.Invoke(null); } - //TODO: Hint that only a curve can be drawn between already existing lines + //Reset Angle-Preview-Attributes + this.angleModeIsFirstPointSelected = false; + this.angleModeFirstPointSelected = null; + this.angleModeIsSecondPointSelected = false; + this.angleModeSecondPointSelected = null; + + //TODO: Hint that only an angle can be created between 3 already existing points } break; //If Left-Mouse-Button was pressed in DeleteMode diff --git a/Assets/InteractionEngine/FactSpawner.cs b/Assets/InteractionEngine/FactSpawner.cs index 1ce27cff..7061aa68 100644 --- a/Assets/InteractionEngine/FactSpawner.cs +++ b/Assets/InteractionEngine/FactSpawner.cs @@ -96,6 +96,7 @@ public void SpawnLine(LineFact lineFact) } + //Spawn an angle: point with id = angleFact.Pid2 is the point where the angle gets applied public void SpawnAngle(AngleFact angleFact) { @@ -109,7 +110,7 @@ public void SpawnAngle(AngleFact angleFact) //Length of the Angle relative to the Length of the shortest of the two lines (point2->point1) and (point2->point3) float lengthFactor = 0.3f; //AngleGO: Triangle-Length: 3/4, Circle-Length: 1/4 - float angleGoFactorTriangleToCircle = 1.25f; + float angleGoFactorTriangleToCircle = 1.27f; //Make 2 TempPoints positioned on length% from Point2 to Point3 and on length% from Point2 to Point1 //Will be used for z-Coordinate of the Angle diff --git a/Assets/InteractionEngine/ShinyThings.cs b/Assets/InteractionEngine/ShinyThings.cs index d6288c67..1d7c05a0 100644 --- a/Assets/InteractionEngine/ShinyThings.cs +++ b/Assets/InteractionEngine/ShinyThings.cs @@ -20,6 +20,7 @@ public class ShinyThings : MonoBehaviour private bool lineDrawingActivated; private bool curveDrawingActivated; + //These are only the vertices for the Curve private int curveDrawingVertexCount = 36; private LineFact curveDrawingStartLine; private Vector3 curveEndPoint; @@ -136,10 +137,11 @@ public void DeactivateLineDrawing(Fact startFact) this.lineDrawingActivated = false; } - //Expect a LineFact here, so that it's possible to change between two possible StartPoints + //Expect a LineFact here, where Line.Pid2 will be the Basis-Point of the angle public void ActivateCurveDrawing(Fact startFact) { - this.lineRenderer.positionCount = curveDrawingVertexCount; + //In AngleMode with 3 Points we want to draw nearly a rectangle so we add a startPoint and an Endpoint to this preview + this.lineRenderer.positionCount = curveDrawingVertexCount + 2; lineRenderer.startWidth = 0.05f; lineRenderer.endWidth = 0.05f; @@ -148,24 +150,14 @@ public void ActivateCurveDrawing(Fact startFact) this.curveDrawingActivated = true; curveDrawingStartLine = (LineFact)startFact; + PointFact curveDrawingPoint1 = (PointFact)Facts.Find(x => x.Id == curveDrawingStartLine.Pid1); + PointFact curveDrawingPoint2 = (PointFact)Facts.Find(x => x.Id == curveDrawingStartLine.Pid2); - curveEndPoint = Cursor.transform.position; - - //Determine which point of the line is closer to the cursor and initialize angleMiddlePoint - //angleMiddlePoint is needed for the Angle Preview - float Distance1 = (Facts.Find(x => x.Id == curveDrawingStartLine.Pid1).Representation.transform.position - curveEndPoint).magnitude; - float Distance2 = (Facts.Find(x => x.Id == curveDrawingStartLine.Pid2).Representation.transform.position - curveEndPoint).magnitude; - - if (Distance1 >= Distance2) - { - angleMiddlePoint = Facts.Find(x => x.Id == curveDrawingStartLine.Pid2).Representation.transform.position; - curveRadius = Distance2; - } - else - { - angleMiddlePoint = Facts.Find(x => x.Id == curveDrawingStartLine.Pid1).Representation.transform.position; - curveRadius = Distance1; - } + //curveEndPoint is a point on the Line selected, with some distance from point2 + curveEndPoint = curveDrawingPoint2.Point + 0.3f * (curveDrawingPoint1.Point - curveDrawingPoint2.Point).magnitude * (curveDrawingPoint1.Point - curveDrawingPoint2.Point).normalized; + + angleMiddlePoint = curveDrawingPoint2.Point; + curveRadius = (curveEndPoint - curveDrawingPoint2.Point).magnitude; } public void UpdateCurveDrawing(Vector3 currentPosition) @@ -178,6 +170,8 @@ public void UpdateCurveDrawing(Vector3 currentPosition) 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); for (float ratio = 0; ratio <= 1; ratio += 1.0f / this.curveDrawingVertexCount) { @@ -187,6 +181,9 @@ public void UpdateCurveDrawing(Vector3 currentPosition) linePositions.Add(bezierPoint); } + //End: LastPoint of Curve -> AngleMiddlePoint + linePositions.Add(((PointFact)Facts.Find(x => x.Id == curveDrawingStartLine.Pid2)).Point); + lineRenderer.positionCount = linePositions.Count; lineRenderer.SetPositions(linePositions.ToArray()); diff --git a/Assets/InventoryStuff/Inventory.meta b/Assets/InventoryStuff/Inventory.meta deleted file mode 100644 index 9818e1d1..00000000 --- a/Assets/InventoryStuff/Inventory.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b543d9677cbde534ab69c0a229bfdb06 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: -- GitLab