public InsightARUserHitAnchor GetHitTestResult(float pointX, float pointY) { InsightARUserHitAnchor anchor = new InsightARUserHitAnchor() { identifier = "", position = Vector3.zero, isValid = 0, }; #if UNITY_ANDROID || UNITY_IOS if (CurrentState != InsightARState.Tracking) { return(anchor); } InsightARVector2 poi = new InsightARVector2(); #if UNITY_ANDROID if (InsightARNative.isUseHWAR()) { poi.y = Screen.height * pointY; poi.x = Screen.width * pointX; } else #endif { var screenPosition = Camera.main.ScreenToViewportPoint(new Vector3(pointX, pointY, 0f)); poi.x = screenPosition.x; poi.y = screenPosition.y; } InsightARAnchorData anchorData = InsightARNative.iarGetLastHitTestResult(poi); anchor = InsightARUtility.GetUserHitAnchorFromAnchorData(anchorData); #endif return(anchor); }
public static InsightARUserHitAnchor GetUserHitAnchorFromAnchorData(InsightARAnchorData anchor) { InsightARUserHitAnchor arUserHitAnchor = new InsightARUserHitAnchor(); arUserHitAnchor.identifier = string.Copy(anchor.identifier); #if UNITY_ANDROID if (InsightARNative.isUseHWAR()) { float[] cent = new float[] { anchor.center.x, anchor.center.y, anchor.center.z }; float[] quat = new float[] { anchor.rotation.x, anchor.rotation.y, anchor.rotation.z, anchor.rotation.w }; Vector3 camPos; Quaternion camRot; InsightARMath.Cvt_GLPose_UnityPose(cent, quat, out camPos, out camRot); arUserHitAnchor.position = camPos; arUserHitAnchor.rotation = camRot; } else #endif { arUserHitAnchor.position = new Vector3(anchor.transform.column3.x, anchor.transform.column3.y, anchor.transform.column3.z); } arUserHitAnchor.isValid = anchor.isValid; return(arUserHitAnchor); }
private static void onAnchorUpdated(InsightARAnchorData anchor, IntPtr pHandler) { if (anchor.type == InsightARAnchorType.Plane) { InsightARPlaneAnchor arPlaneAnchor = InsightARUtility.GetPlaneAnchorFromAnchorData(anchor); listAnchorsToUpdate.Add(arPlaneAnchor); } }
public static InsightARPlaneAnchor GetPlaneAnchorFromAnchorData(InsightARAnchorData anchor) { InsightARPlaneAnchor arPlaneAnchor = new InsightARPlaneAnchor(); arPlaneAnchor.identifier = string.Copy(anchor.identifier); #if UNITY_ANDROID if (InsightARNative.isUseHWAR()) { float[] tran = new float[] { anchor.center.x, anchor.center.y, anchor.center.z }; float[] quat = new float[] { anchor.rotation.x, anchor.rotation.y, anchor.rotation.z, anchor.rotation.w }; Matrix4x4 glWorld_T_glLocal = Matrix4x4.TRS( new Vector3(tran [0], tran [1], tran [2]), new Quaternion(quat [0], quat [1], quat [2], quat [3]), Vector3.one ); Matrix4x4 unityWorld_T_glWorld = Matrix4x4.Scale(new Vector3(1, 1, -1)); Matrix4x4 unityWorld_T_unityLocal = unityWorld_T_glWorld * glWorld_T_glLocal * unityWorld_T_glWorld.inverse; arPlaneAnchor.center = unityWorld_T_unityLocal.GetColumn(3); arPlaneAnchor.rotation = Quaternion.LookRotation(unityWorld_T_unityLocal.GetColumn(2), unityWorld_T_unityLocal.GetColumn(1)); arPlaneAnchor.extent = new Vector3(anchor.extent.x, 1.0f, anchor.extent.z); } else #endif { Matrix4x4 matrix = new Matrix4x4(); matrix.SetColumn(0, new Vector4(anchor.transform.column0.x, anchor.transform.column0.y, anchor.transform.column0.z, anchor.transform.column0.w)); matrix.SetColumn(1, new Vector4(anchor.transform.column1.x, anchor.transform.column1.y, anchor.transform.column1.z, anchor.transform.column1.w)); matrix.SetColumn(2, new Vector4(anchor.transform.column2.x, anchor.transform.column2.y, anchor.transform.column2.z, anchor.transform.column2.w)); matrix.SetColumn(3, new Vector4(anchor.transform.column3.x, anchor.transform.column3.y, anchor.transform.column3.z, anchor.transform.column3.w)); arPlaneAnchor.rotation = GetRotation(matrix); arPlaneAnchor.extent = new Vector3(anchor.extent.x, anchor.extent.y, anchor.extent.z); #if UNITY_ANDROID arPlaneAnchor.center = new Vector3(anchor.center.x, anchor.center.y, anchor.center.z); #elif UNITY_IOS arPlaneAnchor.center = GetPosition(matrix); //Debug.Log(arPlaneAnchor.center.ToString("f3")); #endif arPlaneAnchor.isValid = anchor.isValid; } return(arPlaneAnchor); }