Logic rewrite

Update to LeapCSharp 5.13.1
Not tested in VR
This commit is contained in:
SDraw 2022-09-02 13:44:03 +03:00
parent a41f17af82
commit 3609500959
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
21 changed files with 566 additions and 103 deletions

View file

@ -2,7 +2,6 @@
namespace ml_lme namespace ml_lme
{ {
[RequireComponent(typeof(Animator))]
[DisallowMultipleComponent] [DisallowMultipleComponent]
class LeapIK : MonoBehaviour class LeapIK : MonoBehaviour
{ {

View file

@ -1,20 +1,19 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
using ABI_RC.Core.Savior; using ABI_RC.Core.Savior;
using RootMotion.FinalIK;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
namespace ml_lme namespace ml_lme
{ {
[RequireComponent(typeof(IndexIK))]
[DisallowMultipleComponent] [DisallowMultipleComponent]
class LeapTracked : MonoBehaviour class LeapTracked : MonoBehaviour
{ {
bool m_enabled = true; bool m_enabled = true;
bool m_fingersOnly = false; bool m_fingersOnly = false;
bool m_calibrated = false;
Animator m_animator = null;
IndexIK m_indexIK = null; IndexIK m_indexIK = null;
VRIK m_vrIK = null;
LeapIK m_leapIK = null; LeapIK m_leapIK = null;
Transform m_leftHand = null; Transform m_leftHand = null;
@ -27,58 +26,24 @@ namespace ml_lme
m_indexIK = this.GetComponent<IndexIK>(); m_indexIK = this.GetComponent<IndexIK>();
m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles"); m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles");
if((m_indexIK != null) && (m_animator != null)) if(PlayerSetup.Instance._inVr)
{ PlayerSetup.Instance.avatarSetupCompleted.AddListener(this.OnAvatarSetup);
if(!PlayerSetup.Instance._inVr)
{
// Seems that VR mode always calibrates IndexIK, so let's force it
m_indexIK.avatarAnimator = m_animator;
m_indexIK.Recalibrate();
}
m_calibrated = true;
m_indexIK.activeControl = (m_enabled || m_knucklesInUse);
CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse);
m_leapIK = m_animator.gameObject.AddComponent<LeapIK>();
m_leapIK.SetEnabled(m_enabled);
m_leapIK.SetFingersOnly(m_fingersOnly);
m_leapIK.SetHands(m_leftHand, m_rightHand);
}
} }
public void SetEnabled(bool p_state) public void SetEnabled(bool p_state)
{ {
m_enabled = p_state; m_enabled = p_state;
if(m_enabled)
if(m_indexIK != null)
{ {
if((m_animator != null) && (m_indexIK != null)) m_indexIK.activeControl = (m_enabled || m_knucklesInUse);
{ CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse);
m_indexIK.activeControl = true;
if(!m_calibrated && !PlayerSetup.Instance._inVr)
{
m_indexIK.avatarAnimator = m_animator;
m_indexIK.Recalibrate();
m_calibrated = true;
}
CVRInputManager.Instance.individualFingerTracking = true;
}
}
else
{
if((m_indexIK != null) && m_calibrated)
{
m_indexIK.activeControl = m_knucklesInUse;
CVRInputManager.Instance.individualFingerTracking = m_knucklesInUse;
}
} }
if(m_leapIK != null) if(m_leapIK != null)
m_leapIK.SetEnabled(m_enabled); m_leapIK.SetEnabled(m_enabled);
} }
public void SetAnimator(Animator p_animator) => m_animator = p_animator;
public void SetFingersOnly(bool p_state) public void SetFingersOnly(bool p_state)
{ {
m_fingersOnly = p_state; m_fingersOnly = p_state;
@ -137,5 +102,66 @@ namespace ml_lme
} }
} }
} }
public void UpdateTrackingLate(GestureMatcher.GesturesData p_gesturesData)
{
if(m_enabled && !m_fingersOnly && (m_vrIK != null) && m_vrIK.enabled)
{
if(p_gesturesData.m_handsPresenses[0])
{
IKSolverVR.Arm l_arm = m_vrIK.solver?.leftArm;
if(l_arm?.target != null)
{
if(l_arm.positionWeight < 1f)
l_arm.positionWeight = 1f;
l_arm.target.position = p_gesturesData.m_handsPositons[0];
if(l_arm.rotationWeight < 1f)
l_arm.rotationWeight = 1f;
l_arm.target.rotation = p_gesturesData.m_handsRotations[0];
}
}
if(p_gesturesData.m_handsPresenses[1])
{
IKSolverVR.Arm l_arm = m_vrIK.solver?.rightArm;
if(l_arm?.target != null)
{
if(l_arm.positionWeight < 1f)
l_arm.positionWeight = 1f;
l_arm.target.position = p_gesturesData.m_handsPositons[1];
if(l_arm.rotationWeight < 1f)
l_arm.rotationWeight = 1f;
l_arm.target.rotation = p_gesturesData.m_handsRotations[1];
}
}
}
}
public void OnAvatarClear()
{
m_leapIK = null;
m_vrIK = null;
}
public void OnAvatarSetup()
{
m_knucklesInUse = PlayerSetup.Instance._trackerManager.trackerNames.Contains("knuckles");
if(m_indexIK != null)
m_indexIK.activeControl = (m_enabled || m_knucklesInUse);
CVRInputManager.Instance.individualFingerTracking = (m_enabled || m_knucklesInUse);
if(!PlayerSetup.Instance._inVr)
{
m_leapIK = PlayerSetup.Instance._animator.gameObject.AddComponent<LeapIK>();
m_leapIK.SetEnabled(m_enabled);
m_leapIK.SetFingersOnly(m_fingersOnly);
m_leapIK.SetHands(m_leftHand, m_rightHand);
}
else
m_vrIK = PlayerSetup.Instance._animator.GetComponent<VRIK>();
}
} }
} }

View file

