Пример #1
0
        // Initialize the graphics device. Return True if successful.
        public bool InitializeGraphics()
        {
            //Prepare the pictureBox to render objects on it
            m_Device = PrepareD3dDevice(pic3d);

            // Turn on D3D lighting.
            m_Device.RenderState.Lighting = true;

            // Turn on the Z-buffer.
            m_Device.RenderState.ZBufferEnable = true;

            // Cull triangles that are oriented counter clockwise.
            m_Device.RenderState.CullMode = Cull.Clockwise;// CounterClockwise;

            // Make points bigger so they're easy to see.
            m_Device.RenderState.PointSize = 4;

            // Start in solid mode.
            m_Device.RenderState.FillMode = FillMode.Solid;

            // Make the lights.
            SetupLights();

            this._surface = new NyARD3dSurface(m_Device, SCREEN_WIDTH, SCREEN_HEIGHT);

            // We succeeded.

            return(true);
        }
Пример #2
0
        /// <summary>
        /// バックグラウンドにラスタを描画します。
        /// </summary>
        /// <param name="i_gl"></param>
        /// <param name="i_bg_image"></param>
        public void drawBackground(Device i_dev, INyARRgbRaster i_bg_image)
	    {
            NyARIntSize s = i_bg_image.getSize();
            if(this._surface==null){
                this._surface = new NyARD3dSurface(i_dev,s.w,s.h);
            }else if(!this._surface.isEqualSize(i_bg_image.getSize())){
                //サーフェイスの再構築
                this._surface.Dispose();
                this._surface = new NyARD3dSurface(i_dev, this._screen_size.w, this._screen_size.h);
            }
            this._surface.setRaster(i_bg_image);
            Surface dest_surface = i_dev.GetBackBuffer(0, 0, BackBufferType.Mono);
            Rectangle rect = new Rectangle(0, 0, this._screen_size.w, this._screen_size.h);
            i_dev.StretchRectangle((Surface)this._surface, rect, dest_surface, rect, TextureFilter.None);
	    }
Пример #3
0
        /// <summary>
        /// バックグラウンドにラスタを描画します。
        /// </summary>
        /// <param name="i_gl"></param>
        /// <param name="i_bg_image"></param>
        public void drawBackground(Device i_dev, INyARRgbRaster i_bg_image)
        {
            NyARIntSize s = i_bg_image.getSize();

            if (this._surface == null)
            {
                this._surface = new NyARD3dSurface(i_dev, s.w, s.h);
            }
            else if (!this._surface.isEqualSize(i_bg_image.getSize()))
            {
                //サーフェイスの再構築
                this._surface.Dispose();
                this._surface = new NyARD3dSurface(i_dev, this._screen_size.w, this._screen_size.h);
            }
            this._surface.setRaster(i_bg_image);
            Surface   dest_surface = i_dev.GetBackBuffer(0, 0, BackBufferType.Mono);
            Rectangle rect         = new Rectangle(0, 0, this._screen_size.w, this._screen_size.h);

            i_dev.StretchRectangle((Surface)this._surface, rect, dest_surface, rect, TextureFilter.None);
        }
Пример #4
0
        public bool InitializeApplication(Form1 topLevelForm,CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT);
            //キャプチャを作る(QVGAでフレームレートは30)
            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;
            
            //ARの設定

            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32);

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //AR用のパターンコードを読み出し	
            NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE),16, 16);

            //1パターンのみを追跡するクラスを作成
            this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT);
            
            //計算モードの設定
            this._ar.setContinueMode(true);

            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting = false;


            //カメラProjectionの設定
            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(),ap.getScreenSize(),1, 10, 10000,ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();
            vp.X = 0;
            vp.Y = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width = ap.getScreenSize().w;
            vp.MaxZ = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._device, 40);


            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            this._is_marker_enable = false;
            return true;
        }
