BodyFrame.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.BodyFrame
  8. //
  9. public sealed partial class BodyFrame : RootSystem.IDisposable, Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal BodyFrame(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_BodyFrame_AddRefObject(ref _pNative);
  18. }
  19. ~BodyFrame()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Windows_Kinect_BodyFrame_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Windows_Kinect_BodyFrame_AddRefObject(ref RootSystem.IntPtr pNative);
  27. private void Dispose(bool disposing)
  28. {
  29. if (_pNative == RootSystem.IntPtr.Zero)
  30. {
  31. return;
  32. }
  33. __EventCleanup();
  34. Helper.NativeObjectCache.RemoveObject<BodyFrame>(_pNative);
  35. if (disposing)
  36. {
  37. Windows_Kinect_BodyFrame_Dispose(_pNative);
  38. }
  39. Windows_Kinect_BodyFrame_ReleaseObject(ref _pNative);
  40. _pNative = RootSystem.IntPtr.Zero;
  41. }
  42. // Public Properties
  43. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  44. private static extern int Windows_Kinect_BodyFrame_get_BodyCount(RootSystem.IntPtr pNative);
  45. public int BodyCount
  46. {
  47. get
  48. {
  49. if (_pNative == RootSystem.IntPtr.Zero)
  50. {
  51. throw new RootSystem.ObjectDisposedException("BodyFrame");
  52. }
  53. return Windows_Kinect_BodyFrame_get_BodyCount(_pNative);
  54. }
  55. }
  56. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  57. private static extern RootSystem.IntPtr Windows_Kinect_BodyFrame_get_BodyFrameSource(RootSystem.IntPtr pNative);
  58. public Windows.Kinect.BodyFrameSource BodyFrameSource
  59. {
  60. get
  61. {
  62. if (_pNative == RootSystem.IntPtr.Zero)
  63. {
  64. throw new RootSystem.ObjectDisposedException("BodyFrame");
  65. }
  66. RootSystem.IntPtr objectPointer = Windows_Kinect_BodyFrame_get_BodyFrameSource(_pNative);
  67. Helper.ExceptionHelper.CheckLastError();
  68. if (objectPointer == RootSystem.IntPtr.Zero)
  69. {
  70. return null;
  71. }
  72. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.BodyFrameSource>(objectPointer, n => new Windows.Kinect.BodyFrameSource(n));
  73. }
  74. }
  75. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  76. private static extern RootSystem.IntPtr Windows_Kinect_BodyFrame_get_FloorClipPlane(RootSystem.IntPtr pNative);
  77. public Windows.Kinect.Vector4 FloorClipPlane
  78. {
  79. get
  80. {
  81. if (_pNative == RootSystem.IntPtr.Zero)
  82. {
  83. throw new RootSystem.ObjectDisposedException("BodyFrame");
  84. }
  85. var objectPointer = Windows_Kinect_BodyFrame_get_FloorClipPlane(_pNative);
  86. Helper.ExceptionHelper.CheckLastError();
  87. var obj = (Windows.Kinect.Vector4)RootSystem.Runtime.InteropServices.Marshal.PtrToStructure(objectPointer, typeof(Windows.Kinect.Vector4));
  88. Windows.Kinect.KinectUnityAddinUtils.FreeMemory(objectPointer);
  89. return obj;
  90. }
  91. }
  92. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  93. private static extern long Windows_Kinect_BodyFrame_get_RelativeTime(RootSystem.IntPtr pNative);
  94. public RootSystem.TimeSpan RelativeTime
  95. {
  96. get
  97. {
  98. if (_pNative == RootSystem.IntPtr.Zero)
  99. {
  100. throw new RootSystem.ObjectDisposedException("BodyFrame");
  101. }
  102. return RootSystem.TimeSpan.FromMilliseconds(Windows_Kinect_BodyFrame_get_RelativeTime(_pNative));
  103. }
  104. }
  105. // Public Methods
  106. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  107. private static extern void Windows_Kinect_BodyFrame_Dispose(RootSystem.IntPtr pNative);
  108. public void Dispose()
  109. {
  110. if (_pNative == RootSystem.IntPtr.Zero)
  111. {
  112. return;
  113. }
  114. Dispose(true);
  115. RootSystem.GC.SuppressFinalize(this);
  116. }
  117. private void __EventCleanup()
  118. {
  119. }
  120. }
  121. }