예제 #1
0
        /* カメラのプロジェクションMatrix(RH)を返します。
         * このMatrixはMicrosoft.DirectX.Direct3d.Device.Transform.Projectionに設定できます。
         */
        public static void toCameraFrustumRH(NyARPerspectiveProjectionMatrix i_promat, NyARIntSize i_size, double i_scale, double i_near, double i_far, ref Matrix o_d3d_projection)
        {
            NyARDoubleMatrix44 m = new NyARDoubleMatrix44();

            i_promat.makeCameraFrustumRH(i_size.w, i_size.h, i_near * i_scale, i_far * i_scale, m);
            NyARD3dUtil.mat44ToD3dMatrixT(m, ref o_d3d_projection);
            return;
        }
예제 #2
0
        /* DsXRGB32Rasterの内容を保持しているテクスチャにコピーします。
         * i_rasterのサイズは、このインスタンスに指定したテクスチャサイズ(コンストラクタ等に指定したサイズ)と同じである必要です。
         * ラスタデータはテクスチャの左上を基点にwidth x heightだけコピーされ、残りの部分は更新されません。
         */
        public void setRaster(INyARRgbRaster i_raster)
        {
            Debug.Assert(!this._is_dispose);
            int pitch;

            using (GraphicsStream texture_rect = this.m_texture.LockRectangle(0, LockFlags.None, out pitch))
            {
                try{
                    int dst = (int)texture_rect.InternalData;
                    switch (i_raster.getBufferType())
                    {
                    case NyARBufferType.BYTE1D_B8G8R8X8_32:
                    {
                        byte[] buf = (byte[])i_raster.getBuffer();
                        //テクスチャのピッチって何?
                        int src_w = this.m_width * 4;
                        int src   = 0;
                        for (int r = this.m_height - 1; r >= 0; r--)
                        {
                            Marshal.Copy(buf, src, (IntPtr)dst, pitch);
                            dst += pitch;
                            src += src_w;
                        }
                    }
                    break;

                    case NyARBufferType.OBJECT_CS_Bitmap:
                        NyARBitmapRaster ra = (NyARBitmapRaster)(i_raster);
                        BitmapData       bm = ra.lockBitmap();
                        try
                        {
                            int src = (int)bm.Scan0;
                            for (int r = this.m_height - 1; r >= 0; r--)
                            {
                                NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, pitch);
                                dst += pitch;
                                src += bm.Stride;
                            }
                        }
                        finally
                        {
                            ra.unlockBitmap();
                        }
                        break;

                    default:
                        throw new NyARException();
                    }
                }
                finally
                {
                    //テクスチャをアンロックする
                    this.m_texture.UnlockRectangle(0);
                }
            }
            return;
        }
예제 #3
0
        /* DsXRGB32Rasterの内容を保持しているサーフェイスにコピーします。
         */
        public void setRaster(INyARRgbRaster i_sample)
        {
            Debug.Assert(!this._is_dispose);
            int pitch;
            int s_stride = this.m_width * 4;

            using (GraphicsStream gs = this._surface.LockRectangle(LockFlags.None, out pitch))
            {
                try{
                    switch (i_sample.getBufferType())
                    {
                    case NyARBufferType.BYTE1D_B8G8R8X8_32:
                        if (pitch % s_stride == 0)
                        {
                            Marshal.Copy((byte[])i_sample.getBuffer(), 0, (IntPtr)((int)gs.InternalData), this.m_width * 4 * this.m_height);
                        }
                        else
                        {
                            int s_idx = 0;
                            int d_idx = (int)gs.InternalData;
                            for (int i = this.m_height - 1; i >= 0; i--)
                            {
                                //どう考えてもポインタです。
                                Marshal.Copy((byte[])i_sample.getBuffer(), s_idx, (IntPtr)(d_idx), s_stride);
                                s_idx += s_stride;
                                d_idx += pitch;
                            }
                        }
                        break;

                    case NyARBufferType.OBJECT_CS_Bitmap:
                        NyARBitmapRaster ra = (NyARBitmapRaster)(i_sample);
                        BitmapData       bm = ra.lockBitmap();
                        try{
                            //コピー
                            int src = (int)bm.Scan0;
                            int dst = (int)gs.InternalData;
                            for (int r = this.m_height - 1; r >= 0; r--)
                            {
                                NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, s_stride);
                                dst += pitch;
                                src += bm.Stride;
                            }
                        }finally{
                            ra.unlockBitmap();
                        }
                        break;

                    default:
                        throw new NyARException();
                    }
                }finally{
                    this._surface.UnlockRectangle();
                }
                return;
            }
        }
