HoloLens+unity 3D开发时的坐标系问题

1.坐标系系统

HoloLens:右手

Unity:左手

2.ARCamera的设置

坐标系系统的选择上,头戴式不受限制,Hololens受限于只能选择camera坐标系。

程序在PC上运行时,实际坐标系基准以选择的world center为准,作为场景中的固定对象

程序在Hololens上运行时,由于Hololens本身是自定位,所选择的center实际上无效,被Hololens所建立的地图坐标系所取代,作为全局基准坐标系,所有的对象均转换到该坐标系下。

3.相对坐标的转换

 

               Matrix4x4 Road2HoloLens = GetExtrinsic(imageTarget.transform);
            //获得hololens到road的转换矩阵,inv
            Matrix4x4 Hololens2Road = Road2HoloLens.inverse;
        //    Matrix4x4 Road2World=GetExtrinsic()
            Vector4 vy = Hololens2Road.GetColumn(1);
            Vector4 vz = Hololens2Road.GetColumn(2);

            Quaternion newQ = Quaternion.LookRotation(new Vector3(vz.x, vz.y, vz.z), new Vector3(vy.x, vy.y, vy.z));
            cylinder.transform.position = new Vector3(Hololens2Road.m03, Hololens2Road.m13, Hololens2Road.m23);
            cylinder.transform.rotation = newQ;


    Matrix4x4 GetExtrinsic(Transform trans)
    {
        Matrix4x4 rot = new Matrix4x4();
        rot.SetTRS(trans.position, trans.rotation, new Vector3(1, 1, 1));
        return rot;
    }

4.以方向向量定义物体的姿态

Unity场景中shi左手坐标系,再获取姿态四元数后,需要再绕X轴旋转90度

    {
        Vector3 posA = fingerData[keyA];
        Vector3 posB = fingerData[keyB];

        handCylinder[i * 3 + j].transform.position = GetMiddlePoint(posA, posB);
        handCylinder[i * 3 + j].transform.localScale = new Vector3(0.012f, (posA - posB).magnitude / 2, 0.012f);


        handCylinder[i * 3 + j].transform.rotation = Quaternion.LookRotation(posB - posA);
        //       transform.position = GetMiddlePoint(__AllFingerData_vector[1], __AllFingerData_vector[0]);
        handCylinder[i * 3 + j].transform.Rotate(new Vector3(1, 0, 0), 90);
    }

 

 

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值