Skip to content

Commit

Permalink
#161 control spec gizmos
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Jan 10, 2024
1 parent 79f0c03 commit 021fa81
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CCL.Types/Proxies/Controls/ButtonProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,13 @@ private void OnValidate()
[Header("VR")]
public bool disableTouchUse;
public VRButtonAlias overrideUseButton;

private void OnDrawGizmos()
{
Vector3 pressedOffset = transform.TransformPoint(Vector3.back * linearLimit);

Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, pressedOffset);
}
}
}
75 changes: 75 additions & 0 deletions CCL.Types/Proxies/Controls/LeverProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,80 @@ private void OnValidate()
public AudioClip drag;
public AudioClip limitHit;
public bool limitVibration;

protected const float GIZMO_RADIUS = 0.1f;
protected const int GIZMO_SEGMENTS = 40;
protected static readonly Color START_COLOR = new Color(0.65f, 0, 0);
protected static readonly Color END_COLOR = new Color(0, 0.65f, 0);

private void OnDrawGizmos()
{
Color startColor = invertDirection ? END_COLOR : START_COLOR;
Color endColor = invertDirection ? START_COLOR : END_COLOR;

Vector3 massCenter = ModelUtil.GetModelCenterline(gameObject);
Vector3 massZeroVector = transform.InverseTransformPoint(massCenter);
Vector3 gizmoZeroVector = Vector3.ProjectOnPlane(massZeroVector, jointAxis);

float massLength = massZeroVector.magnitude;
Vector3 massPivot = Vector3.Project(massZeroVector, jointAxis);

Gizmos.color = Color.blue;
Gizmos.DrawLine(transform.position, transform.TransformPoint(massPivot));

if (useSteppedJoint && (notches > 0))
{
float rayCount = notches - 1;

// draw ray segments
for (int i = 0; i <= rayCount; i++)
{
Gizmos.color = Color.Lerp(startColor, endColor, i / rayCount);

float rotateAngle = Mathf.Lerp(jointLimitMin, jointLimitMax, i / rayCount);
Quaternion rotation = Quaternion.AngleAxis(rotateAngle, jointAxis);

// projected sweep
Vector3 rayVector = transform.TransformPoint((rotation * gizmoZeroVector) * GIZMO_RADIUS);
Gizmos.DrawLine(transform.position, rayVector);

// center of mass sweep
rayVector = transform.TransformPoint(rotation * massZeroVector);
Gizmos.DrawLine(transform.TransformPoint(massPivot), rayVector);
}
}
else
{
// draw semi-circle
Vector3 lastVector = transform.position;
Vector3 lastMassVector = transform.TransformPoint(massPivot);

for (int i = 0; i <= GIZMO_SEGMENTS; i++)
{
Gizmos.color = Color.Lerp(startColor, endColor, (float)i / GIZMO_SEGMENTS);

float rotateAngle = Mathf.Lerp(jointLimitMin, jointLimitMax, (float)i / GIZMO_SEGMENTS);
Quaternion rotation = Quaternion.AngleAxis(rotateAngle, jointAxis);

// projected sweep
Vector3 nextVector = transform.TransformPoint((rotation * gizmoZeroVector) * GIZMO_RADIUS);
Vector3 nextMassVector = transform.TransformPoint(rotation * massZeroVector);

if (i == 0 || i == GIZMO_SEGMENTS)
{
Gizmos.DrawLine(transform.position, nextVector);
Gizmos.DrawLine(transform.TransformPoint(massPivot), nextMassVector);
}
if (i != 0)
{
Gizmos.DrawLine(lastVector, nextVector);
Gizmos.DrawLine(lastMassVector, nextMassVector);
}

lastVector = nextVector;
lastMassVector = nextMassVector;
}
}
}
}
}
8 changes: 8 additions & 0 deletions CCL.Types/Proxies/Controls/PullerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,13 @@ private void OnValidate()
public AudioClip notch;
public AudioClip drag;
public AudioClip limitHit;

private void OnDrawGizmos()
{
Vector3 movedOffset = transform.TransformPoint(Vector3.up * linearLimit);

Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, movedOffset);
}
}
}
44 changes: 44 additions & 0 deletions CCL.Types/Proxies/Controls/RotaryProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,49 @@ private void OnValidate()
public AudioClip notch;
public AudioClip drag;
public AudioClip limitHit;