Пример #5
0
        public bool InitializeApplication(Form1 topLevelForm, CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);
            //キャプチャを作る(QVGAでフレームレートは30)
            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;

            //ARラスタを作る(DirectShowキャプチャ仕様)。
            this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32);

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);


            //プロセッサの準備
            this._processor = new MarkerProcessor(ap, this._raster.getBufferType());
            this._processor.setMarkerWidth(100);


            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting = false;
            this._device.RenderState.CullMode = Cull.CounterClockwise;

            Viewport vp = new Viewport();
            vp.X = 0;
            vp.Y = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width = ap.getScreenSize().w;
            vp.MaxZ = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            this._text = new TextPanel(this._device, 1);
            //カメラProjectionの設定
            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(), ap.getScreenSize(), 1, 10, 10000, ref tmp);

            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));

            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            return true;
        }
Пример #6
0
        public void AR_Initialization(Control topLevelForm)
        {
            //Camera parameters
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));

            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //List of patterns
            ar_code = new NyARCode[Constante.PATT_MAX];

            //Pattern files
            AR_CODE_FILES = new String[Constante.PATT_MAX];

            //Pattern index list
            ar_code_index = new int[Constante.PATT_MAX];

            AR_CODE_FILES[0] = "data/patt_U.dat";
            AR_CODE_FILES[1] = "data/patt_S.dat";
            AR_CODE_FILES[2] = "data/patt_T.dat";
            AR_CODE_FILES[3] = "data/patt_H.dat";
            AR_CODE_FILES[4] = "data/patt_B.dat";


            for (int count = 0; count < Constante.PATT_MAX; count++)
            {
                ar_code[count] = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILES[count]), 16, 16);
            }

            marker_width = new double[Constante.PATT_MAX];
            for (int count = 0; count < Constante.PATT_MAX; count++)
            {
                marker_width[count] = 80.0f;
            }


            this._ar = new NyARDetectMarker(ap, ar_code, marker_width, Constante.PATT_MAX);

            this._ar.setContinueMode(true);

            Matrix tmp = new Matrix();

            NyARD3dUtil.toCameraFrustumRH(ap, 1, 2000, ref tmp);
            m_Device.Transform.Projection = tmp;

            // View Matrix:
            Vector3 camera_position = new Vector3(0, 0, -500);

            camera_position.Normalize();
            //camera_position.Multiply(m_Range);

            m_Device.Transform.View = Matrix.LookAtLH(
                camera_position, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
            //m_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 2000);
            Viewport vp = new Viewport();

            vp.X = 0;
            vp.Y = 0;
            //vp.Height = ap.getScreenSize().h;
            //vp.Width = ap.getScreenSize().w;
            vp.Height = SCREEN_HEIGHT;
            vp.Width  = SCREEN_WIDTH;
            vp.MaxZ   = 1.0f;

            m_Device.Viewport = vp;

            this._surface = new NyARD3dSurface(m_Device, SCREEN_WIDTH, SCREEN_HEIGHT);

            NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat;

            int nb_marker_detected = 0;

            nb_marker_detected = this._ar.detectMarkerLite(this._raster, Constante.binarisation);

            if (nb_marker_detected > 0)
            {
                bestConfidence = 0;
                bestMarker     = 0;

                //if the number of detected markers is bigger than the max number available we set it back to MAX number
                if (nb_marker_detected > Constante.MARK_MAX)
                {
                    nb_marker_detected = Constante.MARK_MAX;
                }

                //get the best confidence from the detected markers
                for (int count = 0; count < nb_marker_detected; count++)
                {
                    ar_code_index[count] = this._ar.getARCodeIndex(count);
                    if (this._ar.getConfidence(count) > bestConfidence)
                    {
                        bestConfidence = this._ar.getConfidence(count);
                        bestMarker     = count;
                    }
                    //textBox1.Text += "bestConfidence: " + bestConfidence + "  bestMarker: " + bestMarker+"\n";
                }

                //textBox1.Text += "finally:\nbestConfidence: " + bestConfidence + "  bestMarker: " + bestMarker+"\n\n";

                try
                {
                    //MessageBox.Show("bestMarker: " + bestMarker, "RenderForm.AR_Initialization");
                    this._ar.getTransmationMatrix(bestMarker, nyar_transmat);
                }
                catch (Exception x)
                { //MessageBox.Show(x.ToString(), "RenderForm.AR_Initialize");
                }
                NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat);
            }

            this._nb_marker_detected = nb_marker_detected;

            {
                try
                {
                    this._surface.setRaster(this._raster);
                }
                catch (Exception x)
                {
                    //MessageBox.Show(x.ToString(), "RenderForm.AR_Initialization");
                }
            }
        }
