using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.MagicLeap;
public class Bird_0823 : MonoBehaviour
{
public enum HandPoses { Ok, Finger, Thumb, OpenHand, Pinch, NoPose };
public HandPoses pose = HandPoses.NoPose;
public Vector3[] pos;
public GameObject sphereThumb, sphereIndex, sphereWrist, ObjectToPlace;
private MLHandTracking.HandKeyPose[] _gestures;
bool canIPlace = false;
bool canIGrab = false;
public GameObject selectedGameObject;
private void Start()
{
MLHandTracking.Start();
_gestures = new MLHandTracking.HandKeyPose[5];
_gestures[0] = MLHandTracking.HandKeyPose.Ok;
_gestures[1] = MLHandTracking.HandKeyPose.Finger;
_gestures[2] = MLHandTracking.HandKeyPose.OpenHand;
_gestures[3] = MLHandTracking.HandKeyPose.Fist;
_gestures[4] = MLHandTracking.HandKeyPose.Thumb;
MLHandTracking.KeyPoseManager.EnableKeyPoses(_gestures, true, false);
pos = new Vector3[3];
}
private void OnDestroy()
{
MLHandTracking.Stop();
}
private void Update()
{
ShowPoints();
transform.position = pos[1];
if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Ok))
{
pose = HandPoses.Ok;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Finger))
{
pose = HandPoses.Finger;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.OpenHand))
{
pose = HandPoses.OpenHand;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Pinch))
{
pose = HandPoses.Pinch;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Thumb))
{
pose = HandPoses.Thumb;
if (canIPlace == true)
{
GameObject placedObject = Instantiate(ObjectToPlace, pos[0], transform.rotation);
canIPlace = false;
}
}
else
{
pose = HandPoses.NoPose;
//canIPlace = true;
if (selectedGameObject && canIGrab == false)
{
selectedGameObject = null;
gameObject.GetComponent<SphereCollider>().radius = 0.01f;
}
}
}
private void ShowPoints()
{
// Left Hand Thumb tip
pos[0] = MLHandTracking.Left.Thumb.KeyPoints[2].Position;
// Left Hand Index finger tip
pos[1] = MLHandTracking.Left.Index.KeyPoints[2].Position;
// Left Hand Wrist
pos[2] = MLHandTracking.Left.Wrist.KeyPoints[0].Position;
sphereThumb.transform.position = pos[0];
sphereIndex.transform.position = pos[1];
sphereWrist.transform.position = pos[2];
}
private bool GetGesture(MLHandTracking.Hand hand, MLHandTracking.HandKeyPose type)
{
if (hand != null)
{
if (hand.KeyPose == type)
{
if (hand.HandKeyPoseConfidence > 0.9f)
{
return true;
}
}
}
return false;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.MagicLeap;
public class Bird_0823 : MonoBehaviour
{
public enum HandPoses { Ok, Finger, Thumb, OpenHand, Pinch, NoPose };
public HandPoses pose = HandPoses.NoPose;
public Vector3[] pos;
public GameObject sphereThumb, sphereIndex, sphereWrist, ObjectToPlace;
private MLHandTracking.HandKeyPose[] _gestures;
bool canIPlace = false;
bool canIGrab = false;
public GameObject selectedGameObject;
private void Start()
{
MLHandTracking.Start();
_gestures = new MLHandTracking.HandKeyPose[5];
_gestures[0] = MLHandTracking.HandKeyPose.Ok;
_gestures[1] = MLHandTracking.HandKeyPose.Finger;
_gestures[2] = MLHandTracking.HandKeyPose.OpenHand;
_gestures[3] = MLHandTracking.HandKeyPose.Fist;
_gestures[4] = MLHandTracking.HandKeyPose.Thumb;
MLHandTracking.KeyPoseManager.EnableKeyPoses(_gestures, true, false);
pos = new Vector3[3];
}
private void OnDestroy()
{
MLHandTracking.Stop();
}
private void Update()
{
ShowPoints();
transform.position = pos[1];
if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Ok))
{
pose = HandPoses.Ok;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Finger))
{
pose = HandPoses.Finger;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.OpenHand))
{
pose = HandPoses.OpenHand;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Pinch))
{
pose = HandPoses.Pinch;
}
else if (GetGesture(MLHandTracking.Left, MLHandTracking.HandKeyPose.Thumb))
{
pose = HandPoses.Thumb;
if (canIPlace == true)
{
GameObject placedObject = Instantiate(ObjectToPlace, pos[0], transform.rotation);
canIPlace = false;
}
}
else
{
pose = HandPoses.NoPose;
//canIPlace = true;
if (selectedGameObject && canIGrab == false)
{
selectedGameObject = null;
gameObject.GetComponent<SphereCollider>().radius = 0.01f;
}
}
}
private void ShowPoints()
{
// Left Hand Thumb tip
pos[0] = MLHandTracking.Left.Thumb.KeyPoints[2].Position;
// Left Hand Index finger tip
pos[1] = MLHandTracking.Left.Index.KeyPoints[2].Position;
// Left Hand Wrist
pos[2] = MLHandTracking.Left.Wrist.KeyPoints[0].Position;
sphereThumb.transform.position = pos[0];
sphereIndex.transform.position = pos[1];
sphereWrist.transform.position = pos[2];
}
private bool GetGesture(MLHandTracking.Hand hand, MLHandTracking.HandKeyPose type)
{
if (hand != null)
{
if (hand.KeyPose == type)
{
if (hand.HandKeyPoseConfidence > 0.9f)
{
return true;
}
}
}
return false;
}
}
댓글
댓글 쓰기