LeiaSR SDK 720218b2 v1.32.7.6322 2025-02-13T14:55:38Z
Stable
Example C#

1using System;
2using System.Runtime.InteropServices;
3
4namespace SimulatedReality
5{
6 [StructLayout(LayoutKind.Sequential)]
7 public struct SR_handPose
8 {
9 public ulong frameId;
10 public ulong time;
11 public ulong handId;
12 public ulong side;
13 [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3*21)]
14 public double[] joints;
15 }
16
17 public static class SR
18 {
19 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
20 public delegate void acceptHandPoseCallback(SR_handPose handPose);
21
22#if WIN64
23 [DllImport("SimulatedRealityCore.dll")]
24 public extern static IntPtr newSRContext();
25 [DllImport("SimulatedRealityCore.dll")]
26 public extern static void initializeSRContext(IntPtr context);
27 [DllImport("SimulatedRealityCore.dll")]
28 public extern static void deleteSRContext(IntPtr context);
29 [DllImport("SimulatedRealityHandTrackers.dll")]
30 public extern static IntPtr createHandTracker(IntPtr context);
31 [DllImport("SimulatedRealityHandTrackers.dll")]
32 public extern static IntPtr createHandPoseListener(IntPtr handTracker, acceptHandPoseCallback callback);
33 [DllImport("SimulatedRealityHandTrackers.dll")]
34 public extern static void deleteHandPoseListener(IntPtr handPoseListener);
35#else
36 [DllImport("SimulatedRealityCore32.dll")]
37 public extern static IntPtr newSRContext();
38 [DllImport("SimulatedRealityCore32.dll")]
39 public extern static void initializeSRContext(IntPtr context);
40 [DllImport("SimulatedRealityCore32.dll")]
41 public extern static void deleteSRContext(IntPtr context);
42 [DllImport("SimulatedRealityHandTrackers32.dll")]
43 public extern static IntPtr createHandTracker(IntPtr context);
44 [DllImport("SimulatedRealityHandTrackers32.dll")]
45 public extern static IntPtr createHandPoseListener(IntPtr handTracker, acceptHandPoseCallback callback);
46 [DllImport("SimulatedRealityHandTrackers32.dll")]
47 public extern static void deleteHandPoseListener(IntPtr handPoseListener);
48#endif
49 }
50}
SRAPI void deleteHandPoseListener(SR_handPoseListener handPoseListener)
Cleans up underlying object instances used to facilitate hand pose update callbacks.
SRAPI SR_handPoseListener createHandPoseListener(SR_handTracker handTracker, void(*acceptHandPoseCallback)(SR_handPose))
Create a new callback function to listen to a specific handtracker.
SRAPI SR_handTracker createHandTracker(SRContext context)
Creates a functional HandTracker instance.
SRAPI void deleteSRContext(SRContext context)
Delete and clean up the instance of SRContext.
SRAPI SRContext newSRContext()
Construct an instance of SRContext, the environment in which created senses are kept track of.
SRAPI void initializeSRContext(SRContext context)
Initialize all senses.
Namespace containing all C++ Simulated Reality classes.
Definition: srconfiguration.h:20
C-compatible struct containing the pose of a hand.
Definition: handpose.h:119
1using System;
2using SimulatedReality;
3
4namespace example_cpp
5{
6 class Program
7 {
8 static void Main(string[] args)
9 {
10 SR.acceptHandPoseCallback acceptHandPose = (SR_handPose handPose) =>
11 {
12 Console.WriteLine(handPose.joints[0]);
13 };
14
15 var context = SR.newSRContext();
16 var handTracker = SR.createHandTracker(context);
17 var handPoseListener = SR.createHandPoseListener(handTracker, acceptHandPose);
18 SR.initializeSRContext(context);
19
20 Console.ReadKey();
21
22 SR.deleteHandPoseListener(handPoseListener);
23 SR.deleteSRContext(context);
24 }
25 }
26}