Пример #7
0
        // Initialize the graphics device. Return True if successful.
        public bool InitializeGraphics()
        {
            //Prepare the pictureBox to render objects on it
            m_Device = PrepareD3dDevice(pic3d);

            // Turn on D3D lighting.
            m_Device.RenderState.Lighting = true;

            // Turn on the Z-buffer.
            m_Device.RenderState.ZBufferEnable = true;

            // Cull triangles that are oriented counter clockwise.
            m_Device.RenderState.CullMode = Cull.Clockwise;// CounterClockwise;

            // Make points bigger so they're easy to see.
            m_Device.RenderState.PointSize = 4;

            // Start in solid mode.
            m_Device.RenderState.FillMode = FillMode.Solid;

            // Make the lights.
            SetupLights();

            this._surface = new NyARD3dSurface(m_Device, SCREEN_WIDTH, SCREEN_HEIGHT);

            // We succeeded.

            return true;
        }
Пример #8
0
        public void AR_Initialization(Control topLevelForm)
        {
            //Camera parameters
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //List of patterns
            ar_code = new NyARCode[Constante.PATT_MAX];

            //Pattern files
            AR_CODE_FILES = new String[Constante.PATT_MAX];

            //Pattern index list
            ar_code_index = new int[Constante.PATT_MAX];

            AR_CODE_FILES[0] = "data/patt_U.dat";
            AR_CODE_FILES[1] = "data/patt_S.dat";
            AR_CODE_FILES[2] = "data/patt_T.dat";
            AR_CODE_FILES[3] = "data/patt_H.dat";
            AR_CODE_FILES[4] = "data/patt_B.dat";

            for (int count = 0; count < Constante.PATT_MAX; count++)
                ar_code[count] = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILES[count]), 16, 16);

            marker_width = new double[Constante.PATT_MAX];
            for (int count = 0; count < Constante.PATT_MAX; count++)
                marker_width[count] = 80.0f;

            this._ar = new NyARDetectMarker(ap, ar_code, marker_width, Constante.PATT_MAX);

            this._ar.setContinueMode(true);

            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap, 1, 2000, ref tmp);
            m_Device.Transform.Projection = tmp;

            // View Matrix:
            Vector3 camera_position = new Vector3(0, 0, -500);
            camera_position.Normalize();
            //camera_position.Multiply(m_Range);

            m_Device.Transform.View = Matrix.LookAtLH(
                camera_position, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f));
            //m_Device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 2000);
            Viewport vp = new Viewport();
            vp.X = 0;
            vp.Y = 0;
            //vp.Height = ap.getScreenSize().h;
            //vp.Width = ap.getScreenSize().w;
            vp.Height = SCREEN_HEIGHT;
            vp.Width = SCREEN_WIDTH;
            vp.MaxZ = 1.0f;

            m_Device.Viewport = vp;

            this._surface = new NyARD3dSurface(m_Device, SCREEN_WIDTH, SCREEN_HEIGHT);

            NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat;

            int nb_marker_detected = 0;
            nb_marker_detected = this._ar.detectMarkerLite(this._raster, Constante.binarisation);

            if (nb_marker_detected > 0)
            {
                bestConfidence = 0;
                bestMarker = 0;

                //if the number of detected markers is bigger than the max number available we set it back to MAX number
                if (nb_marker_detected > Constante.MARK_MAX)
                    nb_marker_detected = Constante.MARK_MAX;

                //get the best confidence from the detected markers
                for (int count = 0; count < nb_marker_detected; count++)
                {
                    ar_code_index[count] = this._ar.getARCodeIndex(count);
                    if (this._ar.getConfidence(count) > bestConfidence)
                    {
                        bestConfidence = this._ar.getConfidence(count);
                        bestMarker = count;
                    }
                    //textBox1.Text += "bestConfidence: " + bestConfidence + "  bestMarker: " + bestMarker+"\n";
                }

                //textBox1.Text += "finally:\nbestConfidence: " + bestConfidence + "  bestMarker: " + bestMarker+"\n\n";

                try
                {
                    //MessageBox.Show("bestMarker: " + bestMarker, "RenderForm.AR_Initialization");
                    this._ar.getTransmationMatrix(bestMarker, nyar_transmat);
                }
                catch (Exception x)
                { //MessageBox.Show(x.ToString(), "RenderForm.AR_Initialize");
                }
                NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat);
            }

            this._nb_marker_detected = nb_marker_detected;

            {
                try
                {
                    this._surface.setRaster(this._raster);
                }
                catch (Exception x)
                {
                    //MessageBox.Show(x.ToString(), "RenderForm.AR_Initialization");
                }
            }
        }
        public bool InitializeApplication(Form1 topLevelForm,CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT);
            //キャプチャを作る(QVGAでフレームレートは30)
            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //マーカライブラリ(NyId)の構築
            this._mklib = new RawbitSerialIdTable(10);
            //マーカサイズテーブルの作成(とりあえず全部8cm)
            this._mklib.addAnyItem("any id", 80);

            //Realityの準備
            this._reality = new NyARRealityD3d(ap, 10, 10000, 2, 10);
            this._reality_source = new NyARRealitySource_DShow(SCREEN_WIDTH, SCREEN_HEIGHT, null, 2, 100);

            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting = false;



            //カメラProjectionの設定
            Matrix tmp = new Matrix();
            this._reality.getD3dCameraFrustum(ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();
            vp.Y = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width = ap.getScreenSize().w;
            vp.MaxZ = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._device, 40);
            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            return true;
        }
        public bool InitializeApplication(Form1 topLevelForm)
        {
            topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT);
            this._raster = new NyARBitmapRaster(new Bitmap(TEST_IMAGE));
            

            //AR用カメラパラメタファイルをロードして設定
            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            //AR用のパターンコードを読み出し	
            NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE),16, 16);

            //1パターンのみを追跡するクラスを作成
            this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0,NyARSingleDetectMarker.PF_NYARTOOLKIT);
            
            //計算モードの設定
            this._ar.setContinueMode(true);

            //3dデバイスを準備する
            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting = false;


            //カメラProjectionの設定
            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap, 10, 1000, ref tmp);
            this._device.Transform.Projection = tmp;

            // ビュー変換の設定(左手座標系ビュー行列で設定する)
            // 0,0,0から、Z+方向を向いて、上方向がY軸
            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();
            vp.X = 0;
            vp.Y = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width = ap.getScreenSize().w;
            vp.MaxZ = 1.0f;
            //ビューポート設定
            this._device.Viewport = vp;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._device, 40);

            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            NyARDoubleMatrix44 nyar_transmat = this.__OnBuffer_nyar_transmat;
            //マーカの認識
            bool is_marker_enable = this._ar.detectMarkerLite(this._raster, 110);
            if (is_marker_enable)
            {
                //あればMatrixを計算
                this._ar.getTransmationMatrix(nyar_transmat);
                NyARD3dUtil.toD3dCameraView(nyar_transmat, 1f, ref this._trans_mat);
            }
            this._is_marker_enable = is_marker_enable;
            //サーフェイスへ背景をコピー
            this._surface.setRaster(this._raster);
            return true;
        }
