Skip to content

Commit

Permalink
IR Build Aid improvements
Browse files Browse the repository at this point in the history
Presets are now shown and colors indicate the direction.
  • Loading branch information
ZiwKerman committed Apr 24, 2016
1 parent 788601c commit ccf9be4
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 56 deletions.
Binary file modified InfernalRobotics/.vs/InfernalRobotics/InfernalRobotics.scgdat
Binary file not shown.
60 changes: 53 additions & 7 deletions InfernalRobotics/InfernalRobotics/Gui/IRBuildAid/BasicInterval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class BasicInterval : LinePrimitive

protected LineRenderer currentPosMarker, defaultPosMarker;

protected List<LineRenderer> presetsPosMarkers = new List<LineRenderer>();

public float offset;
public Vector3 mainStartPoint;
public Vector3 mainEndPoint;
Expand All @@ -26,10 +28,12 @@ public class BasicInterval : LinePrimitive
public float width = 0.25f;

public float currentPosition = 0f;
public float defaultPosition = 0f;
public Color currentPositionColor = new Color(0f, 1f, 0f, 0.5f);

public float[] presetPositions;
public float defaultPosition = 0f;

public List<float> presetPositions = new List<float>();
public Color presetPositionsColor = new Color(1f, 0.75f, 0f, 0.5f);
public override bool enabled
{
get { return base.enabled; }
Expand All @@ -46,6 +50,8 @@ protected override void Awake ()
{
base.Awake ();

presetsPosMarkers.Clear();

if (lineRenderers.Count == 0)
{
//main line
Expand Down Expand Up @@ -79,9 +85,9 @@ protected override void Awake ()

currentPosMarker = lineRenderers [3];
defaultPosMarker = lineRenderers [4];
}


}

mainLine.SetVertexCount (2);
endPoint1.SetVertexCount(2);
endPoint2.SetVertexCount(2);
Expand All @@ -90,6 +96,37 @@ protected override void Awake ()
defaultPosMarker.SetVertexCount(2);
}

public void SetMainLineColors(Color startColor, Color endColor)
{
mainLine.SetColors(startColor, endColor);
}

public void SetPresetPositions(List<float> newList)
{
presetsPosMarkers.Clear();

for(int i=5; i< lineRenderers.Count; i++)
{
//remove outdated linerenders
Destroy(lineRenderers[i]);
lineRenderers.RemoveAt(i);
}

presetPositions = newList;

for (int i = 0; i < presetPositions.Count; i++)
{
var pos = presetPositions[i];
var posRenderer = CreateNewRenderer();
posRenderer.material = material;
lineRenderers.Add(posRenderer);
presetsPosMarkers.Add(posRenderer);
posRenderer.SetVertexCount(2);
posRenderer.SetColors(presetPositionsColor, presetPositionsColor);
posRenderer.gameObject.layer = gameObject.layer;
}
}