@ -1,5 +1,4 @@
using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Player;
using ABI_RC.Core.Player;
using ABI_RC.Core.UI; using ABI_RC.Core.UI;
using UnityEngine; using UnityEngine;
@ -21,6 +20,8 @@ namespace ml_lme
GameObject m_leapControllerModel = null; GameObject m_leapControllerModel = null;
LeapTracked m_leapTracked = null; LeapTracked m_leapTracked = null;
static bool ms_vrState = false;
public override void OnApplicationStart() public override void OnApplicationStart()
{ {
if(ms_instance == null) if(ms_instance == null)
@ -59,6 +60,11 @@ namespace ml_lme
null, null,
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)) new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnAvatarClear_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
); );
HarmonyInstance.Patch(
typeof(PlayerSetup).GetMethod("SetupAvatarGeneral", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic),
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnSetupAvatarGeneral_Prefix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)),
new HarmonyLib.HarmonyMethod(typeof(LeapMotionExtension).GetMethod(nameof(OnSetupAvatarGeneral_Postfix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic))
);
MelonLoader.MelonCoroutines.Start(CreateTrackingObjects()); MelonLoader.MelonCoroutines.Start(CreateTrackingObjects());
} }
@ -97,6 +103,11 @@ namespace ml_lme
m_leapControllerModel.transform.localRotation = Quaternion.identity; m_leapControllerModel.transform.localRotation = Quaternion.identity;
} }
// Player setup
ms_vrState = PlayerSetup.Instance._inVr;
m_leapTracked = PlayerSetup.Instance.gameObject.AddComponent<LeapTracked>();
m_leapTracked.SetHands(m_leapHands[0].transform, m_leapHands[1].transform);
OnSettingsEnableChange(Settings.Enabled); OnSettingsEnableChange(Settings.Enabled);
OnSettingsFingersOptionChange(Settings.FingersOnly); OnSettingsFingersOptionChange(Settings.FingersOnly);
OnSettingsModelVisibilityChange(Settings.ModelVisibility); OnSettingsModelVisibilityChange(Settings.ModelVisibility);
@ -137,16 +148,22 @@ namespace ml_lme
} }
} }
public override void OnLateUpdate()
{
if(ms_vrState && Settings.Enabled && (m_leapTracked != null))
m_leapTracked.UpdateTrackingLate(m_gesturesData);
}
// Settings changes // Settings changes
void OnSettingsEnableChange(bool p_state) void OnSettingsEnableChange(bool p_state)
{ {
if(p_state) if(p_state)
{ {
m_leapController.StartConnection(); m_leapController?.StartConnection();
UpdateDeviceTrackingMode(); UpdateDeviceTrackingMode();
} }
else else
m_leapController.StopConnection(); m_leapController?.StopConnection();
if(m_leapTracked != null) if(m_leapTracked != null)
m_leapTracked.SetEnabled(p_state); m_leapTracked.SetEnabled(p_state);
@ -177,7 +194,7 @@ namespace ml_lme
void OnSettingsTrackingModeChange(Settings.LeapTrackingMode p_mode) void OnSettingsTrackingModeChange(Settings.LeapTrackingMode p_mode)
{ {
if(Settings.Enabled && (m_leapController != null)) if(Settings.Enabled)
UpdateDeviceTrackingMode(); UpdateDeviceTrackingMode();
if(m_leapControllerModel != null) if(m_leapControllerModel != null)
@ -256,16 +273,16 @@ namespace ml_lme
// Internal utility // Internal utility
void UpdateDeviceTrackingMode() void UpdateDeviceTrackingMode()
{ {
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null); m_leapController?.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
m_leapController.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null); m_leapController?.ClearPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
switch(Settings.TrackingMode) switch(Settings.TrackingMode)
{ {
case Settings.LeapTrackingMode.Screentop: case Settings.LeapTrackingMode.Screentop:
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null); m_leapController?.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_SCREENTOP, null);
break; break;
case Settings.LeapTrackingMode.HMD: case Settings.LeapTrackingMode.HMD:
m_leapController.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null); m_leapController?.SetPolicy(Leap.Controller.PolicyFlag.POLICY_OPTIMIZE_HMD, null);
break; break;
} }
} }
@ -273,8 +290,11 @@ namespace ml_lme
// Leap events // Leap events
void OnLeapDeviceInitialized(object p_sender, Leap.DeviceEventArgs p_args) void OnLeapDeviceInitialized(object p_sender, Leap.DeviceEventArgs p_args)
{ {
if(Settings.Enabled && (m_leapController != null)) if(Settings.Enabled)
{
m_leapController?.SubscribeToDeviceEvents(p_args.Device);
UpdateDeviceTrackingMode(); UpdateDeviceTrackingMode();
}
if(CohtmlHud.Instance != null) if(CohtmlHud.Instance != null)
CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device initialized"); CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device initialized");
@ -288,6 +308,8 @@ namespace ml_lme
void OnLeapDeviceLost(object p_sender, Leap.DeviceEventArgs p_args) void OnLeapDeviceLost(object p_sender, Leap.DeviceEventArgs p_args)
{ {
m_leapController?.UnsubscribeFromDeviceEvents(p_args.Device);
if(CohtmlHud.Instance != null) if(CohtmlHud.Instance != null)
CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device lost"); CohtmlHud.Instance.ViewDropText("Leap Motion Extension", "Device lost");
} }
@ -305,37 +327,32 @@ namespace ml_lme
} }
// Patches // Patches
static void OnAvatarClear_Postfix(ref PlayerSetup __instance) static void OnAvatarClear_Postfix() => ms_instance?.OnAvatarClear();
{
if((__instance != null) && (__instance == PlayerSetup.Instance))
ms_instance?.OnAvatarClear();
}
void OnAvatarClear() void OnAvatarClear()
{ {
if(m_leapTracked != null) if(m_leapTracked != null)
{ m_leapTracked.OnAvatarClear();
Object.DestroyImmediate(m_leapTracked);
m_leapTracked = null;
}
} }
static void OnAvatarSetup_Postfix(ref PlayerSetup __instance) static void OnAvatarSetup_Postfix() => ms_instance?.OnAvatarSetup();
void OnAvatarSetup()
{ {
if((__instance != null) && (__instance == PlayerSetup.Instance)) if(!PlayerSetup.Instance._inVr && (m_leapTracked != null))
ms_instance?.OnAvatarSetup(__instance._animator, __instance.GetComponent<IndexIK>()); m_leapTracked.OnAvatarSetup();
}
void OnAvatarSetup(Animator p_animator, IndexIK p_indexIK)
{
if(m_leapTracked == null)
{
m_leapTracked = p_indexIK.gameObject.AddComponent<LeapTracked>();
m_leapTracked.SetEnabled(Settings.Enabled);
m_leapTracked.SetAnimator(p_animator);
m_leapTracked.SetHands(m_leapHands[0].transform, m_leapHands[1].transform);
m_leapTracked.SetFingersOnly(Settings.FingersOnly);
OnSettingsHeadAttachChange(Settings.HeadAttach); OnSettingsHeadAttachChange(Settings.HeadAttach);
} }
// Sneaky forced IndexIK calibration
static void OnSetupAvatarGeneral_Prefix(ref PlayerSetup __instance)
{
if(__instance != null)
__instance._inVr = true;
}
static void OnSetupAvatarGeneral_Postfix(ref PlayerSetup __instance)
{
if(__instance != null)
__instance._inVr = ms_vrState;
} }
// Utilities // Utilities

View file