Пример #11
0
        public SimpleLiteMain(Form i_form,CaptureDevice i_dev)
        {
            //setup camera
            i_dev.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30.0f);

            //setup form
            i_form.ClientSize = new Size(SCREEN_WIDTH, SCREEN_HEIGHT);

            //setup AR
            INyARMarkerSystemConfig cf = new NyARMarkerSystemConfig(SCREEN_WIDTH, SCREEN_HEIGHT);
            this._ms = new NyARD3dMarkerSystem(cf);
            this._ss = new NyARDirectShowCamera(i_dev);
            this.mid = this._ms.addARMarker(AR_CODE_FILE, 16, 25, 80);

            //setup directx

            //3dデバイスを準備する
            this._d3d = NyARD3dUtil.createD3dDevice(i_form);
            this._d3d.RenderState.ZBufferEnable = true;
            this._d3d.RenderState.Lighting = false;
            //ビューポートとビューの位置
            this._d3d.Transform.View = NyARD3dUtil.getARView();
            this._d3d.Viewport = NyARD3dUtil.getARViewPort(SCREEN_WIDTH,SCREEN_HEIGHT);
            //Projectionの設定
            this._ms.setProjectionMatrixClipping(10, 10000);
            Matrix pm = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(this._ms.getARParam(),10,10000, ref pm);
            this._d3d.Transform.Projection = pm;

            //カラーキューブの描画インスタンス
            this._cube = new ColorCube(this._d3d, 40);

            //背景サーフェイスを作成
            this._surface = new NyARD3dSurface(this._d3d,SCREEN_WIDTH,SCREEN_HEIGHT);
        }
