private void ShowPrismaticLimits(ArticulationBody body, ArticulationBody parentBody, Matrix4x4 parentAnchorSpace)
{
// if prismatic and unlocked - nothing to visualise
if (body.linearLockX == ArticulationDofLock.FreeMotion || body.linearLockY == ArticulationDofLock.FreeMotion || body.linearLockZ == ArticulationDofLock.FreeMotion)
{
return;
}
float dashSize = 5;
// compute the primary axis of the prismatic
Vector3 primaryAxis = Vector3.zero;
ArticulationDrive drive = body.xDrive;
if (body.linearLockX == ArticulationDofLock.LimitedMotion)
{
primaryAxis = Vector3.right;
drive = body.xDrive;
}
else if (body.linearLockY == ArticulationDofLock.LimitedMotion)
{
primaryAxis = Vector3.up;
drive = body.yDrive;
}
else if (body.linearLockZ == ArticulationDofLock.LimitedMotion)
{
primaryAxis = Vector3.forward;
drive = body.zDrive;
}
// now show the valid movement along the axis as well as limits
using (new Handles.DrawingScope(parentAnchorSpace))
{
Vector3 lowerPoint = primaryAxis * drive.lowerLimit;
Vector3 upperPoint = primaryAxis * drive.upperLimit;
Quaternion orientation = Quaternion.LookRotation(primaryAxis);
Handles.color = Color.red;
Handles.CylinderHandleCap(0, lowerPoint, orientation, CapScale, EventType.Repaint);
Handles.color = Color.green;
Handles.CylinderHandleCap(0, upperPoint, orientation, CapScale, EventType.Repaint);
Handles.color = Color.white;
Handles.DrawDottedLine(lowerPoint, upperPoint, dashSize);
}
}