Event.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using UnityEngine;
  4. namespace TouchlessA3D {
  5. using static NativeCalls;
  6. public enum GestureType {
  7. NO_HAND = 0,
  8. HAND = 1,
  9. OPEN_HAND = 2,
  10. CLOSED_HAND = 3,
  11. CLOSED_PINCH = 4,
  12. GESTURE_TYPE_END = 5
  13. }
  14. public enum HandednessType{
  15. HANDEDNESS_UNKNOWN = 0,
  16. LEFT_HAND = 1,
  17. RIGH_HAND = 2
  18. }
  19. public class GestureEvent : EventArgs {
  20. public readonly GestureType type;
  21. public readonly bool skeletonValid;
  22. public readonly Skeleton skeleton;
  23. public readonly HandednessType handedness;
  24. public GestureEvent (IntPtr ta3d_event) {
  25. type = ta3d_event_get_type (ta3d_event);
  26. handedness = ta3d_get_handedness(ta3d_event);
  27. IntPtr skeletonPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ta3d_skeleton_3d_s)));
  28. try{
  29. ta3d_skeleton_points_3d(ta3d_event, skeletonPtr);
  30. ta3d_skeleton_3d_s skeletonPoints;
  31. skeletonPoints = (ta3d_skeleton_3d_s)Marshal.PtrToStructure(skeletonPtr,typeof(ta3d_skeleton_3d_s));
  32. skeletonValid = skeletonPoints.status == ResultType.RESULT_OK;
  33. if(!skeletonValid) {
  34. return;
  35. }
  36. skeleton = new Skeleton(skeletonPoints.points);
  37. } finally {
  38. Marshal.FreeHGlobal(skeletonPtr);
  39. }
  40. }
  41. public GestureEvent (GestureEvent toCopy) {
  42. type = toCopy.type;
  43. skeletonValid = toCopy.skeletonValid;
  44. skeleton = toCopy.skeleton;
  45. handedness = toCopy.handedness;
  46. }
  47. }
  48. }