/// <summary> /// Gets the depths in mm at the given pixel on screen, or -1 if invalid. /// </summary> /// <param name="x">The x coordinate on screen</param> /// <param name="y">The y coordinate on screen</param> /// <param name="screenSize">The size of the screen</param> /// <returns>The depth, in mm</returns> public static int GetDepthAtPixel(int x, int y, Size screenSize) { checkStarted(); if (depthData == null) return -1; int dx = x * depthFrameWidth / screenSize.Width; int dy = y * depthFrameHeight / screenSize.Height; int index = dy * depthFrameWidth + dx; if (index >= 0 && index < depthData.Length) { return depthData[index] >> DepthImageFrame.PlayerIndexBitmaskWidth; } return -1; }
protected override void Initialize() { base.Initialize(); resolution = GetResolution(); graphics.PreferredBackBufferWidth = resolution.Width; graphics.PreferredBackBufferHeight = resolution.Height; graphics.ApplyChanges(); KinectManager.Start(); StartGame(GetKinnectGame()); }
public GameParameters(Size resolution, GraphicsDeviceManager graphics, GameWindow window) { this.Resolution = resolution; this.Graphics = graphics; this.Window = window; }
/// <summary> /// Creates a KinectGame. This constructor should not /// be overridden. /// </summary> /// <param name="gParams">The GameParameters describing the environment in which the game is running.</param> public KinectGame(GameParameters gParams) { resolution = gParams.Resolution; graphics = gParams.Graphics; window = gParams.Window; }
/// <summary> /// Returns the depth in mm at the given SkeletonPoint, or -1 if the point is invalid. /// </summary> /// <param name="point">The point to check</param> /// <returns>The depth, in mm</returns> public static int GetDepthAtPoint(SkeletonPoint point) { Size depthSize = new Size(depthFrameWidth, depthFrameHeight); Microsoft.Xna.Framework.Vector2 pos = GetSkeletonPointPosOnScreen(point, depthSize); int x = (int)pos.X, y = (int)pos.Y; return GetDepthAtPixel(x, y, depthSize); }
private static void onKinectVideoFrameReady(object sender, ColorImageFrameReadyEventArgs e) { //Debug.WriteLine(DateTime.Now.ToString()); // Open image ColorImageFrame colorVideoFrame = e.OpenColorImageFrame(); if (colorVideoFrame != null) { //Create array for pixel data and copy it from the image frame Byte[] pixelData = new Byte[colorVideoFrame.PixelDataLength]; colorVideoFrame.CopyPixelDataTo(pixelData); //Convert RGBA to BGRA Byte[] bgraPixelData = new Byte[colorVideoFrame.PixelDataLength]; for (int i = 0; i < pixelData.Length; i += 4) { bgraPixelData[i] = pixelData[i + 2]; bgraPixelData[i + 1] = pixelData[i + 1]; bgraPixelData[i + 2] = pixelData[i]; bgraPixelData[i + 3] = (Byte)255; //The video comes with 0 alpha so it is transparent } colorFrameSize = new Size(colorVideoFrame.Width, colorVideoFrame.Height); colorFrameData = bgraPixelData; if (colorFrameTexture != null) colorFrameTexture.Dispose(); colorFrameTexture = null; colorVideoFrame.Dispose(); } }
/// <summary> /// Gets the position of a SkeletonPoint on the screen. /// </summary> /// <param name="point">The point</param> /// <param name="screenSize">The size of the screen.</param> /// <returns>The position on the screen of the point</returns> public static Microsoft.Xna.Framework.Vector2 GetSkeletonPointPosOnScreen(SkeletonPoint point, Size screenSize) { checkStarted(); Kinect.Toolbox.Vector2 v = Tools.Convert(kinect, point); return new Microsoft.Xna.Framework.Vector2(v.X * screenSize.Width, v.Y * screenSize.Height); }
/// <summary> /// Gets the position of a Skeleton's Joint on the screen. /// </summary> /// <param name="joint">The joint</param> /// <param name="screenSize">The size of the screen.</param> /// <returns>The position on the screen of the Joint</returns> public static Microsoft.Xna.Framework.Vector2 GetJointPosOnScreen(Joint joint, Size screenSize) { return GetSkeletonPointPosOnScreen(joint.Position, screenSize); }