/*--------------------------------------------------------------------------------------------*/ private void UpdateForPalm(Hand pLeapHand) { IsAvailable = true; Position = pLeapHand.PalmPosition.ToUnityScaled(); Rotation = LeapUtil.CalcQuaternion(pLeapHand.Basis); //GC_ALLOC Size = pLeapHand.PalmWidth * SizeScaleFactor; }
/*--------------------------------------------------------------------------------------------*/ internal void Rebuild(Hand pLeapHand) { if (pLeapHand == null) { IsAvailable = false; Position = Vector3.zero; Rotation = Quaternion.identity; Radius = 0; NavigateBackStrength = 0; DisplayStrength = 0; return; } IsAvailable = true; Position = pLeapHand.PalmPosition.ToUnityScaled(); Rotation = LeapUtil.CalcQuaternion(pLeapHand.Basis); //GC_ALLOC Radius = 0.01f; FingerList leapFingers = pLeapHand.Fingers; //GC_ALLOC for (int i = 0; i < leapFingers.Count; i++) { Finger leapFinger = leapFingers[i]; //GC_ALLOC if (leapFinger == null || !leapFinger.IsValid) { continue; } Vector3 palmToFinger = leapFinger.TipPosition.ToUnityScaled() - Position; //GC_ALLOC Bone bone = leapFinger.Bone(Bone.BoneType.TYPE_DISTAL); //GC_ALLOC Quaternion boneRot = LeapUtil.CalcQuaternion(bone.Basis); //GC_ALLOC Radius = Math.Max(Radius, palmToFinger.sqrMagnitude); Rotation = Quaternion.Slerp(Rotation, boneRot, 0.1f); } Radius = (float)Math.Sqrt(Radius); Position += Rotation * Vector3.down * vSettings.DistanceFromPalm * Radius; NavigateBackStrength = pLeapHand.GrabStrength / vSettings.NavBackGrabThreshold; NavigateBackStrength = Mathf.Clamp(NavigateBackStrength, 0, 1); DisplayStrength = Vector3.Dot(pLeapHand.PalmNormal.ToUnity(), vSettings.PalmDirection); DisplayStrength = Mathf.Clamp((DisplayStrength - 0.7f) / 0.25f, 0, 1); }
/*--------------------------------------------------------------------------------------------*/ private void UpdateForFinger(Hand pLeapHand, Finger.FingerType pLeapFingerType) { Finger leapFinger = LeapUtil.GetValidFinger(pLeapHand, pLeapFingerType); if (leapFinger == null) { UpdateForNull(); return; } Bone bone = leapFinger.Bone(Bone.BoneType.TYPE_DISTAL); //GC_ALLOC IsAvailable = true; Position = leapFinger.TipPosition.ToUnityScaled(); //GC_ALLOC Rotation = LeapUtil.CalcQuaternion(bone.Basis); //GC_ALLOC Size = leapFinger.Width * SizeScaleFactor; }
/*--------------------------------------------------------------------------------------------*/ private void UpdateForFinger(Hand pLeapHand, Finger.FingerType pLeapFingerType) { Finger leapFinger = pLeapHand.Fingers .FingerType(pLeapFingerType) .FirstOrDefault(f => f.IsValid); if (leapFinger == null) { UpdateForNull(); return; } Bone bone = leapFinger.Bone(Bone.BoneType.TYPE_DISTAL); IsAvailable = true; Position = leapFinger.TipPosition.ToUnityScaled(); Rotation = LeapUtil.CalcQuaternion(bone.Basis); Size = leapFinger.Width * SizeScaleFactor; }