Hololens与ARcore结合实现第三视角(四)

手机定位

1.1使用ARcore定位

Hololens与ARcore结合实现第三视角(四)_第1张图片Hololens与ARcore结合实现第三视角(四)_第2张图片

 

public class ARLocate : BaseSendMessage {

    public static ARLocate Instance;
    public Transform Root;
    public GameObject ScanImage;
    public Transform CamTransform;
    public GameObject PhonePos;
    public GameObject PhoneScreen; 
    public Vector2 PhoneScreenSize;//横屏状态,手机的真实尺寸,x--长边
    public Vector2 PhoneCamCenter;//横屏状态,手机摄像机中心点到屏幕中心点的坐标
    private void Awake()
    {
        base.Awake();
        Instance = this;
    }
    void Start () {
        if (Screen.orientation != ScreenOrientation.LandscapeLeft)
        {
            Screen.orientation = ScreenOrientation.LandscapeLeft;
        }
        PhoneScreen.transform.localScale = new Vector3(PhoneScreenSize.x, 0.005f, PhoneScreenSize.y) ;
    }

    public void StartScan()
    {
        print("StartScan...");
        ScanImage.SetActive(true);
    }
    public void SendArCoreLocation(float posX, float posY, float posZ, float rotX, float rotY, float rotZ)
    {
        print("SendArCoreLocation:" + posX + "," + posY + "," + posZ + ";" + rotX + "," + rotY + "," + rotZ);
        ScanImage.SetActive(false);

        GameObject go = new GameObject();
        go.transform.localEulerAngles = new Vector3(CamTransform.localEulerAngles.x - 90,
            CamTransform.localEulerAngles.y, CamTransform.localEulerAngles.z);
        go.transform.position = CamTransform.position+ new Vector3(-PhoneCamCenter.x, 0, -PhoneCamCenter.y);

        Root.SetParent(go.transform);

        Root.localEulerAngles = new Vector3(rotX,rotY,rotZ);
        Root.localPosition = new Vector3(posX,posY, posZ);

    }
    public void ShowPos()
    {
        GameObject go = new GameObject();
        go.transform.localEulerAngles = new Vector3(CamTransform.localEulerAngles.x-90,
            CamTransform.localEulerAngles.y, CamTransform.localEulerAngles.z);
        go.transform.position = CamTransform.position;

        PhonePos.transform.SetParent(go.transform);
        PhonePos.transform.localEulerAngles = Vector3.zero;
        PhonePos.transform.localPosition = new Vector3 (-PhoneCamCenter.x,0, -PhoneCamCenter.y);
    }
}

 

你可能感兴趣的:(Hololens开发)