@ -5,6 +5,7 @@
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement * * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. * * between Ultraleap and you, your company or other organization. *
******************************************************************************/ ******************************************************************************/
using UnityEngine;
namespace Leap namespace Leap
{ {
@ -29,6 +30,7 @@ namespace Leap
/// Constructs a new Arm object. /// Constructs a new Arm object.
/// @since 3.0 /// @since 3.0
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public Arm(Vector elbow, public Arm(Vector elbow,
Vector wrist, Vector wrist,
Vector center, Vector center,
@ -45,6 +47,25 @@ namespace Leap
BoneType.TYPE_METACARPAL, //ignored for arms BoneType.TYPE_METACARPAL, //ignored for arms
rotation) rotation)
{ } { }
/// <summary>
/// Constructs a new Arm object.
/// </summary>
public Arm(Vector3 elbow,
Vector3 wrist,
Vector3 center,
Vector3 direction,
float length,
float width,
Quaternion rotation)
: base(elbow,
wrist,
center,
direction,
length,
width,
BoneType.TYPE_METACARPAL, //ignored for arms
rotation)
{ }
/// <summary> /// <summary>
/// Compare Arm object equality. /// Compare Arm object equality.
@ -73,6 +94,7 @@ namespace Leap
/// ///
/// @since 2.0.3 /// @since 2.0.3
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector ElbowPosition public Vector ElbowPosition
{ {
get get
@ -90,6 +112,7 @@ namespace Leap
/// ///
/// @since 2.0.3 /// @since 2.0.3
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector WristPosition public Vector WristPosition
{ {
get get

View file

@ -5,6 +5,7 @@
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement * * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. * * between Ultraleap and you, your company or other organization. *
******************************************************************************/ ******************************************************************************/
using UnityEngine;
namespace Leap namespace Leap
{ {
@ -26,7 +27,7 @@ namespace Leap
[Serializable] [Serializable]
public class Bone : IEquatable<Bone> public class Bone : IEquatable<Bone>
{ {
#pragma warning disable 0618
/// <summary> /// <summary>
/// Constructs a default invalid Bone object. /// Constructs a default invalid Bone object.
/// ///
@ -41,6 +42,7 @@ namespace Leap
/// Constructs a new Bone object. /// Constructs a new Bone object.
/// @since 3.0 /// @since 3.0
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use Bone with Vector3s instead. If you believe that it needs to be kept, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
public Bone(Vector prevJoint, public Bone(Vector prevJoint,
Vector nextJoint, Vector nextJoint,
Vector center, Vector center,
@ -60,6 +62,29 @@ namespace Leap
Type = type; Type = type;
} }
/// <summary>
/// Constructs a new Bone object.
/// @since 3.0
/// </summary>
public Bone(Vector3 prevJoint,
Vector3 nextJoint,
Vector3 center,
Vector3 direction,
float length,
float width,
Bone.BoneType type,
Quaternion rotation)
{
PrevJoint = new Vector(prevJoint.x, prevJoint.y, prevJoint.z);
NextJoint = new Vector(nextJoint.x, nextJoint.y, nextJoint.z);
Center = new Vector(center.x, center.y, center.z);
Direction = new Vector(direction.x, direction.y, direction.z);
Rotation = new LeapQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
Length = length;
Width = width;
Type = type;
}
/// <summary> /// <summary>
/// Compare Bone object equality. /// Compare Bone object equality.
/// ///
@ -86,6 +111,7 @@ namespace Leap
/// In anatomical terms, this is the proximal end of the bone. /// In anatomical terms, this is the proximal end of the bone.
/// @since 2.0 /// @since 2.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PrevJoint; public Vector PrevJoint;
/// <summary> /// <summary>
@ -93,18 +119,22 @@ namespace Leap
/// In anatomical terms, this is the distal end of the bone. /// In anatomical terms, this is the distal end of the bone.
/// @since 2.0 /// @since 2.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector NextJoint; public Vector NextJoint;
/// <summary> /// <summary>
/// The midpoint of the bone. /// The midpoint of the bone.
/// @since 2.0 /// @since 2.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Center; public Vector Center;
/// <summary> /// <summary>
/// The normalized direction of the bone from base to tip. /// The normalized direction of the bone from base to tip.
/// @since 2.0 /// @since 2.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Direction; public Vector Direction;
/// <summary> /// <summary>
@ -129,6 +159,7 @@ namespace Leap
/// The orientation of this Bone as a Quaternion. /// The orientation of this Bone as a Quaternion.
/// @since 2.0 /// @since 2.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
public LeapQuaternion Rotation; public LeapQuaternion Rotation;
/// <summary> /// <summary>
@ -179,5 +210,7 @@ namespace Leap
TYPE_INTERMEDIATE = 2, TYPE_INTERMEDIATE = 2,
TYPE_DISTAL = 3 TYPE_DISTAL = 3
} }
#pragma warning restore 0618
} }
} }

View file

@ -16,6 +16,14 @@ namespace Leap
/// </summary> /// </summary>
public static class CSharpExtensions public static class CSharpExtensions
{ {
public static class Constants
{
public const float PI = 3.1415926536f;
public const float DEG_TO_RAD = 0.0174532925f;
public const float RAD_TO_DEG = 57.295779513f;
public const float EPSILON = 1.192092896e-07f;
}
/// <summary> /// <summary>
/// Compares whether two floating point numbers are within an epsilon value of each other. /// Compares whether two floating point numbers are within an epsilon value of each other.
/// @since 3.0 /// @since 3.0

View file

@ -567,7 +567,7 @@ namespace LeapInternal
StructMarshal<LEAP_VECTOR>.PtrToStruct(new IntPtr(posPtr), out position); StructMarshal<LEAP_VECTOR>.PtrToStruct(new IntPtr(posPtr), out position);
StructMarshal<LEAP_QUATERNION>.PtrToStruct(new IntPtr(rotPtr), out orientation); StructMarshal<LEAP_QUATERNION>.PtrToStruct(new IntPtr(rotPtr), out orientation);
LeapTransform transform = new LeapTransform(position.ToLeapVector(), orientation.ToLeapQuaternion()); LeapTransform transform = new LeapTransform(position.ToVector3(), orientation.ToQuaternion());
if (id == leftId) if (id == leftId)
{ {
leftTransform = transform; leftTransform = transform;
@ -1189,6 +1189,7 @@ namespace LeapInternal
/// <summary> /// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates /// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector PixelToRectilinear(Image.CameraType camera, Vector pixel) public Vector PixelToRectilinear(Image.CameraType camera, Vector pixel)
{ {
LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel); LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel);
@ -1200,6 +1201,20 @@ namespace LeapInternal
return new Vector(ray.x, ray.y, ray.z); return new Vector(ray.x, ray.y, ray.z);
} }
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
/// </summary>
public UnityEngine.Vector3 PixelToRectilinear(Image.CameraType camera, UnityEngine.Vector3 pixel)
{
LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel);
LEAP_VECTOR ray = LeapC.LeapPixelToRectilinear(_leapConnection,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
pixelStruct);
return new UnityEngine.Vector3(ray.x, ray.y, ray.z);
}
/// <summary> /// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates /// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
/// ///
@ -1207,6 +1222,7 @@ namespace LeapInternal
/// ///
/// @since 4.1 /// @since 4.1
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector PixelToRectilinearEx(IntPtr deviceHandle, public Vector PixelToRectilinearEx(IntPtr deviceHandle,
Image.CameraType camera, Image.CalibrationType calibType, Vector pixel) Image.CameraType camera, Image.CalibrationType calibType, Vector pixel)
{ {
@ -1222,10 +1238,31 @@ namespace LeapInternal
pixelStruct); pixelStruct);
return new Vector(ray.x, ray.y, ray.z); return new Vector(ray.x, ray.y, ray.z);
} }
/// <summary>
/// Converts from image-space pixel coordinates to camera-space rectilinear coordinates
///
/// Also allows specifying a specific device handle and calibration type.
/// </summary>
public UnityEngine.Vector3 PixelToRectilinearEx(IntPtr deviceHandle,
Image.CameraType camera, Image.CalibrationType calibType, UnityEngine.Vector3 pixel)
{
LEAP_VECTOR pixelStruct = new LEAP_VECTOR(pixel);
LEAP_VECTOR ray = LeapC.LeapPixelToRectilinearEx(_leapConnection,
deviceHandle,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
(calibType == Image.CalibrationType.INFRARED ?
eLeapCameraCalibrationType.eLeapCameraCalibrationType_infrared :
eLeapCameraCalibrationType.eLeapCameraCalibrationType_visual),
pixelStruct);
return new UnityEngine.Vector3(ray.x, ray.y, ray.z);
}
/// <summary> /// <summary>
/// Converts from camera-space rectilinear coordinates to image-space pixel coordinates /// Converts from camera-space rectilinear coordinates to image-space pixel coordinates
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector RectilinearToPixel(Image.CameraType camera, Vector ray) public Vector RectilinearToPixel(Image.CameraType camera, Vector ray)
{ {
LEAP_VECTOR rayStruct = new LEAP_VECTOR(ray); LEAP_VECTOR rayStruct = new LEAP_VECTOR(ray);
@ -1236,6 +1273,19 @@ namespace LeapInternal
rayStruct); rayStruct);
return new Vector(pixel.x, pixel.y, pixel.z); return new Vector(pixel.x, pixel.y, pixel.z);
} }
/// <summary>
/// Converts from camera-space rectilinear coordinates to image-space pixel coordinates
/// </summary>
public UnityEngine.Vector3 RectilinearToPixel(Image.CameraType camera, UnityEngine.Vector3 ray)
{
LEAP_VECTOR rayStruct = new LEAP_VECTOR(ray);
LEAP_VECTOR pixel = LeapC.LeapRectilinearToPixel(_leapConnection,
(camera == Image.CameraType.LEFT ?
eLeapPerspectiveType.eLeapPerspectiveType_stereo_left :
eLeapPerspectiveType.eLeapPerspectiveType_stereo_right),
rayStruct);
return new UnityEngine.Vector3(pixel.x, pixel.y, pixel.z);
}
public void TelemetryProfiling(ref LEAP_TELEMETRY_DATA telemetryData) public void TelemetryProfiling(ref LEAP_TELEMETRY_DATA telemetryData)
{ {
@ -1272,7 +1322,9 @@ namespace LeapInternal
pm.frameId = pmi.frame_id; pm.frameId = pmi.frame_id;
pm.timestamp = pmi.timestamp; pm.timestamp = pmi.timestamp;
#pragma warning disable 0618
pm.points = new Vector[nPoints]; pm.points = new Vector[nPoints];
#pragma warning restore 0618
pm.ids = new UInt32[nPoints]; pm.ids = new UInt32[nPoints];
float[] points = new float[3 * nPoints]; float[] points = new float[3 * nPoints];

View file

@ -428,7 +428,7 @@ namespace Leap
/// ///
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
public Controller() : this(0, null, true) { } public Controller() : this(0) { }
/// <summary> /// <summary>
/// Constructs a Controller object using the specified connection key. /// Constructs a Controller object using the specified connection key.
@ -555,11 +555,30 @@ namespace Leap
/// the change was accepted. /// the change was accepted.
/// @since 2.1.6 (5.4.4 for specific device) /// @since 2.1.6 (5.4.4 for specific device)
/// </summary> /// </summary>
[Obsolete("This method signature will be removed in a future update. Please use the equivalent method that does not take the serial number")]
public void SetAndClearPolicy(PolicyFlag set, PolicyFlag clear, string deviceSerial = "", Device device = null) public void SetAndClearPolicy(PolicyFlag set, PolicyFlag clear, string deviceSerial = "", Device device = null)
{ {
_connection.SetAndClearPolicy(set, clear, device); _connection.SetAndClearPolicy(set, clear, device);
} }
/// <summary>
/// Requests setting and clearing policy flags on a specific device
///
/// A request to change a policy is subject to user approval and a policy
/// can be changed by the user at any time (using the Leap Motion settings dialog).
/// The desired policy flags must be set every time an application runs.
///
/// Policy changes are completed asynchronously and, because they are subject
/// to user approval or system compatibility checks, may not complete successfully. Call
/// Controller.IsPolicySet() after a suitable interval to test whether
/// the change was accepted.
/// @since 2.1.6 (5.4.4 for specific device)
/// </summary>
public void SetAndClearPolicy(PolicyFlag set, PolicyFlag clear, Device device = null)
{
_connection.SetAndClearPolicy(set, clear, device);
}
/// <summary> /// <summary>
/// Requests setting a policy on a specific device /// Requests setting a policy on a specific device
/// ///

View file

@ -9,7 +9,7 @@
namespace LeapInternal namespace LeapInternal
{ {
using Leap; using Leap;
#pragma warning disable 0618
public static class CopyFromLeapCExtensions public static class CopyFromLeapCExtensions
{ {
@ -139,4 +139,5 @@ namespace LeapInternal
return bone; return bone;
} }
} }
#pragma warning restore 0618
} }

View file

@ -8,7 +8,7 @@
namespace Leap namespace Leap
{ {
#pragma warning disable 0618
public static class CopyFromOtherExtensions public static class CopyFromOtherExtensions
{ {
@ -117,4 +117,5 @@ namespace Leap
return bone; return bone;
} }
} }
#pragma warning restore 0618
} }

