private void Awake() { string fViewJsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FViewTool", "FView.json"); if (!File.Exists(fViewJsonPath)) { UnityEngine.Debug.LogError("FView.Awake():先使用工具软件进行罗技摄像头的标定!"); return; } if (FARDll.fmFViewReadJson() == 0)//读取json成功 { //读坐标viewPosition int size = Marshal.SizeOf(viewPosition); IntPtr structPtr = Marshal.AllocHGlobal(size); FARDll.fmFViewGetPosition(structPtr); viewPosition = (Vector3)Marshal.PtrToStructure(structPtr, typeof(Vector3)); Marshal.FreeHGlobal(structPtr); //读旋转viewRotation size = Marshal.SizeOf(viewRotation); structPtr = Marshal.AllocHGlobal(size); FARDll.fmFViewGetRotation(structPtr); viewRotation = (Quaternion)Marshal.PtrToStructure(structPtr, typeof(Quaternion)); Marshal.FreeHGlobal(structPtr); } //使用标定结果设置CamRoot的坐标(注意坐标需要缩放) transform.localPosition = viewPosition * FCore.ViewerScale; transform.localRotation = viewRotation; }
private void SetupArCamTransform() { _camPoseMatrixInDisplaySpace = Matrix4x4.identity; string fViewJsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FViewTool", "FView.json"); if (!File.Exists(fViewJsonPath)) { UnityEngine.Debug.LogError("FView.Awake():先使用工具软件进行罗技摄像头的标定!"); return; } if (FARDll.fmFViewReadJson() == 0) { _viewPosition = Vector3.zero; int size = Marshal.SizeOf(_viewPosition); IntPtr structPtr = Marshal.AllocHGlobal(size); FARDll.fmFViewGetPosition(structPtr); _viewPosition = (Vector3)Marshal.PtrToStructure(structPtr, typeof(Vector3)); Marshal.FreeHGlobal(structPtr); _viewRotation = Quaternion.identity; size = Marshal.SizeOf(_viewRotation); structPtr = Marshal.AllocHGlobal(size); FARDll.fmFViewGetRotation(structPtr); _viewRotation = (Quaternion)Marshal.PtrToStructure(structPtr, typeof(Quaternion)); Marshal.FreeHGlobal(structPtr); _camPoseMatrixInDisplaySpace.SetTRS(_viewPosition * mrSystem.ViewerScale, _viewRotation, Vector3.one); } // transform.position = mrSystem.transform.localToWorldMatrix.MultiplyPoint(_viewPosition * mrSystem.ViewerScale); // transform.rotation = Quaternion.Euler(FCore.slantAngle, 0f, 0f) * mrSystem.transform.rotation * _viewRotation; }