Search Unity

Inaccurate measurements by ruler in unity ARKit

Discussion in 'AR' started by ThoHer, Jul 11, 2018.

  1. ThoHer

    ThoHer

    Joined:
    Feb 27, 2018
    Posts:
    13
    I'm working on an application for room measurement, a ruler of sorts, using the ARKit in Unity3D. For this I am using raycasts to place objects (spheres), against the wall, and calculate the distance between those objects by getting the position of recognized walls, which the ARKit generates.

    The problems I have:

    • My placed objects are mostly a bit to far away from those ARKit walls.
    • Those objects are floating away when I move. So the measurements are not that precise.
    • Furthermore i want to create a gaze pointer, which assigns the wall angle and position by its distance
    The code (snippet):

    Code (CSharp):
    1. // generate first point
    2.     Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);;
    3.     RaycastHit hit;
    4.  
    5.     if (Physics.Raycast(ray, out hit))
    6.     {
    7.             if (!arModeWall)
    8.         {
    9.             if (!continueMeasure)
    10.             {
    11.                 if (!firstTouch)
    12.                 {
    13.                     //Debug.Log("FirstDot");
    14.                     firstTouch = true;
    15.                     doLine = true;
    16.  
    17.                     if (fromToCalculation != 1)
    18.                         fromToCalculation = 1;
    19.                     //continueMeasure = true;
    20.  
    21.                     Vector3 cameraPos = new Vector3(Camera.main.transform.position.x,  Camera.main.transform.position.y, +10);
    22.  
    23.                     //Create first sphere (nessacary for position)
    24.                     GameObject newPoint = Instantiate(distanceMeasuringSphere, hit.point, Quaternion.identity);
    25.                     newPoint.transform.parent = distanceMeasuringSphereContainer.transform;
    26.                     distanceMeasuringSphereArray.Add(newPoint);
    27.  
    28.                     //Create first LineRenderer (nessacary for Visuals)
    29.                     GameObject newLR = Instantiate(distanceMeasuringLr, distanceMeasuringSphereArray[distanceMeasuringSphereArray.Count - 1].gameObject.transform.position, Quaternion.identity);
    30.                     newLR.transform.parent = distanceMeasuringLrContainer.transform;
    31.                     newLR.GetComponent<LineRenderer>().SetPosition(0, distanceMeasuringSphereArray[distanceMeasuringSphereArray.Count - 1].gameObject.transform.position);
    32.                     distanceMeasuringLineRendererArray.Add(newLR);
    33.  
    34.                     //Create first Text (nessacary for Distance)
    35.                     GameObject newDistanceText = Instantiate(distanceMeasuringText, hit.point, Quaternion.identity);
    36.                     newDistanceText.transform.parent = distanceMeasuringTextContainer.transform;
    37.                     distanceMeasuringTextArray.Add(newDistanceText);
    38.  
    39.                 }

    It's the best solution I could think of to create a ruler.
    But I am open for improvement, Suggestions as well