Skip to content

Commit

Permalink
Initial version of visual feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Sep 29, 2024
1 parent 980bf63 commit 65cdb92
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Runtime/Interaction/HPUIInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ protected override void OnEnable()
UpdateVisuals();
}


//FIXME: debug code
public Transform o1, o2, o3;
public LineRenderer lineRenderer;

/// <inheritdoc />
public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase updatePhase)
{
Expand Down Expand Up @@ -459,6 +464,9 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u
var secondItem = activePhalanges.Where(el => el.item != firstItem.item && relatedFignerJoints.Contains(el.item)).First();
Vector3 segmentVectorNormalized = (firstItem.pos - secondItem.pos).normalized;
Vector3 point = Vector3.Dot((thumbTipPos - secondItem.pos), segmentVectorNormalized) * segmentVectorNormalized + secondItem.pos;
o1.position = firstItem.pos;
o2.position = secondItem.pos;
o3.position = point;

Vector3 up = point - thumbTipPos;
Vector3 right = Vector3.Cross(up, attachTransform.forward);
Expand Down Expand Up @@ -494,6 +502,7 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u

// Debug.DrawLine(interactionPoint, interactionPoint + direction_.normalized * InteractionHoverRadius * 2, Color.blue);


foreach(Vector3 direction in directions)
{
bool validInteractable = false;
Expand Down Expand Up @@ -530,18 +539,34 @@ interactable is IHPUIInteractable hpuiInteractable &&
if (ShowDebugRayVisual)
{
Color rayColor = validInteractable ? Color.green : Color.red;
Debug.DrawLine(interactionPoint, interactionPoint + direction.normalized * InteractionHoverRadius, rayColor);
Debug.DrawLine(interactionPoint, interactionPoint + direction.normalized * InteractionSelectionRadius, rayColor);
}
}

float xEndPoint = 0, yEndPoint = 0, zEndPoint = 0, count = 0;

foreach (KeyValuePair<IHPUIInteractable, List<InteractionInfo>> kvp in tempValidTargets)
{
InteractionInfo smallest = kvp.Value.OrderBy(el => el.distance).First();
smallest.huristic = 1 / kvp.Value.Count;
foreach(InteractionInfo i in kvp.Value)
{
xEndPoint += i.point.x;
yEndPoint += i.point.y;
zEndPoint += i.point.z;
count++;
}

validTargets.Add(kvp.Key, smallest);
ListPool<InteractionInfo>.Release(kvp.Value);
}

if (lineRenderer != null)
{
lineRenderer.SetPosition(0, attachTransform.position);
lineRenderer.SetPosition(1, new Vector3(xEndPoint, yEndPoint, zEndPoint) / count);
}

tempValidTargets.Clear();
}
else
Expand Down

0 comments on commit 65cdb92

Please sign in to comment.