View file

@ -6,10 +6,12 @@
* between Ultraleap and you, your company or other organization. * * between Ultraleap and you, your company or other organization. *
******************************************************************************/ ******************************************************************************/
using UnityEngine;
namespace Leap namespace Leap
{ {
using System; using System;
#pragma warning disable 0618
/// <summary> /// <summary>
/// The Finger class represents a tracked finger. /// The Finger class represents a tracked finger.
/// ///
@ -46,6 +48,7 @@ namespace Leap
/// received from the service. /// received from the service.
/// @since 3.0 /// @since 3.0
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Finger(long frameId, public Finger(long frameId,
int handId, int handId,
int fingerId, int fingerId,
@ -75,6 +78,42 @@ namespace Leap
IsExtended = isExtended; IsExtended = isExtended;
TimeVisible = timeVisible; TimeVisible = timeVisible;
} }
/// <summary>
/// Constructs a finger.
///
/// Generally, you should not create your own finger objects. Such objects will not
/// have valid tracking data. Get valid finger objects from a hand in a frame
/// received from the service.
/// </summary>
public Finger(long frameId,
int handId,
int fingerId,
float timeVisible,
Vector3 tipPosition,
Vector3 direction,
float width,
float length,
bool isExtended,
FingerType type,
Bone metacarpal,
Bone proximal,
Bone intermediate,
Bone distal)
{
Type = type;
bones[0] = metacarpal;
bones[1] = proximal;
bones[2] = intermediate;
bones[3] = distal;
Id = (handId * 10) + fingerId;
HandId = handId;
TipPosition = ToVector(tipPosition);
Direction = ToVector(direction);
Width = width;
Length = length;
IsExtended = isExtended;
TimeVisible = timeVisible;
}
/// <summary> /// <summary>
/// The bone at a given bone index on this finger. /// The bone at a given bone index on this finger.
@ -125,6 +164,7 @@ namespace Leap
/// The tip position of this Finger. /// The tip position of this Finger.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector TipPosition; public Vector TipPosition;
/// <summary> /// <summary>
@ -132,6 +172,7 @@ namespace Leap
/// as a unit vector pointing in the same direction as the tip. /// as a unit vector pointing in the same direction as the tip.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Direction; public Vector Direction;
/// <summary> /// <summary>
@ -179,5 +220,13 @@ namespace Leap
TYPE_PINKY = 4, TYPE_PINKY = 4,
TYPE_UNKNOWN = -1 TYPE_UNKNOWN = -1
} }
[Obsolete("This will be removed in the next major version update")]
private Vector ToVector(Vector3 v)
{
return new Vector(v.x, v.y, v.z);
}
} }
#pragma warning restore 0618
} }

