From 829305a52249dee3c63ddd59a5691105b08c2f00 Mon Sep 17 00:00:00 2001 From: Glatzemann Date: Tue, 17 Jan 2012 05:55:36 +0000 Subject: [PATCH] fixed issue #530 (Kinect sample not working) --- .../MotionSensing/MotionSensingDevice.cs | 12 +++- .../MotionSensing/MotionSensingDeviceState.cs | 14 ++++- ANX.Framework/NonXNA/InputDeviceFactory.cs | 4 +- .../ANX.InputDevices.Windows.Kinect/Kinect.cs | 58 ++++++++++--------- .../WindowsGameHost.cs | 1 - Samples/Kinect/Kinect.csproj | 4 ++ 6 files changed, 60 insertions(+), 33 deletions(-) diff --git a/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs b/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs index 95875d72..cd4e15ab 100644 --- a/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs +++ b/ANX.Framework/Input/MotionSensing/MotionSensingDevice.cs @@ -69,11 +69,19 @@ namespace ANX.Framework.Input.MotionSensing { get { - return motionSensingDevice.GraphicsDevice; + if (motionSensingDevice != null) + { + return motionSensingDevice.GraphicsDevice; + } + + return null; } set { - motionSensingDevice.GraphicsDevice = value; + if (motionSensingDevice != null) + { + motionSensingDevice.GraphicsDevice = value; + } } } diff --git a/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs b/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs index 659c2792..2a7f0708 100644 --- a/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs +++ b/ANX.Framework/Input/MotionSensing/MotionSensingDeviceState.cs @@ -56,6 +56,8 @@ namespace ANX.Framework.Input.MotionSensing { public struct MotionSensingDeviceState { + private bool connected; + private Texture2D pRGB; private Texture2D pDepth; @@ -81,6 +83,13 @@ namespace ANX.Framework.Input.MotionSensing private Vector3 pFootRight; private Vector3 pCount; + public bool Connected + { + get + { + return this.connected; + } + } public Texture2D RGB { get { return this.pRGB; } } public Texture2D Depth { get { return this.pDepth; } } @@ -107,10 +116,11 @@ namespace ANX.Framework.Input.MotionSensing public Vector3 FootRight { get { return this.pFootRight; } } public Vector3 Count { get { return this.pCount; } } - - public MotionSensingDeviceState(Texture2D _RGB, Texture2D _Depth, Vector3 _HipCenter, Vector3 _Spine, Vector3 _ShoulderCenter, Vector3 _Head, Vector3 _ShoulderLeft, + public MotionSensingDeviceState(bool connected, Texture2D _RGB, Texture2D _Depth, Vector3 _HipCenter, Vector3 _Spine, Vector3 _ShoulderCenter, Vector3 _Head, Vector3 _ShoulderLeft, Vector3 _ElbowLeft, Vector3 _WristLeft, Vector3 _HandLeft, Vector3 _ShoulderRight, Vector3 _ElbowRight, Vector3 _WristRight, Vector3 _HandRight, Vector3 _HipLeft, Vector3 _KneeLeft, Vector3 _AnkleLeft, Vector3 _FootLeft, Vector3 _HipRight, Vector3 _KneeRight, Vector3 _AnkleRight, Vector3 _FootRight, Vector3 _Count) { + this.connected = connected; + pRGB = _RGB; pDepth = _Depth; diff --git a/ANX.Framework/NonXNA/InputDeviceFactory.cs b/ANX.Framework/NonXNA/InputDeviceFactory.cs index 110a4467..1f564409 100644 --- a/ANX.Framework/NonXNA/InputDeviceFactory.cs +++ b/ANX.Framework/NonXNA/InputDeviceFactory.cs @@ -9,6 +9,7 @@ using NLog; using System.Collections; using System.Resources; using ANX.Framework.NonXNA.InputSystem; +using ANX.Framework.Graphics; #endregion // Using Statements @@ -223,7 +224,8 @@ namespace ANX.Framework.NonXNA if (this.motionSensingDeviceCreators.Count > 0) { - return this.motionSensingDeviceCreators.Values.First().CreateMotionSensingDeviceInstance(); + IMotionSensingDevice motionSensingDevice = this.motionSensingDeviceCreators.Values.First().CreateMotionSensingDeviceInstance(); + return motionSensingDevice; } throw new Exception("Unable to create instance of MotionSensingDevice because no MotionSensingDeviceCreator was registered."); diff --git a/InputSystems/ANX.InputDevices.Windows.Kinect/Kinect.cs b/InputSystems/ANX.InputDevices.Windows.Kinect/Kinect.cs index e58dc6f9..bc9c5fff 100644 --- a/InputSystems/ANX.InputDevices.Windows.Kinect/Kinect.cs +++ b/InputSystems/ANX.InputDevices.Windows.Kinect/Kinect.cs @@ -80,10 +80,10 @@ namespace ANX.InputDevices.Windows.Kinect pNui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking | RuntimeOptions.UseColor); pNui.SkeletonEngine.TransformSmooth = true; } - else - { - throw new Exception("No Kinect was detected, please connect it to your Computer before running this program and make sure you install the Kinect SDK from Microsoft."); - } + //else + //{ + // throw new Exception("No Kinect was detected, please connect it to your Computer before running this program and make sure you install the Kinect SDK from Microsoft."); + //} this.cache = new Vector3[21]; @@ -92,6 +92,7 @@ namespace ANX.InputDevices.Windows.Kinect { this.cache[i] = Vector3.Zero; } + //Added parameters which where used in our Kinect project var parameters = new TransformSmoothParameters { @@ -102,30 +103,33 @@ namespace ANX.InputDevices.Windows.Kinect MaxDeviationRadius = 0.9f }; - pNui.SkeletonEngine.SmoothParameters = parameters; - - try + if (pNui != null) { - pNui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); - pNui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex); + pNui.SkeletonEngine.SmoothParameters = parameters; + + try + { + pNui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color); + pNui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex); + } + catch (InvalidOperationException) + { + // Display error message; omitted for space return; + } + //lastTime = DateTime.Now; + + pNui.SkeletonFrameReady += new EventHandler(pNui_SkeletonFrameReady); + pNui.DepthFrameReady += new EventHandler(pNui_DepthFrameReady); + pNui.VideoFrameReady += new EventHandler(pNui_VideoFrameReady); + + // move down all the way + pNui.NuiCamera.ElevationAngle = -15; + + System.Threading.Thread.Sleep(1500); + + // move up all the way + pNui.NuiCamera.ElevationAngle = 20; } - catch (InvalidOperationException) - { - // Display error message; omitted for space return; - } - //lastTime = DateTime.Now; - - pNui.SkeletonFrameReady += new EventHandler(pNui_SkeletonFrameReady); - pNui.DepthFrameReady += new EventHandler(pNui_DepthFrameReady); - pNui.VideoFrameReady += new EventHandler(pNui_VideoFrameReady); - - // move down all the way - pNui.NuiCamera.ElevationAngle = -15; - - System.Threading.Thread.Sleep(1500); - - // move up all the way - pNui.NuiCamera.ElevationAngle = 20; } void pNui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e) @@ -184,7 +188,7 @@ namespace ANX.InputDevices.Windows.Kinect public MotionSensingDeviceState GetState() { - return new MotionSensingDeviceState(rgb, depth, cache[0], cache[1], cache[2], cache[3], cache[4], cache[5], cache[6], cache[7], cache[8], cache[9], cache[10], cache[11], cache[12], cache[13], cache[14], cache[15], cache[16], cache[17], cache[18], cache[19], cache[20]); + return new MotionSensingDeviceState(Runtime.Kinects.Count > 0, rgb, depth, cache[0], cache[1], cache[2], cache[3], cache[4], cache[5], cache[6], cache[7], cache[8], cache[9], cache[10], cache[11], cache[12], cache[13], cache[14], cache[15], cache[16], cache[17], cache[18], cache[19], cache[20]); } diff --git a/RenderSystems/ANX.Framework.Windows.DX10/WindowsGameHost.cs b/RenderSystems/ANX.Framework.Windows.DX10/WindowsGameHost.cs index 4b32499a..e4e25420 100644 --- a/RenderSystems/ANX.Framework.Windows.DX10/WindowsGameHost.cs +++ b/RenderSystems/ANX.Framework.Windows.DX10/WindowsGameHost.cs @@ -72,7 +72,6 @@ namespace ANX.Framework //this.LockThreadToProcessor(); this.gameWindow = new WindowsGameWindow(); InputDeviceFactory.Instance.WindowHandle = this.gameWindow.Handle; - //TouchPanel.WindowHandle = this.gameWindow.Handle; //this.gameWindow.IsMouseVisible = game.IsMouseVisible; this.gameWindow.Activated += new EventHandler(this.GameWindowActivated); this.gameWindow.Deactivated += new EventHandler(this.GameWindowDeactivated); diff --git a/Samples/Kinect/Kinect.csproj b/Samples/Kinect/Kinect.csproj index 9c2c929e..7f0bba13 100644 --- a/Samples/Kinect/Kinect.csproj +++ b/Samples/Kinect/Kinect.csproj @@ -114,6 +114,10 @@ {E5D69E75-D77C-493F-BBDA-6F9E73B82549} ANX.InputDevices.Windows.Kinect + + {60D08399-244F-46A3-91F1-4CFD26D961A3} + ANX.InputDevices.Windows.XInput + {49066074-3B7B-4A55-B122-6BD33AB73558} ANX.InputSystem.Standard