private void Update() { if (!initialized) { return; } var oFrame = oFrameBuffer.peek(); if (!oFrame.OnSome) { Debug.Log("[EasyAR] oframe is null"); return; } var iFrame = oFrame.Value.inputFrame(); if (iFrame == null) { oFrame.Value.Dispose(); Debug.Log("[EasyAR] iFrame is null"); return; } var index = iFrame.index(); if (frameIndex == index) { oFrame.Value.Dispose(); iFrame.Dispose(); return; } frameIndex = index; var camParams = iFrame.cameraParameters(); if (camParams == null) { Debug.Log("[EasyAR] camParams is null"); return; } var screenRotation = Utility.GetScreenRotation(); var imageRotationDegree = camParams.imageOrientation(screenRotation); var imageRotation = (float)(imageRotationDegree) / 180.0f * Mathf.PI; Matrix4x4 rotationMatrixGlobal = Matrix4x4.identity; rotationMatrixGlobal.m00 = Mathf.Cos(-imageRotation); rotationMatrixGlobal.m01 = -Mathf.Sin(-imageRotation); rotationMatrixGlobal.m10 = Mathf.Sin(-imageRotation); rotationMatrixGlobal.m11 = Mathf.Cos(-imageRotation); args.ImageRotationMatrixGlobal = rotationMatrixGlobal; args.IFrame = iFrame; args.OFrame = oFrame.Value; args.CameraParam = camParams; if (ImgTracker != null) { ImgTracker.UpdateFrame(args); } if (SfTracker != null) { SfTracker.UpdateFrame(args); } if (CameraBackgroundRenderer != null) { CameraBackgroundRenderer.UpdateFrame(args); } oFrame.Value.Dispose(); iFrame.Dispose(); camParams.Dispose(); }
/// <summary> /// Detects new output frames and updates the camera, then passes the output frame through an event to update the foreground /// </summary> /// <param name="timeStep"></param> protected override void OnUpdate(float timeStep) { if (paused) { return; } Optional <OutputFrame> optionalOframe = OutputFrameBuffer.peek(); if (optionalOframe.OnSome) { OutputFrame oframe = optionalOframe.Some; Optional <InputFrame> optionalIframe = oframe.inputFrame(); if (optionalIframe.OnSome) { InputFrame iframe = optionalIframe.Some; CameraParameters cameraParameters = iframe.cameraParameters(); if (cameraParameters != null) { Image image = iframe.image(); float aspectRatio = (float)(DeviceDisplay.MainDisplayInfo.Width / DeviceDisplay.MainDisplayInfo.Height); int rotation = 0; switch (DeviceDisplay.MainDisplayInfo.Rotation) { case DisplayRotation.Rotation90: rotation = 90; break; case DisplayRotation.Rotation180: rotation = 180; break; case DisplayRotation.Rotation270: rotation = 270; break; } if (iframe.index() != previousInputFrameIndex) { Matrix44F ip = cameraParameters.imageProjection(aspectRatio, rotation, true, false); Matrix4 iprj = ip.ToUrhoMatrix(); bgCamera.SetProjection(iprj); EasyAR.Buffer buffer = image.buffer(); try { backgroundUpdater.UpdateTexture(Application, image.format(), image.width(), image.height(), buffer); } finally { buffer.Dispose(); } previousInputFrameIndex = iframe.index(); } ARFrameUpdated?.Invoke(oframe, cameraParameters, aspectRatio, rotation); image.Dispose(); cameraParameters.Dispose(); } iframe.Dispose(); } oframe.Dispose(); } base.OnUpdate(timeStep); }