Weitere ähnliche Inhalte
Ähnlich wie はじめようARCore in 札幌 (14)
Mehr von Takashi Yoshinaga (20)
Kürzlich hochgeladen (10)
はじめようARCore in 札幌
- 12. 事前準備
• Unity2017.4.26 or later
https://unity3d.com/jp/unity/qa/lts-
releases
• ARCore SDK 1.7
https://github.com/google-ar/arcore-
unity-sdk/releases/tag/v1.11.0.1
• Sample
http://arfukuoka.lolipop.jp/ARCore_Sa
pporo/sample.zip
- 84. スクリプトの記述
void Update () {
//タッチしていないなら
if (Input.touchCount < 1 ){ return; }
Touch touch = Input.GetTouch(0);
//画面をなぞっていなければ
if (touch.phase != TouchPhase.Moved ){ return;}
//タップした座標にAndyを移動。
TrackableHit hit;
TrackableHitFlags filter = TrackableHitFlags.PlaneWithinPolygon;
if(Frame.Raycast(touch.position.x, touch.position.y, filter, out hit) )
{
//Andyの3D座標を指定するコードを記述(次頁)
}
}
touch.position
hit
Moved→画面をなぞる
平面を構成するポリゴンの
内側をタップ判定の対象に
- 85. スクリプトの記述
if (Frame.Raycast(touch.position.x, touch.position.y, filter, out hit))
{
//平面にヒットしたならAndyを置く
if (hit.Trackable is DetectedPlane)
{
//Andyの位置・姿勢を指定
andy.transform.position = hit.Pose.position;
andy.transform.rotation = hit.Pose.rotation;
andy.transform.Rotate(0, 180, 0, Space.Self);
//Anchorを設定
var anchor = hit.Trackable.CreateAnchor(hit.Pose);
andy.transform.parent = anchor.transform;
}
}
- 110. スクリプトの記述
void Update () {
if (Input.touchCount == 1)
{
//カメラ手前10cmの位置を取得
Vector3 p = Camera.main.transform.TransformPoint(0,0,0.1f);
//タッチスタート
TouchPhase phase = Input.GetTouch(0).phase;
if (phase == TouchPhase.Began)
{
drawObj = GameObject.Instantiate(obj, p, Quaternion.identity);
}
//押下中
else if (phase == TouchPhase.Stationary || phase == TouchPhase.Moved){
drawObj.transform.position = p;
}
}
}
- 114. 線を消す
List<GameObject> lines = new List<GameObject>();
void Update () {
if (Input.touchCount == 1)
{//カメラ手前10cmの位置を取得
Vector3 p = Camera.main.transform.TransformPoint(0,0,0.1f);//
TouchPhase phase = Input.GetTouch(0).phase;
if ( phase == TouchPhase.Began)
{
drawObj = GameObject.Instantiate(obj, p, Quaternion.identity);
GameObject tmp
= GameObject.Instantiate(obj, p, Quaternion.identity);
lines.Add(tmp);
drawObj = tmp;
} //押下中
else if (phase == TouchPhase.Stationary || phase == TouchPhase.Moved){
drawObj.transform.position = p;
}
}
}
- 115. 線を消す
void Update () {
if (Input.touchCount == 1)
{
//線の描画をする/カメラ手前10cmの位置を取得
}
else if (Input.touchCount == 2)
{
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
for(int i = 0; i < lines.Count; i++)
{
Destroy(lines[i]);
lines[i] = null;
}
lines.Clear();
}
}
}
- 167. ARCoreハンズオン資料
• ARCoreハンズオン (自己位置推定/マーカー認識/Cloud Anchor)
https://www.slideshare.net/ssuserc0d7fb/arcore-
108717431
• 塗り絵AR
https://www.slideshare.net/ssuserc0d7fb/opencvarcore
unityar
• スタンプAR
https://www.slideshare.net/ssuserc0d7fb/openar-
152506475
• 簡易HMD Aryzon
https://www.slideshare.net/ssuserc0d7fb/aryzonar-
141441121