Making object parallel (fit) to detected AR plane

Viewed 389

I tried the Measure App on iOS and I noticed that the reticle automatically fits the detected plane (for horizontal planes the reticle will be horizontal and for vertical planes, it will be vertical). Even for the inclined plane, it will rotate to fit it as it is a part of it.

I am building an AR application using AR foundation.

Currently, I am just rotate my reticle on vertical and horizontal planes using this code:

if (_arRaycastManager.Raycast(screenCenter, s_Hits, TrackableType.Planes))
{
    var hit = s_Hits[0];
    if (_arPlaneManager.GetPlane(s_Hits[0].trackableId).alignment == PlaneAlignment.HorizontalUp ||
        _arPlaneManager.GetPlane(s_Hits[0].trackableId).alignment == PlaneAlignment.HorizontalDown)
    {
        Reticle.transform.eulerAngles = new Vector3(90, 0, 0);
    }
    else if (_arPlaneManager.GetPlane(s_Hits[0].trackableId).alignment == PlaneAlignment.Vertical)
    {
        Reticle.transform.eulerAngles = new Vector3(0, 0, 0);
    }

    Reticle.transform.position = hit.pose.position;
}   

Is there a way to implement the behaviour of measure app reticle in my application.

1 Answers

Not sure but currently you are hard setting 0, 0, 0 or 90, 0, 0 as world space rotation.

This of course ignores completely how the planes are actually rotated within the Unity world coordinate system.

I think what you rather want to use is simply

Reticle.transform.rotation = hit.pose.rotation;

or if you can get the plane itself you could also use its normal like e.g.

Reticle.transform.up = _arPlaneManager.GetPlane(hit.trackableId).normal;

depending on the axis your Reticle should match the normal on.

Related