fixed issue #530 (Kinect sample not working)

This commit is contained in:
Glatzemann 2012-01-17 05:55:36 +00:00
parent aaa894f9fb
commit 829305a522
6 changed files with 60 additions and 33 deletions

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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<IMotionSensingDeviceCreator>().CreateMotionSensingDeviceInstance();
IMotionSensingDevice motionSensingDevice = this.motionSensingDeviceCreators.Values.First<IMotionSensingDeviceCreator>().CreateMotionSensingDeviceInstance();
return motionSensingDevice;
}
throw new Exception("Unable to create instance of MotionSensingDevice because no MotionSensingDeviceCreator was registered.");

View File

@ -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<SkeletonFrameReadyEventArgs>(pNui_SkeletonFrameReady);
pNui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(pNui_DepthFrameReady);
pNui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(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<SkeletonFrameReadyEventArgs>(pNui_SkeletonFrameReady);
pNui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(pNui_DepthFrameReady);
pNui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(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]);
}

View File

@ -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<EventArgs>(this.GameWindowActivated);
this.gameWindow.Deactivated += new EventHandler<EventArgs>(this.GameWindowDeactivated);

View File

@ -114,6 +114,10 @@
<Project>{E5D69E75-D77C-493F-BBDA-6F9E73B82549}</Project>
<Name>ANX.InputDevices.Windows.Kinect</Name>
</ProjectReference>
<ProjectReference Include="..\..\InputSystems\ANX.InputDevices.Windows.XInput\ANX.InputDevices.Windows.XInput.csproj">
<Project>{60D08399-244F-46A3-91F1-4CFD26D961A3}</Project>
<Name>ANX.InputDevices.Windows.XInput</Name>
</ProjectReference>
<ProjectReference Include="..\..\InputSystems\ANX.InputSystem.Standard\ANX.InputSystem.Standard.csproj">
<Project>{49066074-3B7B-4A55-B122-6BD33AB73558}</Project>
<Name>ANX.InputSystem.Standard</Name>