Update to latest LeapCSharp and LeapC SDK

This commit is contained in:
SDraw 2022-04-13 10:09:55 +03:00
parent 450968964d
commit 987aa798ba
No known key found for this signature in database
GPG key ID: BB95B4DAB2BB8BB5
8 changed files with 257 additions and 26 deletions

View file

@ -409,19 +409,41 @@ namespace LeapInternal
}
public UInt64 GetInterpolatedFrameSize(Int64 time)
public UInt64 GetInterpolatedFrameSize(Int64 time, Device device = null)
{
UInt64 size = 0;
eLeapRS result = LeapC.GetFrameSize(_leapConnection, time, out size);
eLeapRS result;
if (device != null)
{
result = LeapC.GetFrameSizeEx(_leapConnection, device.Handle, time, out size);
}
else
{
result = LeapC.GetFrameSize(_leapConnection, time, out size);
}
reportAbnormalResults("LeapC get interpolated frame call was ", result);
return size;
}
public void GetInterpolatedFrame(Frame toFill, Int64 time)
public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null)
{
UInt64 size = GetInterpolatedFrameSize(time);
UInt64 size = GetInterpolatedFrameSize(time, device);
IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
eLeapRS result = LeapC.InterpolateFrame(_leapConnection, time, trackingBuffer, size);
eLeapRS result;
if (device != null)
{
result = LeapC.InterpolateFrameEx(_leapConnection, device.Handle, time, trackingBuffer, size);
}
else
{
result = LeapC.InterpolateFrame(_leapConnection, time, trackingBuffer, size);
}
reportAbnormalResults("LeapC get interpolated frame call was ", result);
if (result == eLeapRS.eLeapRS_Success)
{
@ -432,11 +454,22 @@ namespace LeapInternal
Marshal.FreeHGlobal(trackingBuffer);
}
public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime)
public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime, Device device = null)
{
UInt64 size = GetInterpolatedFrameSize(time);
UInt64 size = GetInterpolatedFrameSize(time, device);
IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
eLeapRS result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
eLeapRS result;
if (device != null)
{
result = LeapC.InterpolateFrameFromTimeEx(_leapConnection, device.Handle, time, sourceTime, trackingBuffer, size);
}
else
{
result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
}
reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
if (result == eLeapRS.eLeapRS_Success)
{
@ -447,10 +480,10 @@ namespace LeapInternal
Marshal.FreeHGlobal(trackingBuffer);
}
public Frame GetInterpolatedFrame(Int64 time)
public Frame GetInterpolatedFrame(Int64 time, Device device = null)
{
Frame frame = new Frame();
GetInterpolatedFrame(frame, time);
GetInterpolatedFrame(frame, time, device);
return frame;
}
@ -471,15 +504,26 @@ namespace LeapInternal
Int64 sourceTime,
Int64 leftId,
Int64 rightId,
Device device,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
leftTransform = LeapTransform.Identity;
rightTransform = LeapTransform.Identity;
UInt64 size = GetInterpolatedFrameSize(time);
UInt64 size = GetInterpolatedFrameSize(time, device);
IntPtr trackingBuffer = Marshal.AllocHGlobal((Int32)size);
eLeapRS result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
eLeapRS result;
if (device != null)
{
result = LeapC.InterpolateFrameFromTimeEx(_leapConnection, device.Handle, time, sourceTime, trackingBuffer, size);
}
else
{
result = LeapC.InterpolateFrameFromTime(_leapConnection, time, sourceTime, trackingBuffer, size);
}
reportAbnormalResults("LeapC get interpolated frame from time call was ", result);
if (result == eLeapRS.eLeapRS_Success)
@ -516,6 +560,17 @@ namespace LeapInternal
}
Marshal.FreeHGlobal(trackingBuffer);
}
public void GetInterpolatedLeftRightTransform(Int64 time,
Int64 sourceTime,
Int64 leftId,
Int64 rightId,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, null, out leftTransform, out rightTransform);
}
private void handleConnection(ref LEAP_CONNECTION_EVENT connectionMsg)
@ -545,7 +600,6 @@ namespace LeapInternal
device.UpdateStatus(statusEvent.status);
}
private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg)
{
IntPtr deviceHandle = deviceMsg.device.handle;

View file

@ -497,6 +497,17 @@ namespace Leap
}
}
/// <summary>
/// Returns the current Leap service version information.
/// </summary>
public LEAP_VERSION ServiceVersion
{
get
{
return _connection.GetCurrentServiceVersion();
}
}
/// <summary>
/// Checks whether a minimum or required tracking service version is installed.
/// Gets the currently installed service version from the connection and checks whether
@ -634,20 +645,28 @@ namespace Leap
return new Frame().CopyFrom(Frame(history)).Transform(trs);
}
/// <summary>
/// Returns the Frame at the specified time, interpolating the data between existing frames, if necessary.
/// </summary>
public Frame GetInterpolatedFrame(Int64 time, Device device = null)
{
return _connection.GetInterpolatedFrame(time, device);
}
/// <summary>
/// Returns the Frame at the specified time, interpolating the data between existing frames, if necessary.
/// </summary>
public Frame GetInterpolatedFrame(Int64 time)
{
return _connection.GetInterpolatedFrame(time);
return GetInterpolatedFrame(time, null);
}
/// <summary>
/// Fills the Frame with data taken at the specified time, interpolating the data between existing frames, if necessary.
/// </summary>
public void GetInterpolatedFrame(Frame toFill, Int64 time)
public void GetInterpolatedFrame(Frame toFill, Int64 time, Device device = null)
{
_connection.GetInterpolatedFrame(toFill, time);
_connection.GetInterpolatedFrame(toFill, time, device);
}
/// <summary>
@ -730,6 +749,27 @@ namespace Leap
_connection.GetPointMapping(ref pointMapping);
}
/// <summary>
/// This is a special variant of GetInterpolatedFrameFromTime, for use with special
/// features that only require the position and orientation of the palm positions, and do
/// not care about pose data or any other data.
///
/// You must specify the id of the hand that you wish to get a transform for. If you specify
/// an id that is not present in the interpolated frame, the output transform will be the
/// identity transform.
/// </summary>
public void GetInterpolatedLeftRightTransform(Int64 time,
Int64 sourceTime,
int leftId,
int rightId,
Device device,
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
_connection.GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, device, out leftTransform, out rightTransform);
}
/// <summary>
/// This is a special variant of GetInterpolatedFrameFromTime, for use with special
/// features that only require the position and orientation of the palm positions, and do
@ -746,12 +786,12 @@ namespace Leap
out LeapTransform leftTransform,
out LeapTransform rightTransform)
{
_connection.GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, out leftTransform, out rightTransform);
GetInterpolatedLeftRightTransform(time, sourceTime, leftId, rightId, null, out leftTransform, out rightTransform);
}
public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime)
public void GetInterpolatedFrameFromTime(Frame toFill, Int64 time, Int64 sourceTime, Device device = null)
{
_connection.GetInterpolatedFrameFromTime(toFill, time, sourceTime);
_connection.GetInterpolatedFrameFromTime(toFill, time, sourceTime, device);
}
/// <summary>

