// We use Update() here, but be aware that unless ARController has been configured to // execute first (Unity Editor->Edit->Project Settings->Script Execution Order) then // state produced by this update may lag by one frame. void Update() { // Only query visibility if we are running in the Player. if (!Application.isPlaying) { return; } lock (loadLock) { //ARController.Log(LogTag + "ARTrackable.Update()"); if (UID == NO_ID) { visible = false; return; } if (pluginFunctions == null || !pluginFunctions.IsInited()) { visible = false; return; } float[] matrixRawArray = new float[16]; visible = pluginFunctions.arwQueryTrackableVisibilityAndTransformation(UID, matrixRawArray); //ARController.Log(LogTag + "ARTrackable.Update() UID=" + UID + ", visible=" + visible); if (visible) { matrixRawArray[12] *= 0.001f; // Scale the position from artoolkitX units (mm) into Unity units (m). matrixRawArray[13] *= 0.001f; matrixRawArray[14] *= 0.001f; Matrix4x4 matrixRaw = ARUtilityFunctions.MatrixFromFloatArray(matrixRawArray); //.Log("arwQueryTrackableTransformation(" + UID + ") got matrix: [" + Environment.NewLine + matrixRaw.ToString("F3").Trim() + "]"); // artoolkitX uses right-hand coordinate system where the marker lies in x-y plane with right in direction of +x, // up in direction of +y, and forward (towards viewer) in direction of +z. // Need to convert to Unity's left-hand coordinate system where marker lies in x-y plane with right in direction of +x, // up in direction of +y, and forward (towards viewer) in direction of -z. transformationMatrix = ARUtilityFunctions.LHMatrixFromRHMatrix(matrixRaw); } } }