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);
}