Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added an event for the raw tracking frame #1560

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/Tracking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Support for reading the camera matrix
- Raise RawFrameEvent for the raw tracking frame

### Changed
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public event EventHandler<ConnectionEventArgs> LeapConnection
public EventHandler<DeviceFailureEventArgs> LeapDeviceFailure;
public EventHandler<PolicyEventArgs> LeapPolicyChange;
public EventHandler<FrameEventArgs> LeapFrame;
public EventHandler<RawFrameEventArgs> LeapRawFrameData;
public EventHandler<InternalFrameEventArgs> LeapInternalFrame;
public EventHandler<LogEventArgs> LeapLogEvent;
[Obsolete("Config is not used in Ultraleap's Tracking Service 5.X+. This will be removed in the next Major release")]
Expand Down Expand Up @@ -413,6 +414,11 @@ private void handleTrackingMessage(ref LEAP_TRACKING_EVENT trackingMsg, UInt32 d
{
Frames.Put(ref trackingMsg);

if (LeapRawFrameData != null)
{
LeapRawFrameData.DispatchOnContext(this, EventContext, new RawFrameEventArgs(trackingMsg));
}

if (LeapFrame != null)
{
LeapFrame.DispatchOnContext(this, EventContext, new FrameEventArgs(new Frame(deviceID).CopyFrom(ref trackingMsg)));
Expand Down
15 changes: 15 additions & 0 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ public event EventHandler<FrameEventArgs> FrameReady
}
}

/// <summary>
/// Dispatched when the raw frame data is ready
/// </summary>
public event EventHandler<RawFrameEventArgs> RawFrameReady
{
add
{
_connection.LeapRawFrameData += value;
}
remove
{
_connection.LeapRawFrameData -= value;
}
}

/// <summary>
/// Dispatched when an internal tracking frame is ready.
/// @since 3.0
Expand Down
37 changes: 37 additions & 0 deletions Packages/Tracking/Core/Runtime/Plugins/LeapCSharp/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ public LeapEventArgs(LeapEvent type)
public LeapEvent type { get; set; }
}

/// <summary>
/// Provides access to the raw leap frame data
/// </summary>
public class RawFrameEventArgs : LeapEventArgs
{
public bool IsTrackingLeftHand { get; set; }
public LEAP_HAND LeftHand { get; set; }

public bool IsTrackingRightHand { get; set; }
public LEAP_HAND RightHand { get; set; }

public RawFrameEventArgs(LEAP_TRACKING_EVENT trackingMsg) : base(LeapEvent.EVENT_FRAME)
{
IsTrackingLeftHand = false;
IsTrackingRightHand = false;

for (int i = (int)trackingMsg.nHands; i-- != 0;)
{
LEAP_HAND hand;
StructMarshal<LEAP_HAND>.ArrayElementToStruct(trackingMsg.pHands, i, out hand);

switch (hand.type)
{
case eLeapHandType.eLeapHandType_Left:
LeftHand = hand;
IsTrackingLeftHand = true;
break;

case eLeapHandType.eLeapHandType_Right:
RightHand = hand;
IsTrackingRightHand = true;
break;
}
}
}
}

/// <summary>
/// Dispatched when a tracking frame is ready.
///
Expand Down