//メインループ処理 public void MainLoop() { //RealitySourceにデータが処理する。 if (!this._reality_source.isReady()) { return; } // 背景を書く try{ lock (this){ // 背景サーフェイスを直接描画 Surface dest_surface = this._device.GetBackBuffer(0, 0, BackBufferType.Mono); Rectangle src_dest_rect = new Rectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); this._device.StretchRectangle((Surface)this._surface, src_dest_rect, dest_surface, src_dest_rect, TextureFilter.None); // 3Dオブジェクトの描画はここから this._device.BeginScene(); this._device.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0); //ターゲットリストを走査して、画面に内容を反映 NyARRealityTargetList tl = this._reality.refTargetList(); for (int i = tl.getLength() - 1; i >= 0; i--) { NyARRealityTarget t = tl.getItem(i); switch (t.getTargetType()) { case NyARRealityTarget.RT_KNOWN: //立方体を20mm上(マーカーの上)にずらしておく Matrix mat = new Matrix(); this._reality.getD3dModelViewMatrix(t.refTransformMatrix(), ref mat); Matrix transform_mat2 = Matrix.Translation(0, 0, 20.0f); transform_mat2 = transform_mat2 * mat; this._device.SetTransform(TransformType.World, transform_mat2); this._cube.draw(this._device); break; case NyARRealityTarget.RT_UNKNOWN: // break; } } // 描画はここまで this._device.EndScene(); // 実際のディスプレイに描画 this._device.Present(); } Thread.Sleep(1); // タスク実行権限を一旦渡す }catch (Exception e) { System.Console.WriteLine(e.StackTrace); } return; }
//メインループ処理 public void MainLoop() { //ARの計算 lock (this) { // 背景サーフェイスを直接描画 Surface dest_surface = this._device.GetBackBuffer(0, 0, BackBufferType.Mono); Rectangle src_dest_rect = new Rectangle(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); this._device.StretchRectangle((Surface)this._surface, src_dest_rect, dest_surface, src_dest_rect, TextureFilter.None); // 3Dオブジェクトの描画はここから this._device.BeginScene(); this._device.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0); //ターゲットリストを走査して、画面に内容を反映 NyARRealityTargetList tl = this._reality.refTargetList(); for (int i = tl.getLength() - 1; i >= 0; i--) { NyARRealityTarget t = tl.getItem(i); switch (t.getTargetType()) { case NyARRealityTarget.RT_KNOWN: //立方体を20mm上(マーカーの上)にずらしておく Matrix mat = new Matrix(); this._reality.getD3dModelViewMatrix(t.refTransformMatrix(), ref mat); Matrix transform_mat2 = Matrix.Translation(0, 0, 20.0f); transform_mat2 = transform_mat2 * mat; this._device.SetTransform(TransformType.World, transform_mat2); this._cube.draw(this._device); break; case NyARRealityTarget.RT_UNKNOWN: //NyARDoublePoint2d[] p = t.refTargetVertex(); //NyARGLDrawUtil.beginScreenCoordinateSystem(this._gl, SCREEN_X, SCREEN_Y, true); //NyARGLDrawUtil.endScreenCoordinateSystem(this._gl); break; } } // 描画はここまで this._device.EndScene(); // 実際のディスプレイに描画 this._device.Present(); } return; }
//メインループ処理 public void MainLoop() { //ARの計算 lock (this) { Device dev = this._d3dmgr.d3d_device; // 背景サーフェイスを直接描画 // 3Dオブジェクトの描画はここから dev.Clear(ClearFlags.ZBuffer, Color.DarkBlue, 1.0f, 0); dev.BeginScene(); this._back_ground.drawBackGround(this._d3dmgr.d3d_device); //ターゲットリストを走査して、画面に内容を反映 NyARRealityTargetList tl = this._reality.refTargetList(); for (int i = tl.getLength() - 1; i >= 0; i--) { NyARRealityTarget t = tl.getItem(i); switch (t.getTargetType()) { case NyARRealityTarget.RT_KNOWN: //立方体を20mm上(マーカーの上)にずらしておく Matrix mat = new Matrix(); this._reality.getD3dModelViewMatrix(t.refTransformMatrix(), ref mat); Matrix transform_mat2 = Matrix.Translation(0, 0, 20.0f); transform_mat2 = transform_mat2 * mat; dev.SetTransform(TransformType.World, transform_mat2); this._d3dcube.draw(dev); break; case NyARRealityTarget.RT_UNKNOWN: //NyARDoublePoint2d[] p = t.refTargetVertex(); //NyARGLDrawUtil.beginScreenCoordinateSystem(this._gl, SCREEN_X, SCREEN_Y, true); //NyARGLDrawUtil.endScreenCoordinateSystem(this._gl); break; } } // 描画はここまで dev.EndScene(); // 実際のディスプレイに描画 dev.Present(); } return; }
/** * コンストラクタから呼び出す共通な初期化部分です。 * @param i_dist_factor * @param i_prjmat * @throws NyARException */ protected void initInstance(NyARIntSize i_screen,double i_near,double i_far,NyARPerspectiveProjectionMatrix i_prjmat,INyARCameraDistortionFactor i_dist_factor) { int number_of_reality_target=this.MAX_LIMIT_KNOWN+this.MAX_LIMIT_UNKNOWN; //演算インスタンス this._transmat=new NyARTransMat(i_dist_factor,i_prjmat); //データインスタンス this._pool=new NyARRealityTargetPool(number_of_reality_target,i_prjmat); this.target=new NyARRealityTargetList(number_of_reality_target); //Trackerの特性値 this._tracker=new NyARTracker((this.MAX_LIMIT_KNOWN+this.MAX_LIMIT_UNKNOWN)*2,1,this.MAX_LIMIT_KNOWN*2); //フラスタムの計算とスクリーンサイズの保存 this._ref_prjmat=i_prjmat; this._frustum=new NyARFrustum(i_prjmat,i_screen.w,i_screen.h, i_near, i_far); //初期化 this._number_of_dead=this._number_of_unknown=this._number_of_known=0; return; }