Ultrahaptics座標変換マトリックスメモ
Unity+UHDK5正方形
通常配置
Ultrahaptics.Vector3 LeapToUHVector(Leap.Vector vec) { UnityEngine.Matrix4x4 leapToU5 = new UnityEngine.Matrix4x4(); leapToU5.SetRow(0, new Vector4(0.001f, 0.0f, 0.0f, 0.0f)); leapToU5.SetRow(1, new Vector4(0.0f, 0.0f, -0.001f, 0.1105f)); leapToU5.SetRow(2, new Vector4(0.0f, 0.001f, 0.0f, 0.0f)); leapToU5.SetRow(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); UnityEngine.Vector4 leapVec = new UnityEngine.Vector4(); leapVec.x = vec.x; leapVec.y = vec.y; leapVec.z = vec.z; leapVec.w = 1; UnityEngine.Vector4 UHVec = leapToU5 * leapVec; return new Ultrahaptics.Vector3(UHVec.x, UHVec.y, UHVec.z); }
LeapMotionを反転させて設置
Ultrahaptics.Vector3 LeapToUHVector(Leap.Vector vec) { UnityEngine.Matrix4x4 leapToU5 = new UnityEngine.Matrix4x4(); leapToU5.SetRow(0, new Vector4(-0.001f, 0.0f, 0.0f, 0.0f)); leapToU5.SetRow(1, new Vector4(0.0f, 0.0f, -0.001f, 0.1105f)); leapToU5.SetRow(2, new Vector4(0.0f, 0.001f, 0.0f, 0.0f)); leapToU5.SetRow(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f)); UnityEngine.Vector4 leapVec = new UnityEngine.Vector4(); leapVec.x = vec.x; leapVec.y = vec.y; leapVec.z = vec.z; leapVec.w = 1; UnityEngine.Vector4 UHVec = leapToU5 * leapVec; return new Ultrahaptics.Vector3(UHVec.x, UHVec.y, UHVec.z); }
使い方例 leapとUltrahapticsのSDKの導入とunity用assetsのインポートが必要 using Ultrahaptics;も宣言必要
AmplitudeModulationEmitter _emitter; Alignment _alignment; Leap.Controller _leap; void Start() { // Initialize the emitter _emitter = new AmplitudeModulationEmitter(); _emitter.initialize(); _leap = new Leap.Controller(); // Load the appropriate alignment file for the currently-used device _alignment = _emitter.getDeviceInfo().getDefaultAlignment(); } void Update() { if (_leap.IsConnected) { var frame = _leap.Frame (); if (frame.Hands.Count > 0) { Leap.Vector leapPalmPosition = frame.Hands[0].PalmPosition; Ultrahaptics.Vector3 uhPalmPosition0 = LeapToUHVector(leapPalmPosition); AmplitudeModulationControlPoint point0 = new AmplitudeModulationControlPoint(uhPalmPosition0, 1.0f, 200.0f); _emitter.update(new List<AmplitudeModulationControlPoint> { point0 }); } else { Debug.LogWarning ("No hands detected"); _emitter.stop(); } } else { Debug.LogWarning ("No Leap connected"); _emitter.stop(); } }