Skip to content

Commit

Permalink
Optimize scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
mogoson committed Jan 24, 2018
1 parent a7b808e commit 6d80cc8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
17 changes: 13 additions & 4 deletions Assets/MGS-Machinery/Scripts/Hinge/CrankRocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions Assets/MGS-Machinery/Scripts/Hinge/CrankSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -134,7 +134,7 @@ protected override void DriveLinkBars()
/// <returns>Correct lsJoint angles.</returns>
protected Vector3 CorrectLSJointAngles(Vector3 angles)
{
return new Vector3(angles.x, 90, 0);
return new Vector3(angles.x, 90);
}
#endregion

Expand Down
2 changes: 1 addition & 1 deletion Assets/MGS-Machinery/Scripts/Mechanism/Mechanism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ protected Vector3 CorrectAngles(Vector3 angles)
/// <returns>Correct position.</returns>
protected Vector3 CorrectPosition(Vector3 position)
{
return new Vector3(position.x, position.y, 0);
return new Vector3(position.x, position.y);
}

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions Assets/MGS-Machinery/Scripts/Planimetry/Planimetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,13 @@ 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
re = Relation.External;
}
else
{
//Meet the linear equation.
if (p.y == L.k * p.x + L.b)
re = Relation.Coincidence;
else
Expand Down

0 comments on commit 6d80cc8

Please sign in to comment.