Ejemplo n.º 1
0
        void MarkerFound(PKTMarker marker)
        {
            Console.WriteLine("MarkerFound called with id = {0}!", marker.Id);

            /*
             * float[] projArray = new float[16];
             * float[] modelArray = new float[16];
             * IntPtr projMatrixPtr = IntPtr.Zero, modelMatrixPtr = IntPtr.Zero;
             * GetCurrentProjectionMatrix(ref projMatrixPtr);
             * GetCurrentModelViewMatrix(ref modelMatrixPtr);
             *
             * Marshal.Copy(projMatrixPtr, projArray, 0, 16);
             * Marshal.Copy(modelMatrixPtr, modelArray,0,16);
             */

            //Console.WriteLine("projMatrix[0] = {0}, projMatrix[1] = {1}", projArray[0], projArray[1]);
            //Console.WriteLine("modelMatrix[0] = {0}, modelMatrix[1] = {1}", modelArray[0], modelArray[1]);
        }
        public void DrawMesh(ref float [] modelView, ref float[] projection)
        {
            var viewCtrl = _parentCtrl as RecognitionViewController;

            if (viewCtrl != null)
            {
                var currentStatus = PKTVIDEO_STATE.NOT_READY;
                if (mPikkartVideoPlayer != null)
                {
                    currentStatus = mPikkartVideoPlayer.Status;
                    if (currentStatus == PKTVIDEO_STATE.PLAYING)
                    {
                        mPikkartVideoPlayer.UpdateVideoData();
                        videoAspectRatio = (float)(mPikkartVideoPlayer.Size.Height / mPikkartVideoPlayer.Size.Width);
                    }
                }

                PKTMarker currentMarker = viewCtrl.CurrentMarker;
                if (currentMarker != null)
                {
                    var markerSize = new CGSize(currentMarker.Width, currentMarker.Height);
                    GL.Enable(EnableCap.DepthTest);
                    GL.Disable(EnableCap.CullFace);

                    if ((currentStatus == PKTVIDEO_STATE.READY) ||
                        (currentStatus == PKTVIDEO_STATE.REACHED_END) ||
                        (currentStatus == PKTVIDEO_STATE.NOT_READY) ||
                        (currentStatus == PKTVIDEO_STATE.ERROR))
                    {
                        float[] scaleMatrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        RenderUtils.MtxLoadIdentity(ref scaleMatrix);
                        scaleMatrix[0]  = (float)markerSize.Width;
                        scaleMatrix[5]  = (float)(markerSize.Width * keyframeAspectRatio);
                        scaleMatrix[10] = (float)markerSize.Width;

                        float[] temp_mv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        RenderUtils.MatrixMultiply(4, 4, ref modelView, 4, 4, ref scaleMatrix, ref temp_mv);

                        float[] temp_mvp = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        RenderUtils.MatrixMultiply(4, 4, ref projection, 4, 4, ref temp_mv, ref temp_mvp);

                        float[] mvpMatrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MtxTranspose(ref temp_mvp,
                                                 ref mvpMatrix);

                        DrawKeyFrame(ref mvpMatrix);
                    }
                    else
                    {
                        float[] scaleMatrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        RenderUtils.MtxLoadIdentity(ref scaleMatrix);
                        scaleMatrix[0]  = (float)(markerSize.Width);
                        scaleMatrix[5]  = (float)(markerSize.Width * videoAspectRatio);
                        scaleMatrix[10] = (float)(markerSize.Width);


                        float[] temp_mv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MatrixMultiply(4, 4, ref modelView, 4, 4, ref scaleMatrix, ref temp_mv);


                        float[] temp_mvp = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                        RenderUtils.MatrixMultiply(4, 4, ref projection, 4, 4, ref temp_mv, ref temp_mvp);

                        float[] mvpMatrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MtxTranspose(ref temp_mvp,
                                                 ref mvpMatrix);

                        DrawVideo(ref mvpMatrix);
                    }

                    if ((currentStatus == PKTVIDEO_STATE.READY) ||
                        (currentStatus == PKTVIDEO_STATE.REACHED_END) ||
                        (currentStatus == PKTVIDEO_STATE.PAUSED) ||
                        (currentStatus == PKTVIDEO_STATE.NOT_READY) ||
                        (currentStatus == PKTVIDEO_STATE.ERROR))
                    {
                        float[] translateMatrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MtxLoadIdentity(ref translateMatrix);
                        //scale a bit
                        translateMatrix[0]  = 0.4f;
                        translateMatrix[5]  = 0.4f;
                        translateMatrix[10] = 0.4f;
                        //translate a bit
                        translateMatrix[3]  = 0;
                        translateMatrix[7]  = 0.45f;
                        translateMatrix[11] = -0.05f;

                        float[] temp_mv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MatrixMultiply(4, 4, ref modelView, 4, 4, ref translateMatrix, ref temp_mv);

                        float[] temp_mvp = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MatrixMultiply(4, 4, ref projection, 4, 4, ref temp_mv, ref temp_mvp);

                        float[] mvpMatrix = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                        RenderUtils.MtxTranspose(ref temp_mvp,
                                                 ref mvpMatrix);

                        DrawIcon(ref mvpMatrix, currentStatus);
                    }
                    RenderUtils.CheckGLError();
                }
            }
        }