Пример #1
0
 /// <summary>
 /// MonoBehaviour OnDestroy
 /// </summary>
 protected virtual void OnDestroy()
 {
     if (cameraParameters != null)
     {
         cameraParameters.Dispose();
     }
     if (ExternalParameters)
     {
         ExternalParameters.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);
        }