View file

@ -5,12 +5,13 @@
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement * * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. * * between Ultraleap and you, your company or other organization. *
******************************************************************************/ ******************************************************************************/
using UnityEngine;
namespace Leap namespace Leap
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#pragma warning disable 0618
/// <summary> /// <summary>
/// The Hand class reports the physical characteristics of a detected hand. /// The Hand class reports the physical characteristics of a detected hand.
/// ///
@ -46,6 +47,7 @@ namespace Leap
Fingers.Add(new Finger()); Fingers.Add(new Finger());
} }
/// <summary> /// <summary>
/// Constructs a hand. /// Constructs a hand.
/// ///
@ -54,6 +56,7 @@ namespace Leap
/// received from the service. /// received from the service.
/// @since 3.0 /// @since 3.0
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public Hand(long frameID, public Hand(long frameID,
int id, int id,
float confidence, float confidence,
@ -94,6 +97,53 @@ namespace Leap
Direction = direction; Direction = direction;
WristPosition = wristPosition; WristPosition = wristPosition;
} }
/// <summary>
/// Constructs a hand.
///
/// Generally, you should not create your own Hand objects. Such objects will not
/// have valid tracking data. Get valid Hand objects from a frame
/// received from the service.
/// </summary>
public Hand(long frameID,
int id,
float confidence,
float grabStrength,
float grabAngle,
float pinchStrength,
float pinchDistance,
float palmWidth,
bool isLeft,
float timeVisible,
Arm arm,
List<Finger> fingers,
Vector3 palmPosition,
Vector3 stabilizedPalmPosition,
Vector3 palmVelocity,
Vector3 palmNormal,
Quaternion palmOrientation,
Vector3 direction,
Vector3 wristPosition)
{
FrameId = frameID;
Id = id;
Confidence = confidence;
GrabStrength = grabStrength;
GrabAngle = grabAngle;
PinchStrength = pinchStrength;
PinchDistance = pinchDistance;
PalmWidth = palmWidth;
IsLeft = isLeft;
TimeVisible = timeVisible;
Arm = arm;
Fingers = fingers;
PalmPosition = ToVector(palmPosition);
StabilizedPalmPosition = ToVector(stabilizedPalmPosition);
PalmVelocity = ToVector(palmVelocity);
PalmNormal = ToVector(palmNormal);
Rotation = ToLeapQuaternion(palmOrientation);
Direction = ToVector(direction);
WristPosition = ToVector(wristPosition);
}
/// <summary> /// <summary>
/// The Finger object with the specified ID attached to this hand. /// The Finger object with the specified ID attached to this hand.
@ -171,12 +221,14 @@ namespace Leap
/// The center position of the palm. /// The center position of the palm.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PalmPosition; public Vector PalmPosition;
/// <summary> /// <summary>
/// The rate of change of the palm position. /// The rate of change of the palm position.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PalmVelocity; public Vector PalmVelocity;
/// <summary> /// <summary>
@ -190,6 +242,7 @@ namespace Leap
/// respect to the horizontal plane. /// respect to the horizontal plane.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector PalmNormal; public Vector PalmNormal;
/// <summary> /// <summary>
@ -202,6 +255,7 @@ namespace Leap
/// respect to the horizontal plane. /// respect to the horizontal plane.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector Direction; public Vector Direction;
/// <summary> /// <summary>
@ -217,6 +271,7 @@ namespace Leap
/// ///
/// @since 3.1 /// @since 3.1
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
public LeapQuaternion Rotation; public LeapQuaternion Rotation;
/// <summary> /// <summary>
@ -239,6 +294,7 @@ namespace Leap
/// ///
/// @since 3.0 /// @since 3.0
/// </summary> /// </summary>
[System.Obsolete("This code will be removed in the next major version of the plugin. If you believe that it needs to be kept, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
public float GrabAngle; public float GrabAngle;
/// <summary> /// <summary>
@ -276,16 +332,18 @@ namespace Leap
/// primarily on the speed of movement. /// primarily on the speed of movement.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector StabilizedPalmPosition; public Vector StabilizedPalmPosition;
/// <summary> /// <summary>
/// The position of the wrist of this hand. /// The position of the wrist of this hand.
/// @since 2.0.3 /// @since 2.0.3
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector WristPosition; public Vector WristPosition;
/// <summary> /// <summary>
/// The duration of time this Hand has been visible to the Leap Motion Controller. /// The duration of time this Hand has been visible to the Leap Motion Controller, in seconds
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
public float TimeVisible; public float TimeVisible;
@ -318,5 +376,20 @@ namespace Leap
/// @since 2.0.3 /// @since 2.0.3
/// </summary> /// </summary>
public Arm Arm; public Arm Arm;
[Obsolete("This will be removed in the next major version update")]
private Vector ToVector(Vector3 v)
{
return new Vector(v.x, v.y, v.z);
}
[Obsolete("This will be removed in the next major version update")]
private LeapQuaternion ToLeapQuaternion(Quaternion q)
{
return new LeapQuaternion(q.x, q.y, q.z, q.w);
}
} }
#pragma warning restore 0618
} }

