Skip to content
Snippets Groups Projects
Commit 04fa018f authored by John Schihada's avatar John Schihada
Browse files

Adjusted the AngleMode from 2 Lines to 3 Points AND Adjusted the AnglePreview...

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
parent 7cf37d3a
No related branches found
No related tags found
No related merge requests found
...@@ -14,8 +14,10 @@ public class FactManager : MonoBehaviour ...@@ -14,8 +14,10 @@ public class FactManager : MonoBehaviour
public Fact lineModeFirstPointSelected = null; public Fact lineModeFirstPointSelected = null;
//Variables for AngleMode distinction //Variables for AngleMode distinction
public bool angleModeIsFirstLineSelected = false; public bool angleModeIsFirstPointSelected = false;
public Fact angleModeFirstLineSelected = null; public Fact angleModeFirstPointSelected = null;
public bool angleModeIsSecondPointSelected = false;
public Fact angleModeSecondPointSelected = null;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
...@@ -142,16 +144,16 @@ public void OnToolModeChanged(ToolMode ActiveToolMode) ...@@ -142,16 +144,16 @@ public void OnToolModeChanged(ToolMode ActiveToolMode)
} }
break; break;
case ToolMode.CreateAngleMode: case ToolMode.CreateAngleMode:
//If CreateAngleMode is activated we want to have the ability to select Lines for the Angle //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 Points or Angles //but we don't want to have the ability to select Lines or Angles
foreach (Fact fact in Facts) foreach (Fact fact in Facts)
{ {
GameObject gO = fact.Representation; 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; gO.GetComponentInChildren<Collider>().enabled = false;
} }
else if (gO.layer == LayerMask.NameToLayer("Line")) else if (gO.layer == LayerMask.NameToLayer("Point"))
{ {
gO.GetComponentInChildren<Collider>().enabled = true; gO.GetComponentInChildren<Collider>().enabled = true;
} }
...@@ -213,6 +215,7 @@ public void Rocket(RaycastHit hit) ...@@ -213,6 +215,7 @@ public void Rocket(RaycastHit hit)
CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB,idA,idC, GetFirstEmptyID())); CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(idB,idA,idC, GetFirstEmptyID()));
} }
//Creating 90-degree Angles
public void SmallRocket(RaycastHit hit, int idA) public void SmallRocket(RaycastHit hit, int idA)
{ {
//enable collider to measure angle to the treetop //enable collider to measure angle to the treetop
...@@ -316,7 +319,6 @@ public void OnHit(RaycastHit hit) ...@@ -316,7 +319,6 @@ public void OnHit(RaycastHit hit)
} }
} }
//If no Point was hit //If no Point was hit
else else
{ {
...@@ -334,67 +336,72 @@ public void OnHit(RaycastHit hit) ...@@ -334,67 +336,72 @@ public void OnHit(RaycastHit hit)
break; break;
//If Left-Mouse-Button was pressed in CreateAngleMode //If Left-Mouse-Button was pressed in CreateAngleMode
case ToolMode.CreateAngleMode: case ToolMode.CreateAngleMode:
//Check if an existing Line was hit //Check if an existing Point was hit
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Line")) if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point"))
{ {
Fact tempFact = Facts[hit.transform.GetComponent<FactObject>().Id]; 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); CommunicationEvents.StopCurveDrawingEvent.Invoke(null);
//Create AngleFact //Create AngleFact
//Check if selected Lines are the same -> if true -> cancel //Check if new Point is equal to one of the previous points -> if true -> cancel
if (!(angleModeFirstLineSelected.Id == tempFact.Id)) if (!(angleModeFirstPointSelected.Id == tempFact.Id || angleModeSecondPointSelected.Id == tempFact.Id))
{ {
//Check if selected Lines have a common Point = id2 for AngleFact CommunicationEvents.AddFactEvent.Invoke(this.AddAngleFact(((PointFact)angleModeFirstPointSelected).Id, ((PointFact)angleModeSecondPointSelected).Id, ((PointFact)tempFact).Id, GetFirstEmptyID()));
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
}
} }
this.angleModeIsFirstLineSelected = false; this.angleModeIsFirstPointSelected = false;
this.angleModeFirstLineSelected = null; 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 else
{ {
//Activate CurveDrawing for preview //Save the first point selected
this.angleModeIsFirstLineSelected = true; this.angleModeIsFirstPointSelected = true;
this.angleModeFirstLineSelected = tempFact; this.angleModeFirstPointSelected = tempFact;
//Event for start line-rendering in "ShinyThings"
CommunicationEvents.StartCurveDrawingEvent.Invoke(this.angleModeFirstLineSelected);
} }
} }
//No point was hit
else else
{ {
//TODO: If Point was hit: Angle Drawing with Selecting 3 Points if (this.angleModeIsFirstPointSelected && this.angleModeIsSecondPointSelected)
if (this.angleModeIsFirstLineSelected)
{ {
//Deactivate CurveDrawing and first line selection //Event for end of curve-drawing in "ShinyThings"
this.angleModeIsFirstLineSelected = false;
this.angleModeFirstLineSelected = null;
//Event for end of line-drawing in "ShinyThings"
CommunicationEvents.StopCurveDrawingEvent.Invoke(null); 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; break;
//If Left-Mouse-Button was pressed in DeleteMode //If Left-Mouse-Button was pressed in DeleteMode
......
...@@ -96,6 +96,7 @@ public void SpawnLine(LineFact lineFact) ...@@ -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) public void SpawnAngle(AngleFact angleFact)
{ {
...@@ -109,7 +110,7 @@ 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) //Length of the Angle relative to the Length of the shortest of the two lines (point2->point1) and (point2->point3)
float lengthFactor = 0.3f; float lengthFactor = 0.3f;
//AngleGO: Triangle-Length: 3/4, Circle-Length: 1/4 //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 //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 //Will be used for z-Coordinate of the Angle
......
...@@ -20,6 +20,7 @@ public class ShinyThings : MonoBehaviour ...@@ -20,6 +20,7 @@ public class ShinyThings : MonoBehaviour
private bool lineDrawingActivated; private bool lineDrawingActivated;
private bool curveDrawingActivated; private bool curveDrawingActivated;
//These are only the vertices for the Curve
private int curveDrawingVertexCount = 36; private int curveDrawingVertexCount = 36;
private LineFact curveDrawingStartLine; private LineFact curveDrawingStartLine;
private Vector3 curveEndPoint; private Vector3 curveEndPoint;
...@@ -136,10 +137,11 @@ public void DeactivateLineDrawing(Fact startFact) ...@@ -136,10 +137,11 @@ public void DeactivateLineDrawing(Fact startFact)
this.lineDrawingActivated = false; 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) 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.startWidth = 0.05f;
lineRenderer.endWidth = 0.05f; lineRenderer.endWidth = 0.05f;
...@@ -148,24 +150,14 @@ public void ActivateCurveDrawing(Fact startFact) ...@@ -148,24 +150,14 @@ public void ActivateCurveDrawing(Fact startFact)
this.curveDrawingActivated = true; this.curveDrawingActivated = true;
curveDrawingStartLine = (LineFact)startFact; 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; //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;
//Determine which point of the line is closer to the cursor and initialize angleMiddlePoint
//angleMiddlePoint is needed for the Angle Preview angleMiddlePoint = curveDrawingPoint2.Point;
float Distance1 = (Facts.Find(x => x.Id == curveDrawingStartLine.Pid1).Representation.transform.position - curveEndPoint).magnitude; curveRadius = (curveEndPoint - curveDrawingPoint2.Point).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;
}
} }
public void UpdateCurveDrawing(Vector3 currentPosition) public void UpdateCurveDrawing(Vector3 currentPosition)
...@@ -178,6 +170,8 @@ public void UpdateCurveDrawing(Vector3 currentPosition) ...@@ -178,6 +170,8 @@ public void UpdateCurveDrawing(Vector3 currentPosition)
Vector3 curveMiddlePoint = angleMiddlePoint + curveRadius * (tempCenterPoint - angleMiddlePoint).normalized; Vector3 curveMiddlePoint = angleMiddlePoint + curveRadius * (tempCenterPoint - angleMiddlePoint).normalized;
linePositions = new List<Vector3>(); 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) for (float ratio = 0; ratio <= 1; ratio += 1.0f / this.curveDrawingVertexCount)
{ {
...@@ -187,6 +181,9 @@ public void UpdateCurveDrawing(Vector3 currentPosition) ...@@ -187,6 +181,9 @@ public void UpdateCurveDrawing(Vector3 currentPosition)
linePositions.Add(bezierPoint); linePositions.Add(bezierPoint);
} }
//End: LastPoint of Curve -> AngleMiddlePoint
linePositions.Add(((PointFact)Facts.Find(x => x.Id == curveDrawingStartLine.Pid2)).Point);
lineRenderer.positionCount = linePositions.Count; lineRenderer.positionCount = linePositions.Count;
lineRenderer.SetPositions(linePositions.ToArray()); lineRenderer.SetPositions(linePositions.ToArray());
......
fileFormatVersion: 2
guid: b543d9677cbde534ab69c0a229bfdb06
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment