using System; using UnityEngine; namespace Leap.Unity { public abstract class HandModel : IHandModel { public override Chirality Handedness { get { return this.handedness; } set { this.handedness = value; } } public abstract override ModelType HandModelType { get; } public Vector3 GetPalmPosition() { return this.hand_.PalmPosition.ToVector3(); } public Quaternion GetPalmRotation() { if (this.hand_ != null) { return this.hand_.Basis.CalculateRotation(); } if (this.palm) { return this.palm.rotation; } return Quaternion.identity; } public Vector3 GetPalmDirection() { if (this.hand_ != null) { return this.hand_.Direction.ToVector3(); } if (this.palm) { return this.palm.forward; } return Vector3.forward; } public Vector3 GetPalmNormal() { if (this.hand_ != null) { return this.hand_.PalmNormal.ToVector3(); } if (this.palm) { return -this.palm.up; } return -Vector3.up; } public Vector3 GetArmDirection() { if (this.hand_ != null) { return this.hand_.Arm.Direction.ToVector3(); } if (this.forearm) { return this.forearm.forward; } return Vector3.forward; } public Vector3 GetArmCenter() { if (this.hand_ != null) { Vector vector = 0.5f * (this.hand_.Arm.WristPosition + this.hand_.Arm.ElbowPosition); return vector.ToVector3(); } if (this.forearm) { return this.forearm.position; } return Vector3.zero; } public float GetArmLength() { return (this.hand_.Arm.WristPosition - this.hand_.Arm.ElbowPosition).Magnitude; } public float GetArmWidth() { return this.hand_.Arm.Width; } public Vector3 GetElbowPosition() { if (this.hand_ != null) { return this.hand_.Arm.ElbowPosition.ToVector3(); } if (this.elbowJoint) { return this.elbowJoint.position; } return Vector3.zero; } public Vector3 GetWristPosition() { if (this.hand_ != null) { return this.hand_.Arm.WristPosition.ToVector3(); } if (this.wristJoint) { return this.wristJoint.position; } return Vector3.zero; } public Quaternion GetArmRotation() { if (this.hand_ != null) { return this.hand_.Arm.Rotation.ToQuaternion(); } if (this.forearm) { return this.forearm.rotation; } return Quaternion.identity; } public override Hand GetLeapHand() { return this.hand_; } public override void SetLeapHand(Hand hand) { this.hand_ = hand; for (int i = 0; i < this.fingers.Length; i++) { if (this.fingers[i] != null) { this.fingers[i].SetLeapHand(this.hand_); } } } public override void InitHand() { for (int i = 0; i < this.fingers.Length; i++) { if (this.fingers[i] != null) { this.fingers[i].fingerType = (Finger.FingerType)i; this.fingers[i].InitFinger(); } } } public int LeapID() { if (this.hand_ != null) { return this.hand_.Id; } return -1; } public abstract override void UpdateHand(); [SerializeField] private Chirality handedness; private ModelType handModelType; public const int NUM_FINGERS = 5; public float handModelPalmWidth = 0.085f; public FingerModel[] fingers = new FingerModel[5]; public Transform palm; public Transform forearm; public Transform wristJoint; public Transform elbowJoint; protected Hand hand_; } }