protected override void LateUpdate ()
{
base.LateUpdate ();
Expand All @@ -111,7 +148,7 @@ protected override void LateUpdate ()

mainLine.SetPosition (0, mainStartPoint);
mainLine.SetPosition (1, mainEndPoint);

endPoint1.SetPosition (0, mainStartPoint + cross * width * 2);
endPoint1.SetPosition (1, mainStartPoint - cross * width * 2);

Expand All @@ -120,8 +157,7 @@ protected override void LateUpdate ()

currentPosMarker.SetWidth (width*2, 0.01f);

var c = new Color (0f, 1f, 0f, 0.5f);
currentPosMarker.SetColors (c, c);
currentPosMarker.SetColors(currentPositionColor, currentPositionColor);

currentPosMarker.SetPosition (0, currentPosPoint - cross * width * 2);
currentPosMarker.SetPosition (1, currentPosPoint);
Expand All @@ -130,6 +166,16 @@ protected override void LateUpdate ()

defaultPosMarker.SetPosition (0, defaultPosPoint + cross * width * 2);
defaultPosMarker.SetPosition (1, defaultPosPoint);

for (int i = 0; i < presetsPosMarkers.Count; i++)
{
var pos = presetPositions[i];
var posMarker = presetsPosMarkers[i];
var posPoint = transform.position + norm * pos;
posMarker.SetPosition(0, posPoint - cross * width * 2);
posMarker.SetPosition(1, posPoint);
posMarker.SetColors(presetPositionsColor, presetPositionsColor);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CircularInterval : BasicInterval
//arc angle in degrees
public float arcAngle = 30;
public float offsetAngle = 0f;

protected override void Start ()
{
base.Start ();
Expand All @@ -37,6 +37,15 @@ protected override void Start ()
defaultPosMarker.useWorldSpace = false;
defaultPosMarker.SetColors(lineColor, lineColor);

for (int i = 0; i < presetsPosMarkers.Count; i++)
{
var posRenderer = presetsPosMarkers[i];
posRenderer.useWorldSpace = false;
posRenderer.SetVertexCount(2);
posRenderer.SetColors(presetPositionsColor, presetPositionsColor);
posRenderer.gameObject.layer = gameObject.layer;
}

mainLine.gameObject.layer = gameObject.layer;
endPoint1.gameObject.layer = gameObject.layer;
endPoint2.gameObject.layer = gameObject.layer;
Expand Down Expand Up @@ -132,6 +141,26 @@ protected override void LateUpdate ()
y = Mathf.Cos (a) * (circleRadius);
v = new Vector3(x, y, z);
defaultPosMarker.SetPosition(1, v);

for (int i = 0; i < presetsPosMarkers.Count; i++)
{
var posMarker = presetsPosMarkers[i];
var pos = presetPositions[i];

posMarker.SetColors(presetPositionsColor, presetPositionsColor);
posMarker.SetWidth(width * 2, 0.01f);

a = Mathf.Deg2Rad * pos;
x = Mathf.Sin(a) * (circleRadius - width * 2);
y = Mathf.Cos(a) * (circleRadius - width * 2);
v = new Vector3(x, y, z);
posMarker.SetPosition(0, v);

x = Mathf.Sin(a) * (circleRadius);
y = Mathf.Cos(a) * (circleRadius);
v = new Vector3(x, y, z);
posMarker.SetPosition(1, v);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public class IRBuildAidManager : MonoBehaviour
{
private static IRBuildAidManager instance;

public static Color mainLineColor1 = new Color(1f, 0.75f, 0, 0.5f);
public static Color mainLineColor2 = new Color(0.5f, 1f, 0, 0.5f);
public static Color presetPositionsColor = new Color(1f, 0.75f, 0f, 0.5f);

public static IRBuildAidManager Instance
{
get { return instance;}
Expand Down Expand Up @@ -73,6 +77,18 @@ public void UpdateServoRange(IServo s)
currentRange.offsetAngle = s.Mechanism.MinPositionLimit;
currentRange.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position);
currentRange.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition);

if (s.RawServo.PresetPositions != null)
currentRange.SetPresetPositions(s.RawServo.PresetPositions);

if (s.Motor.IsAxisInverted)
{
currentRange.SetMainLineColors(mainLineColor2, mainLineColor1);
}
else
{
currentRange.SetMainLineColors(mainLineColor1, mainLineColor2);
}
}
else
{
Expand All @@ -83,7 +99,21 @@ public void UpdateServoRange(IServo s)
currentRange.offset = s.Mechanism.MinPositionLimit;
currentRange.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position);
currentRange.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition);

if (s.RawServo.PresetPositions != null)
currentRange.SetPresetPositions(s.RawServo.PresetPositions);

if (s.Motor.IsAxisInverted)
{
currentRange.SetMainLineColors(mainLineColor2, mainLineColor1);
}
else
{
currentRange.SetMainLineColors(mainLineColor1, mainLineColor2);
}
}


}

public void DrawServoRange (IServo s)
Expand Down Expand Up @@ -112,14 +142,27 @@ public void DrawServoRange (IServo s)
aid.transform.rotation = obj.transform.rotation;
aid.width = 0.05f;

var c = new Color (1, 1, 0, 0.5f);
aid.UpdateColor (c);
aid.UpdateColor (mainLineColor1);

if (s.Motor.IsAxisInverted)
{
aid.SetMainLineColors(mainLineColor2, mainLineColor1);
}
else
{
aid.SetMainLineColors(mainLineColor1, mainLineColor2);
}

aid.UpdateWidth (0.05f);
aid.arcAngle = (s.Mechanism.MaxPositionLimit - s.Mechanism.MinPositionLimit);
aid.offsetAngle = s.Mechanism.MinPositionLimit;
aid.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position);
aid.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition);

aid.presetPositionsColor = presetPositionsColor;
if (s.RawServo.PresetPositions != null)
aid.SetPresetPositions(s.RawServo.PresetPositions);

aid.enabled = true;

lines.Add (s, aid);
Expand Down Expand Up @@ -148,10 +191,22 @@ public void DrawServoRange (IServo s)
aid.currentPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.Position);
aid.defaultPosition = s.RawServo.Translator.ToInternalPos(s.Mechanism.DefaultPosition);

var c = new Color (1, 1, 0, 0.5f);
aid.UpdateColor (c);
aid.UpdateColor(mainLineColor1);
if (s.Motor.IsAxisInverted)
{
aid.SetMainLineColors(mainLineColor2, mainLineColor1);
}
else
{
aid.SetMainLineColors(mainLineColor1, mainLineColor2);
}
aid.UpdateWidth (0.05f);

aid.presetPositionsColor = presetPositionsColor;

if (s.RawServo.PresetPositions != null)
aid.SetPresetPositions(s.RawServo.PresetPositions);

lines.Add (s, aid);
}
}
Expand Down
Loading

0 comments on commit ccf9be4

Please sign in to comment.