protected const int GIZMO_SLICE_SIZE = 10;
protected const float GIZMO_RADIUS = 0.02f;
protected static readonly Color START_COLOR = new Color(0.65f, 0, 0);
protected static readonly Color END_COLOR = new Color(0, 0.65f, 0);

private void OnDrawGizmos()
{
Vector3 lastVector = transform.position;
Vector3 lastOpp = transform.position;

foreach (float end in new[] { jointLimitMin, jointLimitMax })
{
if (jointStartingPos != end)
{
float totalSweep = Mathf.Abs(end - jointStartingPos);
int gizmoSegments = Mathf.FloorToInt(totalSweep / GIZMO_SLICE_SIZE);

for (int i = 0; i <= gizmoSegments; i++)
{
Gizmos.color = Color.Lerp(START_COLOR, END_COLOR, (float)i / gizmoSegments);
Vector3 radialVector = (Quaternion.AngleAxis(
Mathf.Lerp(jointStartingPos, end, (float)i / gizmoSegments), jointAxis)
* Vector3.forward).normalized;

Vector3 nextVector = transform.TransformPoint(radialVector * GIZMO_RADIUS);
Vector3 oppositeVector = transform.TransformPoint(radialVector * -GIZMO_RADIUS);

if (i != 0)
{
Gizmos.DrawLine(lastVector, nextVector);
Gizmos.DrawLine(lastOpp, oppositeVector);
}

Gizmos.DrawLine(transform.position, nextVector);
Gizmos.DrawLine(transform.position, oppositeVector);

lastVector = nextVector;
lastOpp = oppositeVector;
}
}
}
}
}
}
44 changes: 44 additions & 0 deletions CCL.Types/Proxies/Controls/ToggleSwitchProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,49 @@ private void OnValidate()
[Header("VR")]
public Vector3 touchInteractionAxis = Vector3.up;
public bool disableTouchUse;


protected const float GIZMO_RADIUS = 0.05f;
protected const int GIZMO_SEGMENTS = 10;
protected static readonly Color START_COLOR = new Color(0.65f, 0, 0);
protected static readonly Color END_COLOR = new Color(0, 0.65f, 0);

private void OnDrawGizmos()
{
Vector3 massCenter = ModelUtil.GetModelCenterline(gameObject);
Vector3 massZeroVector = transform.InverseTransformPoint(massCenter);
Vector3 gizmoZeroVector = Vector3.ProjectOnPlane(massZeroVector, jointAxis);
Vector3 massPivot = Vector3.Project(massZeroVector, jointAxis);

Vector3 lastVector = transform.position;
Vector3 lastMassVector = transform.TransformPoint(massPivot);

// draw ray segments
for (int i = 0; i <= GIZMO_SEGMENTS; i++)
{
Gizmos.color = Color.Lerp(START_COLOR, END_COLOR, (float)i / GIZMO_SEGMENTS);

float rotateAngle = Mathf.Lerp(jointLimitMin, jointLimitMax, (float)i / GIZMO_SEGMENTS);
Quaternion rotation = Quaternion.AngleAxis(rotateAngle, jointAxis);

// projected sweep
Vector3 nextVector = transform.TransformPoint((rotation * gizmoZeroVector) * GIZMO_RADIUS);
Vector3 nextMassVector = transform.TransformPoint(rotation * massZeroVector);

if (i == 0 || i == GIZMO_SEGMENTS)
{
Gizmos.DrawLine(transform.position, nextVector);
Gizmos.DrawLine(transform.TransformPoint(massPivot), nextMassVector);
}
if (i != 0)
{
Gizmos.DrawLine(lastVector, nextVector);
Gizmos.DrawLine(lastMassVector, nextMassVector);
}

lastVector = nextVector;
lastMassVector = nextMassVector;
}
}
}
}
40 changes: 40 additions & 0 deletions CCL.Types/Proxies/Indicators/IndicatorGaugeProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,45 @@ public class IndicatorGaugeProxy : IndicatorProxy
public bool unclamped;
public Vector3 rotationAxis = Vector3.forward;
public float gizmoRadius = 0.1f;