View file

@ -154,6 +154,11 @@ namespace Leap
return imageData(camera).DistortionData.Data; return imageData(camera).DistortionData.Data;
} }
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector PixelToRectilinear(CameraType camera, Vector pixel)
{
return Connection.GetConnection().PixelToRectilinear(camera, pixel);
}
/// <summary> /// <summary>
/// Provides the corrected camera ray intercepting the specified point on the image. /// Provides the corrected camera ray intercepting the specified point on the image.
/// ///
@ -172,13 +177,17 @@ namespace Leap
/// in between the time the image was received and the time this function is called. /// in between the time the image was received and the time this function is called.
/// ///
/// Note, this function was formerly named Rectify(). /// Note, this function was formerly named Rectify().
/// @since 2.1.0
/// </summary> /// </summary>
public Vector PixelToRectilinear(CameraType camera, Vector pixel) public UnityEngine.Vector3 PixelToRectilinear(CameraType camera, UnityEngine.Vector3 pixel)
{ {
return Connection.GetConnection().PixelToRectilinear(camera, pixel); return Connection.GetConnection().PixelToRectilinear(camera, pixel);
} }
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector RectilinearToPixel(CameraType camera, Vector ray)
{
return Connection.GetConnection().RectilinearToPixel(camera, ray);
}
/// <summary> /// <summary>
/// Provides the point in the image corresponding to a ray projecting /// Provides the point in the image corresponding to a ray projecting
/// from the camera. /// from the camera.
@ -202,9 +211,8 @@ namespace Leap
/// in between the time the image was received and the time this function is called. /// in between the time the image was received and the time this function is called.
/// ///
/// Note, this function was formerly named Warp(). /// Note, this function was formerly named Warp().
/// @since 2.1.0
/// </summary> /// </summary>
public Vector RectilinearToPixel(CameraType camera, Vector ray) public UnityEngine.Vector3 RectilinearToPixel(CameraType camera, UnityEngine.Vector3 ray)
{ {
return Connection.GetConnection().RectilinearToPixel(camera, ray); return Connection.GetConnection().RectilinearToPixel(camera, ray);
} }

View file

@ -799,17 +799,29 @@ namespace LeapInternal
public float y; public float y;
public float z; public float z;
[System.Obsolete("This code will be removed in the next major version of the plugin. Use 'ToVector3()' instead.")]
public Leap.Vector ToLeapVector() public Leap.Vector ToLeapVector()
{ {
return new Leap.Vector(x, y, z); return new Leap.Vector(x, y, z);
} }
public UnityEngine.Vector3 ToVector3()
{
return new UnityEngine.Vector3(x, y, z);
}
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one taking a Vector3 instead.")]
public LEAP_VECTOR(Leap.Vector leap) public LEAP_VECTOR(Leap.Vector leap)
{ {
x = leap.x; x = leap.x;
y = leap.y; y = leap.y;
z = leap.z; z = leap.z;
} }
public LEAP_VECTOR(UnityEngine.Vector3 vector)
{
x = vector.x;
y = vector.y;
z = vector.z;
}
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
@ -820,11 +832,17 @@ namespace LeapInternal
public float z; public float z;
public float w; public float w;
[System.Obsolete("This code will be removed in the next major version of the plugin. Use 'ToQuaternion()' instead.")]
public Leap.LeapQuaternion ToLeapQuaternion() public Leap.LeapQuaternion ToLeapQuaternion()
{ {
return new Leap.LeapQuaternion(x, y, z, w); return new Leap.LeapQuaternion(x, y, z, w);
} }
public UnityEngine.Quaternion ToQuaternion()
{
return new UnityEngine.Quaternion(x, y, z, w);
}
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one taking a UnityEngine.Quaternion instead.")]
public LEAP_QUATERNION(Leap.LeapQuaternion q) public LEAP_QUATERNION(Leap.LeapQuaternion q)
{ {
x = q.x; x = q.x;
@ -832,6 +850,13 @@ namespace LeapInternal
z = q.z; z = q.z;
w = q.w; w = q.w;
} }
public LEAP_QUATERNION(UnityEngine.Quaternion q)
{
x = q.x;
y = q.y;
z = q.z;
w = q.w;
}
} }
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]

View file

