From 6d80cc8a8cb92637c1f4e4b73779be4c2e441d7f Mon Sep 17 00:00:00 2001 From: Mogoson Date: Wed, 24 Jan 2018 22:57:08 +0800 Subject: [PATCH] Optimize scripts. --- .../MGS-Machinery/Scripts/Hinge/CrankRocker.cs | 17 +++++++++++++---- .../MGS-Machinery/Scripts/Hinge/CrankSlider.cs | 6 +++--- .../Scripts/Mechanism/Mechanism.cs | 2 +- .../Scripts/Planimetry/Planimetry.cs | 2 -- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Assets/MGS-Machinery/Scripts/Hinge/CrankRocker.cs b/Assets/MGS-Machinery/Scripts/Hinge/CrankRocker.cs index ef894bd..6cc0fb7 100644 --- a/Assets/MGS-Machinery/Scripts/Hinge/CrankRocker.cs +++ b/Assets/MGS-Machinery/Scripts/Hinge/CrankRocker.cs @@ -128,16 +128,25 @@ protected override void DriveLinkBars() } IsLock = false; - Point point; + var point = Point.Zero; if (points.Count == 1) point = points[0]; else { - //Adapt intertia and restrict. + //Adapt restrict and intertia. var rID = useRestrict ? 1 : 0; - point = useInertia ? points[rID] : (points[0].y - points[1].y >= 0 == isTop ? points[rID] : points[1 - rID]); + if (useInertia) + point = points[rID]; + else + { + var isPointTop = points[0].y - points[1].y >= 0; + if (isPointTop == isTop) + point = points[rID]; + else + point = points[1 - rID]; + } } - lrJoint.localPosition = new Vector3((float)point.x, (float)point.y, 0); + lrJoint.localPosition = new Vector3((float)point.x, (float)point.y); //Drive bars. rocker.DriveMechanism(); diff --git a/Assets/MGS-Machinery/Scripts/Hinge/CrankSlider.cs b/Assets/MGS-Machinery/Scripts/Hinge/CrankSlider.cs index 29bdfa5..4390841 100644 --- a/Assets/MGS-Machinery/Scripts/Hinge/CrankSlider.cs +++ b/Assets/MGS-Machinery/Scripts/Hinge/CrankSlider.cs @@ -116,12 +116,12 @@ protected override void DriveLinkBars() } IsLock = false; - Point point; + var point = Point.Zero; if (points.Count == 1) point = points[0]; else point = isRight ? points[0] : points[1]; - lsJoint.localPosition = new Vector3((float)point.x, (float)point.y, 0); + lsJoint.localPosition = new Vector3((float)point.x, (float)point.y); //Drive linkBar. linkBar.DriveMechanism(); @@ -134,7 +134,7 @@ protected override void DriveLinkBars() /// Correct lsJoint angles. protected Vector3 CorrectLSJointAngles(Vector3 angles) { - return new Vector3(angles.x, 90, 0); + return new Vector3(angles.x, 90); } #endregion diff --git a/Assets/MGS-Machinery/Scripts/Mechanism/Mechanism.cs b/Assets/MGS-Machinery/Scripts/Mechanism/Mechanism.cs index 76f9e26..59d0bf9 100644 --- a/Assets/MGS-Machinery/Scripts/Mechanism/Mechanism.cs +++ b/Assets/MGS-Machinery/Scripts/Mechanism/Mechanism.cs @@ -181,7 +181,7 @@ protected Vector3 CorrectAngles(Vector3 angles) /// Correct position. protected Vector3 CorrectPosition(Vector3 position) { - return new Vector3(position.x, position.y, 0); + return new Vector3(position.x, position.y); } /// diff --git a/Assets/MGS-Machinery/Scripts/Planimetry/Planimetry.cs b/Assets/MGS-Machinery/Scripts/Planimetry/Planimetry.cs index f8ff397..c93610a 100644 --- a/Assets/MGS-Machinery/Scripts/Planimetry/Planimetry.cs +++ b/Assets/MGS-Machinery/Scripts/Planimetry/Planimetry.cs @@ -374,7 +374,6 @@ public static Relation GetRelation(Line L, Point p) var re = Relation.Undefined; if (L.k == double.PositiveInfinity) { - //Meet the linear equation. if (p.x == L.b) re = Relation.Coincidence; else @@ -382,7 +381,6 @@ public static Relation GetRelation(Line L, Point p) } else { - //Meet the linear equation. if (p.y == L.k * p.x + L.b) re = Relation.Coincidence; else