protected const float GIZMO_RADIUS = 0.1f;
protected const int GIZMO_SEGMENTS = 20;
protected static readonly Color END_COLOR = new Color(0, 0, 0.65f);
protected static readonly Color START_COLOR = new Color(0.65f, 0, 0);

private void OnDrawGizmos()
{
if (!needle)
{
return;
}

Vector3 massCenter = ModelUtil.GetModelCenterline(gameObject);
Vector3 massZeroVector = transform.InverseTransformPoint(massCenter);
Vector3 massPivot = Vector3.Project(massZeroVector, rotationAxis);

Vector3 lastVector = Vector3.zero;
for (int i = 0; i <= GIZMO_SEGMENTS; i++)
{
Color segmentColor = Color.Lerp(START_COLOR, END_COLOR, (float)i / GIZMO_SEGMENTS);

Quaternion rotation = Quaternion.AngleAxis(Mathf.Lerp(minAngle, maxAngle, (float)i / GIZMO_SEGMENTS), rotationAxis);
Vector3 nextVector = transform.TransformPoint(rotation * massZeroVector);

Gizmos.color = segmentColor;
if (i == 0 || i == GIZMO_SEGMENTS)
{
Gizmos.DrawLine(transform.TransformPoint(massPivot), nextVector);
}

if (i != 0)
{
Gizmos.DrawLine(lastVector, nextVector);
}

lastVector = nextVector;
}
}
}
}
21 changes: 21 additions & 0 deletions CCL.Types/Proxies/Indicators/IndicatorScalerProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,26 @@ public class IndicatorScalerProxy : IndicatorProxy
public Transform indicatorToScale;
public Vector3 startScale = Vector3.one;
public Vector3 endScale = Vector3.one;

public void OnDrawGizmos()
{
if (!indicatorToScale) return;

Vector3 worldCenter = ModelUtil.GetModelCenterline(gameObject);
Vector3 localCenter = transform.InverseTransformPoint(worldCenter);
Vector3 worldStart = transform.TransformPoint(Vector3.Scale(localCenter, startScale));
Vector3 worldEnd = transform.TransformPoint(Vector3.Scale(localCenter, endScale));

float tickScale = Vector3.Distance(worldStart, worldEnd) * 0.1f;
Vector3 axis = (worldEnd - worldStart).normalized;
Vector3 perpendicular = (axis.z < axis.x) ? new Vector3(axis.y, -axis.x, 0) : new Vector3(0, -axis.z, axis.y);

Gizmos.color = Color.blue;
Gizmos.DrawLine(worldStart, worldEnd);
Gizmos.color = Color.red;
Gizmos.DrawLine(worldStart + perpendicular * tickScale, worldStart + perpendicular * -tickScale);
Gizmos.color = Color.green;
Gizmos.DrawLine(worldEnd + perpendicular * tickScale, worldEnd + perpendicular * -tickScale);
}
}
}
19 changes: 19 additions & 0 deletions CCL.Types/Proxies/Indicators/IndicatorSliderProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,24 @@ public class IndicatorSliderProxy : IndicatorProxy
public Transform pointer;
public Vector3 startPosition = -Vector3.right;
public Vector3 endPosition = Vector3.right;

public void OnDrawGizmos()
{
if (!pointer) return;

Vector3 worldStart = pointer.parent.TransformPoint(startPosition);
Vector3 worldEnd = pointer.parent.TransformPoint(endPosition);

float tickScale = Vector3.Distance(startPosition, endPosition) * 0.1f;
Vector3 axis = (worldEnd - worldStart).normalized;
Vector3 perpendicular = (axis.z < axis.x) ? new Vector3(axis.y, -axis.x, 0) : new Vector3(0, -axis.z, axis.y);

Gizmos.color = Color.blue;
Gizmos.DrawLine(worldStart, worldEnd);
Gizmos.color = Color.red;
Gizmos.DrawLine(worldStart + perpendicular * tickScale, worldStart + perpendicular * -tickScale);
Gizmos.color = Color.green;
Gizmos.DrawLine(worldEnd + perpendicular * tickScale, worldEnd + perpendicular * -tickScale);
}
}
}

0 comments on commit 021fa81

Please sign in to comment.