Пример #12
0
        public bool InitializeApplication(Form1 topLevelForm,CaptureDevice i_cap_device)
        {
            topLevelForm.ClientSize=new Size(SCREEN_WIDTH,SCREEN_HEIGHT);

            i_cap_device.SetCaptureListener(this);
            i_cap_device.PrepareCapture(SCREEN_WIDTH, SCREEN_HEIGHT, 30);
            this._cap = i_cap_device;

            //this._raster = new DsRgbRaster(i_cap_device.video_width, i_cap_device.video_height,NyARBufferType.BYTE1D_B8G8R8X8_32);

            #region my code
            try
                {
                    byte[] bimg = service.getb();
                    //if(bimg != null)
                    {
                        Image img = byteToImage(bimg);
                        if (img != null)
                        {
                            //frm.textBox1.Text = img.ToString();
                            this._raster = new NyARBitmapRaster((Bitmap)img);
                        }
                    }
                    //else
                }
                catch (Exception x)
                {
                    //MessageBox.Show(x.ToString());
                }
            #endregion

            NyARParam ap = NyARParam.createFromARParamFile(new StreamReader(AR_CAMERA_FILE));
            ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);

            NyARCode code = NyARCode.createFromARPattFile(new StreamReader(AR_CODE_FILE),16, 16);

            this._ar = NyARSingleDetectMarker.createInstance(ap, code, 80.0, NyARSingleDetectMarker.PF_NYARTOOLKIT);

            this._ar.setContinueMode(true);

            this._device = PrepareD3dDevice(topLevelForm);
            this._device.RenderState.ZBufferEnable = true;
            this._device.RenderState.Lighting = false;

            Matrix tmp = new Matrix();
            NyARD3dUtil.toCameraFrustumRH(ap.getPerspectiveProjectionMatrix(),ap.getScreenSize(),1, 10, 10000,ref tmp);
            this._device.Transform.Projection = tmp;

            this._device.Transform.View = Matrix.LookAtLH(
                new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f), new Vector3(0.0f, 1.0f, 0.0f));
            Viewport vp = new Viewport();
            vp.X = 0;
            vp.Y = 0;
            vp.Height = ap.getScreenSize().h;
            vp.Width = ap.getScreenSize().w;
            vp.MaxZ = 1.0f;

            this._device.Viewport = vp;

            this._cube = new ColorCube(this._device, 40);

            this._surface = new NyARD3dSurface(this._device, SCREEN_WIDTH, SCREEN_HEIGHT);

            this._is_marker_enable = false;
            return true;
        }