View file

@ -578,6 +578,11 @@ namespace LeapInternal
public Int32 major;
public Int32 minor;
public Int32 patch;
public new string ToString()
{
return major + "." + minor + "." + patch;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@ -657,6 +662,13 @@ namespace LeapInternal
public float framerate;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LEAP_TRACKING_MODE_EVENT
{
public UInt32 reserved;
public eLeapTrackingMode current_tracking_mode;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LEAP_DROPPED_FRAME_EVENT
{
@ -699,6 +711,8 @@ namespace LeapInternal
public Int64 timestamp;
public LEAP_VECTOR head_position;
public LEAP_QUATERNION head_orientation;
public LEAP_VECTOR head_linear_velocity;
public LEAP_VECTOR head_angular_velocity;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
@ -965,9 +979,15 @@ namespace LeapInternal
[DllImport("LeapC", EntryPoint = "LeapSetTrackingMode")]
public static extern eLeapRS SetTrackingMode(IntPtr hConnection, eLeapTrackingMode mode);
[DllImport("LeapC", EntryPoint = "LeapSetTrackingModeEx")]
public static extern eLeapRS SetTrackingModeEx(IntPtr hConnection, IntPtr hDevice, eLeapTrackingMode mode);
[DllImport("LeapC", EntryPoint = "LeapGetTrackingMode")]
public static extern eLeapRS LeapGetTrackingMode(IntPtr hConnection);
[DllImport("LeapC", EntryPoint = "LeapGetTrackingModeEx")]
public static extern eLeapRS LeapGetTrackingModeEx(IntPtr hConnection, IntPtr hDevice);
[DllImport("LeapC", EntryPoint = "LeapGetNow")]
public static extern long GetNow();
@ -1017,6 +1037,9 @@ namespace LeapInternal
[DllImport("LeapC", EntryPoint = "LeapOpenDevice")]
public static extern eLeapRS OpenDevice(LEAP_DEVICE_REF rDevice, out IntPtr pDevice);
[DllImport("LeapC", EntryPoint = "LeapSetPrimaryDevice")]
public static extern eLeapRS LeapSetPrimaryDevice(IntPtr hConnection, IntPtr hDevice, bool unsubscribeOthers);
[DllImport("LeapC", EntryPoint = "LeapSubscribeEvents")]
public static extern eLeapRS LeapSubscribeEvents(IntPtr hConnection, IntPtr hDevice);
@ -1029,11 +1052,12 @@ namespace LeapInternal
[DllImport("LeapC", EntryPoint = "LeapGetDeviceTransform")]
public static extern eLeapRS GetDeviceTransform(IntPtr hDevice, out float[] transform);
// Will be a SetPolicyFlagsEx()..
[DllImport("LeapC", EntryPoint = "LeapSetPolicyFlags")]
public static extern eLeapRS SetPolicyFlags(IntPtr hConnection, UInt64 set, UInt64 clear);
[DllImport("LeapC", EntryPoint = "LeapSetPolicyFlagsEx")]
public static extern eLeapRS SetPolicyFlagsEx(IntPtr hConnection, IntPtr hDevice, UInt64 set, UInt64 clear);
[DllImport("LeapC", EntryPoint = "LeapSetPause")]
public static extern eLeapRS LeapSetPause(IntPtr hConnection, bool pause);
@ -1046,12 +1070,21 @@ namespace LeapInternal
[DllImport("LeapC", EntryPoint = "LeapGetFrameSize")]
public static extern eLeapRS GetFrameSize(IntPtr hConnection, Int64 timestamp, out UInt64 pncbEvent);
[DllImport("LeapC", EntryPoint = "LeapGetFrameSizeEx")]
public static extern eLeapRS GetFrameSizeEx(IntPtr hConnection, IntPtr hDevice, Int64 timestamp, out UInt64 pncbEvent);
[DllImport("LeapC", EntryPoint = "LeapInterpolateFrame")]
public static extern eLeapRS InterpolateFrame(IntPtr hConnection, Int64 timestamp, IntPtr pEvent, UInt64 ncbEvent);
[DllImport("LeapC", EntryPoint = "LeapInterpolateFrameEx")]
public static extern eLeapRS InterpolateFrameEx(IntPtr hConnection, IntPtr hDevice, Int64 timestamp, IntPtr pEvent, UInt64 ncbEvent);
[DllImport("LeapC", EntryPoint = "LeapInterpolateFrameFromTime")]
public static extern eLeapRS InterpolateFrameFromTime(IntPtr hConnection, Int64 timestamp, Int64 sourceTimestamp, IntPtr pEvent, UInt64 ncbEvent);
[DllImport("LeapC", EntryPoint = "LeapInterpolateFrameFromTimeEx")]
public static extern eLeapRS InterpolateFrameFromTimeEx(IntPtr hConnection, IntPtr hDevice, Int64 timestamp, Int64 sourceTimestamp, IntPtr pEvent, UInt64 ncbEvent);
[DllImport("LeapC", EntryPoint = "LeapInterpolateHeadPose")]
public static extern eLeapRS InterpolateHeadPose(IntPtr hConnection, Int64 timestamp, ref LEAP_HEAD_POSE_EVENT headPose);