LoginSignup
18
20

More than 5 years have passed since last update.

[Unity] Leapmotion Orionで手のモデルの位置を簡単に取得する

Posted at

Leapmotionが神アップデートされ、トラッキング精度とできることが格段によくなりました。
ただそれに伴って、APIやら仕組みやらが一新され、以前の感覚で実装するとうまく動きません。

Leapmotion Orionで手のモデルの位置とか手のひらの法線とかってどうやって取るのかなーと探していたら、この質問を見つけました。

結論から言うと、 LeapServiceProvider を使うことで非常に手軽に手のモデルの位置などの情報を取得することができます。
もっと言うと、 CurrentFrame で取得できる Frame オブジェクトの Hand オブジェクトはUnity上で手のモデルが実際に表示されている位置をすでに保持しているので、 Hand クラスの各種値がそのまま使えます。
(ただ、Documentとかから見つけられなくて苦労しました( ;´Д`))

とても短いコードなので全文載せておきます。

サンプルコード

using UnityEngine;
using System.Collections;
using Leap;
using Leap.Unity;
using System.Collections.Generic;

public class AnyHand : MonoBehaviour {

    [SerializeField]
    GameObject m_ProviderObject;

    LeapServiceProvider m_Provider;

    void Start () {
        m_Provider = m_ProviderObject.GetComponent<LeapServiceProvider>();
    }

    void Update() {
        Frame frame = m_Provider.CurrentFrame;

         // 右手を取得する
        Hand rightHand = null;
        foreach (Hand hand in frame.Hands) {
            if (hand.IsRight) {
                rightHand = hand;
                break;
            }
        }

        if (rightHand == null) {
            return;
        }

        // 手のひらの法線
        Vector3 normal = rightHand.PalmNormal.ToVector3();

        // 手の向き
        Vector3 direction = rightHand.Direction.ToVector3();

        // 情報がとれたので、あとは煮るなり焼くなりお好きに。
    }
 }
18
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
20