| | @@ -1,75 +1,76 @@ |
| 1 | | -using UnityEngine; |
| 2 | | -using UnityEditor; |
| 3 | | -using System; |
| 4 | | -using System.Collections; |
| 5 | | -using jp.nyatla.nyartoolkit.cs.markersystem; |
| 6 | | -using jp.nyatla.nyartoolkit.cs.core; |
| 7 | | -using NyARUnityUtils; |
| 8 | | -using System.IO; |
| 9 | | -/// <summary> |
| 10 | | -/// このサンプルプログラムは、マーカ表面の画像をテクスチャとして取得します。 |
| 11 | | -/// マーカファイルには、hiroマーカを使用してください。 |
| 12 | | -/// </summary> |
| 13 | | -public class MarkerPlaneBehavior : MonoBehaviour |
| 14 | | -{ |
| 15 | | - private NyARUnityMarkerSystem _ms; |
| 16 | | - private NyARUnityWebCam _ss; |
| 17 | | - private int mid;//marker id |
| 18 | | - private GameObject _bg_panel; |
| 19 | | - void Awake() |
| 20 | | - { |
| 21 | | - //setup unity webcam |
| 22 | | - WebCamDevice[] devices= WebCamTexture.devices; |
| 23 | | - WebCamTexture w; |
| 24 | | - if (devices.Length > 0){ |
| 25 | | - w=new WebCamTexture(320, 240, 15); |
| 26 | | - this._ss=new NyARUnityWebCam(w); |
| 27 | | - NyARMarkerSystemConfig config = new NyARMarkerSystemConfig(w.requestedWidth,w.requestedHeight); |
| 28 | | - this._ms=new NyARUnityMarkerSystem(config); |
| 29 | | - mid=this._ms.addARMarker("./Assets/Data/patt.hiro",16,25,80); |
| 30 | | - |
| 31 | | - //setup background |
| 32 | | - this._bg_panel=GameObject.Find("Plane"); |
| 33 | | - this._bg_panel.renderer.material.mainTexture=w; |
| 34 | | - this._ms.setARBackgroundTransform(this._bg_panel.transform); |
| 35 | | - |
| 36 | | - //setup camera projection |
| 37 | | - this._ms.setARCameraProjection(this.camera); |
| 38 | | - |
| 39 | | - }else{ |
| 40 | | - Debug.LogError("No Webcam."); |
| 41 | | - } |
| 42 | | - } |
| 43 | | - // Use this for initialization |
| 44 | | - void Start () |
| 45 | | - { |
| 46 | | - this._ss.start(); |
| 47 | | - } |
| 48 | | - int c=0; |
| 49 | | - // Update is called once per frame |
| 50 | | - void Update () |
| 51 | | - { |
| 52 | | - //Update marker system by ss |
| 53 | | - this._ss.update(); |
| 54 | | - this._ms.update(this._ss); |
| 55 | | - Vector3 mpos=Input.mousePosition; |
| 56 | | - mpos=this.camera.ScreenToViewportPoint(mpos); |
| 57 | | - mpos.x=(mpos.x)*320; |
| 58 | | - mpos.y=(1.0f-mpos.y)*240; |
| 59 | | - Debug.Log(c+":"+mpos.x+","+mpos.y+","+mpos.z);c++; |
| 60 | | - //update Gameobject transform |
| 61 | | - if(this._ms.isExistMarker(mid)){ |
| 62 | | - this._ms.setMarkerTransform(mid,GameObject.Find("MarkerObject").transform); |
| 63 | | - //マウス座標の取得 |
| 64 | | - //平面座標に変換 |
| 65 | | - Vector3 p=new Vector3(); |
| 66 | | - this._ms.getMarkerPlanePos(mid,(int)mpos.x,(int)mpos.y,ref p); |
| 67 | | - GameObject.Find("Cube").transform.localPosition=p; |
| 68 | | - Transform t=GameObject.Find("MarkerObject").transform; |
| 69 | | - }else{ |
| 70 | | - // hide Game object |
| 71 | | - GameObject.Find("MarkerObject").transform.localPosition=new Vector3(0,0,-100); |
| 72 | | - } |
| 73 | | - } |
| 74 | | -} |
| 75 | | - |
| 1 | +u s i n g U n i t y E n g i n e ; |
| 2 | + u s i n g U n i t y E d i t o r ; |
| 3 | + u s i n g S y s t e m ; |
| 4 | + u s i n g S y s t e m . C o l l e c t i o n s ; |
| 5 | + u s i n g j p . n y a t l a . n y a r t o o l k i t . c s . m a r k e r s y s t e m ; |
| 6 | + u s i n g j p . n y a t l a . n y a r t o o l k i t . c s . c o r e ; |
| 7 | + u s i n g N y A R U n i t y U t i l s ; |
| 8 | + u s i n g S y s t e m . I O ; |
| 9 | + / / / < |