Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Where does FocusSquare get its position?

Discussion in 'AR' started by Jelmersb, Jul 26, 2018.

  1. Jelmersb

    Jelmersb

    Joined:
    Jul 12, 2016
    Posts:
    66
    In the UnityARKitplugin, FocusSquare.cs places the Focus Square cursor on a plane:
    Code (CSharp):
    1. #else
    2.         var screenPosition = Camera.main.ScreenToViewportPoint(center);
    3.         ARPoint point = new ARPoint {
    4.             x = screenPosition.x,
    5.             y = screenPosition.y
    6.         };
    7.  
    8.         // prioritize reults types
    9.         ARHitTestResultType[] resultTypes = {
    10.             ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
    11.             // if you want to use infinite planes use this:
    12.             //ARHitTestResultType.ARHitTestResultTypeExistingPlane,
    13.             //ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
    14.             //ARHitTestResultType.ARHitTestResultTypeFeaturePoint
    15.         };
    16.  
    17.         foreach (ARHitTestResultType resultType in resultTypes)
    18.         {
    19.         if (HitTestWithResultType (point, resultType))
    20.             {
    21.                 SquareState = FocusState.Found;
    22.                 return;
    23.             }
    24.         }
    25.  
    26.         #endif
    Can someone explain how the focussquare gets a position from this ARHitTest? I don't get it..
     
  2. zyonneo

    zyonneo

    Joined:
    Apr 13, 2018
    Posts:
    385
    I am new to ARkit. Olease verify again .From the below code i Believe it places the Focussquare at the centre of the screen
    1. var screenPosition = Camera.main.ScreenToViewportPoint(center);
    2. ARPoint point = new ARPoint {
    3. x = screenPosition.x,
    4. y = screenPosition.y
    5. };

    On hit how it places is the below code in the
    Code (CSharp):
    1. bool  HitTestWithResultType (ARPoint point, ARHitTestResultType resultTypes)
    We can find the below code in the above function.
    Code (CSharp):
    1. foundSquare.transform.position = UnityARMatrixOps.GetPosition (hitResult.worldTransform);
    2.                 foundSquare.transform.rotation = UnityARMatrixOps.GetRotation (hitResult.worldTransform);
     
    Jelmersb likes this.
  3. Jelmersb

    Jelmersb

    Joined:
    Jul 12, 2016
    Posts:
    66
    Ah yeah, I think you're right! Thanks, I'm not so advanced with C# :)