Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Kinect;
- using LineBatch;
- namespace WindowsGame4
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class Game1 : Microsoft.Xna.Framework.Game
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- KinectSensor myKinect;
- int[] skeletonArray = new int[40];
- public Game1()
- {
- graphics = new GraphicsDeviceManager(this);
- Content.RootDirectory = "Content";
- }
- protected override void Initialize()
- {
- // TODO: Add your initialization logic here
- SpriteBatchEx.GraphicsDevice = GraphicsDevice;
- base.Initialize();
- }
- protected override void LoadContent()
- {
- // Create a new SpriteBatch, which can be used to draw textures.
- spriteBatch = new SpriteBatch(GraphicsDevice);
- myKinect = KinectSensor.KinectSensors[0];
- myKinect.SkeletonStream.Enable();
- myKinect.Start();
- // TODO: use this.Content to load your game content here
- }
- protected override void UnloadContent()
- {
- // TODO: Unload any non ContentManager content here
- }
- protected override void Update(GameTime gameTime)
- {
- Skeleton[] skeletons;
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- using (SkeletonFrame frameData = myKinect.SkeletonStream.OpenNextFrame(1))
- {
- // if frame is null , then exit
- if (frameData == null)
- {
- //System.Console.WriteLine("no data");
- return;
- }
- skeletons = new Skeleton[frameData.SkeletonArrayLength];
- frameData.CopySkeletonDataTo(skeletons);
- foreach (Skeleton skeleton in skeletons)
- {
- if (skeleton.TrackingState != SkeletonTrackingState.NotTracked)
- {
- for(int i = 0 ; i < 20 ; i++)
- {
- ColorImagePoint point1 = myKinect.MapSkeletonPointToColor(skeleton.Joints[(JointType)i].Position, ColorImageFormat.RgbResolution640x480Fps30);
- skeletonArray[i * 2] = point1.X;
- skeletonArray[i * 2 + 1] = point1.Y;
- }
- ColorImagePoint point2 = myKinect.MapSkeletonPointToColor(skeleton.Joints[(JointType)2].Position, ColorImageFormat.RgbResolution640x480Fps30);
- }
- }
- }
- base.Update(gameTime);
- }
- protected override void Draw(GameTime gameTime)
- {
- GraphicsDevice.Clear(Color.CornflowerBlue);
- // draw head to neck
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[6], skeletonArray[7]), new Vector2(skeletonArray[4], skeletonArray[5]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[4], skeletonArray[5]), new Vector2(skeletonArray[2], skeletonArray[3]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[2], skeletonArray[3]), new Vector2(skeletonArray[0], skeletonArray[1]), Color.DarkRed, 4);
- // draw nack to left arm
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[4], skeletonArray[5]), new Vector2(skeletonArray[8], skeletonArray[9]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[8], skeletonArray[9]), new Vector2(skeletonArray[10], skeletonArray[11]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[10], skeletonArray[11]), new Vector2(skeletonArray[12], skeletonArray[13]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[12], skeletonArray[13]), new Vector2(skeletonArray[14], skeletonArray[15]), Color.DarkRed, 4);
- // draw nack to right arm
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[4], skeletonArray[5]), new Vector2(skeletonArray[16], skeletonArray[17]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[16], skeletonArray[17]), new Vector2(skeletonArray[18], skeletonArray[19]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[18], skeletonArray[19]), new Vector2(skeletonArray[20], skeletonArray[21]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[20], skeletonArray[21]), new Vector2(skeletonArray[22], skeletonArray[23]), Color.DarkRed, 4);
- // draw center to left leg
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[0], skeletonArray[1]), new Vector2(skeletonArray[24], skeletonArray[25]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[24], skeletonArray[25]), new Vector2(skeletonArray[26], skeletonArray[27]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[26], skeletonArray[27]), new Vector2(skeletonArray[28], skeletonArray[29]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[28], skeletonArray[29]), new Vector2(skeletonArray[30], skeletonArray[31]), Color.DarkRed, 4);
- // draw center to right leg
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[0], skeletonArray[1]), new Vector2(skeletonArray[32], skeletonArray[33]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[32], skeletonArray[33]), new Vector2(skeletonArray[34], skeletonArray[35]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[34], skeletonArray[35]), new Vector2(skeletonArray[36], skeletonArray[37]), Color.DarkRed, 4);
- spriteBatch.DrawSingleLine(new Vector2(skeletonArray[36], skeletonArray[37]), new Vector2(skeletonArray[38], skeletonArray[39]), Color.DarkRed, 4);
- base.Draw(gameTime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement