123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- 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_;
- }
- }
|