如何在ARkit中平行于X轴放置模型?

时间:2018-06-27 07:01:41

标签: unity3d arkit

嗨,我试图将模型放在触摸屏上。当焦点正方形被聚焦后,我触摸屏幕,模型在FocusedSquare的位置变为活动状态。也就是说,在检测到平面之后,模型被精确地放置在FocusSquared位置

model.transform.position =  foundSquare.transform.position;
model.transform.rotation= UnityARMatrixOps.GetRotation(hitResult.worldTransform);

我尝试了不同的旋转值组合,但模型不平行于X轴。它有点对角放置。我希望将它精确地放置在X轴的直线上。

bool HitTestWithResultType (ARPoint point, ARHitTestResultType resultTypes)
{
    List<ARHitTestResult> hitResults = UnityARSessionNativeInterface.GetARSessionNativeInterface ().HitTest (point, resultTypes);
    if (hitResults.Count > 0) {
        foreach (var hitResult in hitResults) {

                foundSquare.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
             foundSquare.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);
            //foundSquare.transform.rotation = Quaternion.Euler(0,-Input.compass.trueHeading,0);


             model.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);

            model.transform.rotation = Quaternion.Euler(0,1,0);

            //model.transform.rotation = foundSquare.transform.rotation;

           // model.transform.position = UnityARMatrixOps.GetPosition(hitResult.worldTransform);
            //model.transform.rotation = foundSquare.transform.rotation;

          /*  model.transform.position = foundSquare.transform.position;
            Vector3 temp = Camera.main.transform.position;
            temp.y = foundSquare.transform.position.y;
            model.transform.LookAt(temp); */


                //var dir = Camera.main.transform.position- model.transform.position;
            //model.transform.rotation = Quaternion.FromToRotation(Vector3.up, dir); ;

            //model.transform.rotation = TestPosition.rotation;
           // model.transform.rotation = UnityARMatrixOps.GetRotation(hitResult.worldTransform);

           // model.transform.rotation = Camera.main.transform.rotation;


          //  model.transform.rotation = foundSquare.transform.rotation;

            //model.transform.parent = null;
            //model.transform.parent = TestPosition

                Debug.Log(string.Format("x:{0:0.######} y:{1:0.######} z:{2:0.######}", foundSquare.transform.position.x, foundSquare.transform.position.y, foundSquare.transform.position.z));


                return true;
        }
    }
    return false;
}

注释行是我尝试过的不同方法。

0 个答案:

没有答案