예제 #4
0
 /// <summary>
 /// Device.Transform.ViewにAR表示向けのDirectXビューを設定します。
 /// </summary>
 /// <param name="i_d3d"></param>
 public void loadARViewMatrix(Device i_dev)
 {
     // ビュー変換の設定(左手座標系ビュー行列で設定する)
     // 0,0,0から、Z+方向を向いて、上方向がY軸
     i_dev.Transform.View = NyARD3dUtil.getARView();
 }
예제 #5
0
 /// <summary>
 /// Device.ViewportをAR向けに設定します。
 /// </summary>
 /// <param name="i_img_height">バックグラウンド画像の解像度を指定します。</param>
 /// <param name="i_img_width">バックグラウンド画像の解像度を指定します。</param>
 public void loadARViewPort(Device i_dev)
 {
     //ビューポート設定
     i_dev.Viewport = NyARD3dUtil.getARViewPort(this._screen_size.w, this._screen_size.h);
 }
예제 #6
0
 /**
  * Observerのイベントハンドラ
  */
 public void onUpdateCameraParametor(NyARParam i_param, double i_near, double i_far)
 {
     NyARD3dUtil.toCameraFrustumRH(i_param, i_near, i_far, ref this._projection_mat);
 }
예제 #7
0
        private void buttonBookDemo_Click(object sender, EventArgs e)
        {
            if (bookDemo == false)
            {
                StopOtherApps(this, e);
                bookDemo = true;
                labelDemoName.Text = "Book";
                buttonBookDemo.Text = "Stop Book";
                labelDemoInstructions.Enabled = true;
                labelDemoInstructions.Text = "Book Demo Instructions:\n\n"
                    + "Book \n";

                //pictureBoxAlbum.Show();
                lblResult.Hide();

                //NYAR
                //initialize nyar components.
                NyARParam ap = new NyARParam();
                ap.loadARParamFromFile(AR_CAMERA_FILE);
                ap.changeScreenSize(SCREEN_WIDTH, SCREEN_HEIGHT);
                _raster = new DsBGRX32Raster(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_WIDTH * 32 / 8);
                _utils = new NyARD3dUtil();

                // For each pattern
                NyARCode code1 = new NyARCode(16, 16);
                code1.loadARPattFromFile(AR_CODE_FILE1);
                _ar1 = new NyARSingleDetectMarker(ap, code1, 80.0);
                _ar1.setContinueMode(false);

                NyARCode code2 = new NyARCode(16, 16);
                code2.loadARPattFromFile(AR_CODE_FILE2);
                _ar2 = new NyARSingleDetectMarker(ap, code2, 80.0);
                _ar2.setContinueMode(false);

                NyARCode code3 = new NyARCode(16, 16);
                code3.loadARPattFromFile(AR_CODE_FILE3);
                _ar3 = new NyARSingleDetectMarker(ap, code3, 80.0);
                _ar3.setContinueMode(false);

                NyARCode code4 = new NyARCode(16, 16);
                code4.loadARPattFromFile(AR_CODE_FILE4);
                _ar4 = new NyARSingleDetectMarker(ap, code4, 80.0);
                _ar4.setContinueMode(false);
            }
            else
            {
                bookDemo = false;
                labelDemoName.Text = "WUW";
                buttonBookDemo.Text = "Book";
                Cursor = Cursors.Arrow;
                labelDemoInstructions.Enabled = false;
                labelDemoInstructions.Text = "";
                ResetEnvironment();

                //pictureBoxAlbum.Hide();
                lblResult.Show();
            }
        }
예제 #8
0
 /**
  * DirectXスタイルのProjectionMatrixを返却します。
  */
 public void getD3dCameraFrustum(ref Matrix o_mat)
 {
     NyARD3dUtil.mat44ToD3dMatrixT(this._frustum.getMatrix(), ref o_mat);
 }
예제 #9
0
 /**
  *
  * NyARToolKitの姿勢変換行列を返します。
  * @throws NyARException
  */
 public void getD3dModelViewMatrix(NyARDoubleMatrix44 i_nyar_mat, ref Matrix o_mat)
 {
     NyARD3dUtil.toD3dCameraView(i_nyar_mat, 1f, ref o_mat);
     return;
 }
예제 #10
0
 /**
  * この関数は、i_bufに指定idのOpenGL形式の姿勢変換行列を設定して返します。
  * @param i_id
  * @param i_buf
  * @return
  */
 public void getMarkerMatrix(int i_id, ref Matrix i_buf)
 {
     NyARD3dUtil.toD3dCameraView(base.getMarkerMatrix(i_id), 1, ref i_buf);
     return;
 }