@ -14,6 +14,7 @@ namespace Leap
/// The LeapQuaternion struct represents a rotation in three-dimensional space. /// The LeapQuaternion struct represents a rotation in three-dimensional space.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This code will be moved to a legacy package in the next major version of the plugin. Use Unity's Quaternion instead. If you believe that it needs to be kept in tracking, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
[Serializable] [Serializable]
public struct LeapQuaternion : public struct LeapQuaternion :
IEquatable<LeapQuaternion> IEquatable<LeapQuaternion>
@ -125,7 +126,7 @@ namespace Leap
get get
{ {
float denom = MagnitudeSquared; float denom = MagnitudeSquared;
if (denom <= Constants.EPSILON) if (denom <= CSharpExtensions.Constants.EPSILON)
{ {
return Identity; return Identity;
} }

View file

@ -5,11 +5,12 @@
* http://www.apache.org/licenses/LICENSE-2.0, or another agreement * * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
* between Ultraleap and you, your company or other organization. * * between Ultraleap and you, your company or other organization. *
******************************************************************************/ ******************************************************************************/
using UnityEngine;
namespace Leap namespace Leap
{ {
using System; using System;
#pragma warning disable 0618
/// <summary> /// <summary>
/// The LeapTransform class represents a transform in three dimensional space. /// The LeapTransform class represents a transform in three dimensional space.
/// ///
@ -22,15 +23,24 @@ namespace Leap
/// Constructs a new transform from the specified translation and rotation. /// Constructs a new transform from the specified translation and rotation.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public LeapTransform(Vector translation, LeapQuaternion rotation) : public LeapTransform(Vector translation, LeapQuaternion rotation) :
this(translation, rotation, Vector.Ones) this(translation, rotation, Vector.Ones)
{ {
} }
/// <summary>
/// Constructs a new transform from the specified translation and rotation.
/// </summary>
public LeapTransform(Vector3 translation, Quaternion rotation) :
this(translation, rotation, Vector3.one)
{
}
/// <summary> /// <summary>
/// Constructs a new transform from the specified translation, rotation and scale. /// Constructs a new transform from the specified translation, rotation and scale.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 and Quaternion instead.")]
public LeapTransform(Vector translation, LeapQuaternion rotation, Vector scale) : public LeapTransform(Vector translation, LeapQuaternion rotation, Vector scale) :
this() this()
{ {
@ -39,33 +49,81 @@ namespace Leap
this.translation = translation; this.translation = translation;
this.rotation = rotation; // Calls validateBasis this.rotation = rotation; // Calls validateBasis
} }
/// <summary>
/// Constructs a new transform from the specified translation, rotation and scale.
/// </summary>
public LeapTransform(Vector3 translation, Quaternion rotation, Vector3 scale) :
this()
{
_scale = ToVector(scale);
// these are non-trival setters.
this.translation = ToVector(translation);
this.rotation = ToLeapQuaternion(rotation); // Calls validateBasis
}
/// <summary>
/// Constructs a new Leap transform from a Unity Transform
/// </summary>
/// <param name="t">Unity Transform</param>
public LeapTransform(Transform t) : this()
{
float MM_TO_M = 1e-3f;
_scale = new Vector(t.lossyScale.x * MM_TO_M, t.lossyScale.y * MM_TO_M, t.lossyScale.z * MM_TO_M);
this.translation = ToVector(t.position);
this.rotation = ToLeapQuaternion(t.rotation);
this.MirrorZ(); // Unity is left handed.
}
/// <summary> /// <summary>
/// Transforms the specified position vector, applying translation, rotation and scale. /// Transforms the specified position vector, applying translation, rotation and scale.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector TransformPoint(Vector point) public Vector TransformPoint(Vector point)
{ {
return _xBasisScaled * point.x + _yBasisScaled * point.y + _zBasisScaled * point.z + translation; return _xBasisScaled * point.x + _yBasisScaled * point.y + _zBasisScaled * point.z + translation;
} }
/// <summary>
/// Transforms the specified position vector, applying translation, rotation and scale.
/// </summary>
public Vector3 TransformPoint(Vector3 point)
{
return ToVector3(_xBasisScaled * point.x + _yBasisScaled * point.y + _zBasisScaled * point.z + translation);
}
/// <summary> /// <summary>
/// Transforms the specified direction vector, applying rotation only. /// Transforms the specified direction vector, applying rotation only.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector TransformDirection(Vector direction) public Vector TransformDirection(Vector direction)
{ {
return _xBasis * direction.x + _yBasis * direction.y + _zBasis * direction.z; return _xBasis * direction.x + _yBasis * direction.y + _zBasis * direction.z;
} }
/// <summary>
/// Transforms the specified direction vector, applying rotation only.
/// </summary>
public Vector3 TransformDirection(Vector3 direction)
{
return ToVector3(_xBasis * direction.x + _yBasis * direction.y + _zBasis * direction.z);
}
/// <summary> /// <summary>
/// Transforms the specified velocity vector, applying rotation and scale. /// Transforms the specified velocity vector, applying rotation and scale.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with Vector3 instead.")]
public Vector TransformVelocity(Vector velocity) public Vector TransformVelocity(Vector velocity)
{ {
return _xBasisScaled * velocity.x + _yBasisScaled * velocity.y + _zBasisScaled * velocity.z; return _xBasisScaled * velocity.x + _yBasisScaled * velocity.y + _zBasisScaled * velocity.z;
} }
/// <summary>
/// Transforms the specified velocity vector, applying rotation and scale.
/// </summary>
public Vector3 TransformVelocity(Vector3 velocity)
{
return ToVector3(_xBasisScaled * velocity.x + _yBasisScaled * velocity.y + _zBasisScaled * velocity.z);
}
/// <summary> /// <summary>
/// Transforms the specified quaternion. /// Transforms the specified quaternion.
@ -78,6 +136,7 @@ namespace Leap
/// ///
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("This signature will be removed in the next major version of the plugin. Use the one with UnityEngine.Quaternion instead.")]
public LeapQuaternion TransformQuaternion(LeapQuaternion rhs) public LeapQuaternion TransformQuaternion(LeapQuaternion rhs)
{ {
if (_quaternionDirty) if (_quaternionDirty)
@ -94,6 +153,31 @@ namespace Leap
LeapQuaternion t = _quaternion.Multiply(rhs); LeapQuaternion t = _quaternion.Multiply(rhs);
return t; return t;
} }
/// <summary>
/// Transforms the specified quaternion.
/// Multiplies the quaternion representing the rotational part of this transform by the specified
/// quaternion.
///
/// **Important:** Modifying the basis vectors of this transform directly leaves the underlying quaternion in
/// an indeterminate state. Neither this function nor the LeapTransform.rotation quaternion can be used after
/// the basis vectors are set.
/// </summary>
public Quaternion TransformQuaternion(Quaternion rhs)
{
if (_quaternionDirty)
throw new InvalidOperationException("Calling TransformQuaternion after Basis vectors have been modified.");
if (_flip)
{
// Mirror the axis of rotation across the flip axis.
rhs.x *= _flipAxes.x;
rhs.y *= _flipAxes.y;
rhs.z *= _flipAxes.z;
}
Quaternion t = ToQuaternion(_quaternion) * rhs;
return t;
}
/// <summary> /// <summary>
/// Mirrors this transform's rotation and scale across the x-axis. Translation is not affected. /// Mirrors this transform's rotation and scale across the x-axis. Translation is not affected.
@ -132,6 +216,7 @@ namespace Leap
/// ///
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector xBasis public Vector xBasis
{ {
get { return _xBasis; } get { return _xBasis; }
@ -152,6 +237,7 @@ namespace Leap
/// ///
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector yBasis public Vector yBasis
{ {
get { return _yBasis; } get { return _yBasis; }
@ -172,6 +258,7 @@ namespace Leap
/// ///
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector zBasis public Vector zBasis
{ {
get { return _zBasis; } get { return _zBasis; }
@ -187,6 +274,7 @@ namespace Leap
/// The translation component of the transform. /// The translation component of the transform.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector translation public Vector translation
{ {
get { return _translation; } get { return _translation; }
@ -201,6 +289,7 @@ namespace Leap
/// Scale is kept separate from translation. /// Scale is kept separate from translation.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from Vector to Vector3")]
public Vector scale public Vector scale
{ {
get { return _scale; } get { return _scale; }
@ -222,6 +311,7 @@ namespace Leap
/// ///
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
public LeapQuaternion rotation public LeapQuaternion rotation
{ {
get get
@ -234,7 +324,7 @@ namespace Leap
{ {
_quaternion = value; _quaternion = value;
float d = value.MagnitudeSquared; float d = value.x * value.x + value.y * value.y + value.z * value.z + value.w * value.w;
float s = 2.0f / d; float s = 2.0f / d;
float xs = value.x * s, ys = value.y * s, zs = value.z * s; float xs = value.x * s, ys = value.y * s, zs = value.z * s;
float wx = value.w * xs, wy = value.w * ys, wz = value.w * zs; float wx = value.w * xs, wy = value.w * ys, wz = value.w * zs;
@ -259,19 +349,54 @@ namespace Leap
/// The identity transform. /// The identity transform.
/// @since 3.1.2 /// @since 3.1.2
/// </summary> /// </summary>
public static readonly LeapTransform Identity = new LeapTransform(Vector.Zero, LeapQuaternion.Identity, Vector.Ones); public static readonly LeapTransform Identity = new LeapTransform(Vector3.zero, Quaternion.identity, Vector3.one);
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _translation; private Vector _translation;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _scale; private Vector _scale;
[System.Obsolete("Its type will be changed from LeapQuaternion to UnityEngine.Quaternion")]
private LeapQuaternion _quaternion; private LeapQuaternion _quaternion;
private bool _quaternionDirty; private bool _quaternionDirty;
private bool _flip; private bool _flip;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _flipAxes; private Vector _flipAxes;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _xBasis; private Vector _xBasis;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _yBasis; private Vector _yBasis;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _zBasis; private Vector _zBasis;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _xBasisScaled; private Vector _xBasisScaled;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _yBasisScaled; private Vector _yBasisScaled;
[System.Obsolete("Its type will be changed from Vector to Vector3")]
private Vector _zBasisScaled; private Vector _zBasisScaled;
[Obsolete("This will be removed in the next major version update")]
private Vector ToVector(Vector3 v)
{
return new Vector(v.x, v.y, v.z);
}
[Obsolete("This will be removed in the next major version update")]
private Vector3 ToVector3(Vector v)
{
return new Vector3(v.x, v.y, v.z);
}
[Obsolete("This will be removed in the next major version update")]
private LeapQuaternion ToLeapQuaternion(Quaternion q)
{
return new LeapQuaternion(q.x, q.y, q.z, q.w);
}
[Obsolete("This will be removed in the next major version update")]
private Quaternion ToQuaternion(LeapQuaternion q)
{
return new Quaternion(q.x, q.y, q.z, q.w);
}
} }
#pragma warning restore 0618
} }

View file

@ -21,6 +21,7 @@ namespace Leap
/// the * operator. /// the * operator.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("This code will be moved to a legacy package in the next major version of the plugin. If you believe that it needs to be kept in tracking, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
public struct Matrix public struct Matrix
{ {

View file

@ -8,7 +8,7 @@
namespace Leap namespace Leap
{ {
#pragma warning disable 0618
public struct PointMapping public struct PointMapping
{ {
public long frameId; public long frameId;
@ -16,4 +16,5 @@ namespace Leap
public Vector[] points; public Vector[] points;
public uint[] ids; public uint[] ids;
} }
#pragma warning restore 0618
} }

View file

@ -53,13 +53,9 @@ namespace LeapInternal
public static void PtrToStruct(IntPtr ptr, out T t) public static void PtrToStruct(IntPtr ptr, out T t)
{ {
#if ENABLE_IL2CPP #if ENABLE_IL2CPP
#if UNITY_2018_1_OR_NEWER
unsafe { unsafe {
Unity.Collections.LowLevel.Unsafe.UnsafeUtility.CopyPtrToStructure((void*)ptr, out t); Unity.Collections.LowLevel.Unsafe.UnsafeUtility.CopyPtrToStructure((void*)ptr, out t);
} }
#else
#error UnityModules Only supports IL2CPP on versions of Unity 2018.1 or greater.
#endif
#else #else
if (_container == null) if (_container == null)
{ {

View file

@ -6,10 +6,12 @@
* between Ultraleap and you, your company or other organization. * * between Ultraleap and you, your company or other organization. *
******************************************************************************/ ******************************************************************************/
using UnityEngine;
namespace Leap namespace Leap
{ {
using System; using System;
#pragma warning disable 0618
public static class TransformExtensions public static class TransformExtensions
{ {
@ -173,4 +175,5 @@ namespace Leap
return new Bone().CopyFrom(bone).Transform(transform); return new Bone().CopyFrom(bone).Transform(transform);
} }
} }
#pragma warning restore 0618
} }

View file

@ -13,6 +13,7 @@ namespace Leap
/// <summary> /// <summary>
/// Constants used in Leap Motion math functions. /// Constants used in Leap Motion math functions.
/// </summary> /// </summary>
[System.Obsolete("This code will be moved to Leap.CSharpExtensions.Constants in the next major version of the plugin.")]
public static class Constants public static class Constants
{ {
public const float PI = 3.1415926536f; public const float PI = 3.1415926536f;
@ -34,6 +35,7 @@ namespace Leap
/// The z-axis has positive values increasing away from the computer screen. /// The z-axis has positive values increasing away from the computer screen.
/// @since 1.0 /// @since 1.0
/// </summary> /// </summary>
[System.Obsolete("This code will be moved to a legacy package in the next major version of the plugin. Use Unity's Vector3 instead. If you believe that it needs to be kept in tracking, please open a discussion on the GitHub forum (https://github.com/ultraleap/UnityPlugin/discussions)")]
[Serializable] [Serializable]
public struct Vector : IEquatable<Vector> public struct Vector : IEquatable<Vector>
{ {
@ -135,7 +137,7 @@ namespace Leap
public float AngleTo(Vector other) public float AngleTo(Vector other)
{ {
float denom = MagnitudeSquared * other.MagnitudeSquared; float denom = MagnitudeSquared * other.MagnitudeSquared;
if (denom <= Constants.EPSILON) if (denom <= CSharpExtensions.Constants.EPSILON)
{ {
return 0.0f; return 0.0f;
} }
@ -146,7 +148,7 @@ namespace Leap
} }
else if (val <= -1.0f) else if (val <= -1.0f)
{ {
return Constants.PI; return CSharpExtensions.Constants.PI;
} }
return (float)Math.Acos(val); return (float)Math.Acos(val);
} }
@ -335,7 +337,7 @@ namespace Leap
get get
{ {
float denom = MagnitudeSquared; float denom = MagnitudeSquared;
if (denom <= Constants.EPSILON) if (denom <= CSharpExtensions.Constants.EPSILON)
{ {
return Zero; return Zero;
} }