Advertisement
Guest User

Untitled

a guest
Aug 4th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Kinect;
  12. using LineBatch;
  13. namespace WindowsGame4
  14. {
  15. /// <summary>
  16. /// This is the main type for your game
  17. /// </summary>
  18. public class Game1 : Microsoft.Xna.Framework.Game
  19. {
  20. GraphicsDeviceManager graphics;
  21. SpriteBatch spriteBatch;
  22. KinectSensor myKinect;
  23. int[] skeletonArray = new int[40];
  24.  
  25.  
  26. public Game1()
  27. {
  28. graphics = new GraphicsDeviceManager(this);
  29. Content.RootDirectory = "Content";
  30. }
  31.  
  32. protected override void Initialize()
  33. {
  34. // TODO: Add your initialization logic here
  35. SpriteBatchEx.GraphicsDevice = GraphicsDevice;
  36. base.Initialize();
  37. }
  38. protected override void LoadContent()
  39. {
  40. // Create a new SpriteBatch, which can be used to draw textures.
  41. spriteBatch = new SpriteBatch(GraphicsDevice);
  42. myKinect = KinectSensor.KinectSensors[0];
  43. myKinect.SkeletonStream.Enable();
  44. myKinect.Start();
  45.  
  46. // TODO: use this.Content to load your game content here
  47. }
  48.  
  49. protected override void UnloadContent()
  50. {
  51. // TODO: Unload any non ContentManager content here
  52. }
  53.  
  54. protected override void Update(GameTime gameTime)
  55. {
  56. Skeleton[] skeletons;
  57. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  58. this.Exit();
  59.  
  60.  
  61. using (SkeletonFrame frameData = myKinect.SkeletonStream.OpenNextFrame(1))
  62. {
  63. // if frame is null , then exit
  64. if (frameData == null)
  65. {
  66. //System.Console.WriteLine("no data");
  67. return;
  68. }
  69. skeletons = new Skeleton[frameData.SkeletonArrayLength];
  70. frameData.CopySkeletonDataTo(skeletons);
  71. foreach (Skeleton skeleton in skeletons)
  72. {
  73. if (skeleton.TrackingState != SkeletonTrackingState.NotTracked)
  74. {
  75. for(int i = 0 ; i < 20 ; i++)
  76. {
  77. ColorImagePoint point1 = myKinect.MapSkeletonPointToColor(skeleton.Joints[(JointType)i].Position, ColorImageFormat.RgbResolution640x480Fps30);
  78. skeletonArray[i * 2] = point1.X;
  79. skeletonArray[i * 2 + 1] = point1.Y;
  80. }
  81. ColorImagePoint point2 = myKinect.MapSkeletonPointToColor(skeleton.Joints[(JointType)2].Position, ColorImageFormat.RgbResolution640x480Fps30);
  82. }
  83. }
  84. }
  85.  
  86. base.Update(gameTime);
  87. }
  88.  
  89. protected override void Draw(GameTime gameTime)
  90. {
  91. GraphicsDevice.Clear(Color.CornflowerBlue);
  92. // draw head to neck
  93. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[6], skeletonArray[7]), new Vector2(skeletonArray[4], skeletonArray[5]), Color.DarkRed, 4);
  94. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[4], skeletonArray[5]), new Vector2(skeletonArray[2], skeletonArray[3]), Color.DarkRed, 4);
  95. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[2], skeletonArray[3]), new Vector2(skeletonArray[0], skeletonArray[1]), Color.DarkRed, 4);
  96. // draw nack to left arm
  97. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[4], skeletonArray[5]), new Vector2(skeletonArray[8], skeletonArray[9]), Color.DarkRed, 4);
  98. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[8], skeletonArray[9]), new Vector2(skeletonArray[10], skeletonArray[11]), Color.DarkRed, 4);
  99. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[10], skeletonArray[11]), new Vector2(skeletonArray[12], skeletonArray[13]), Color.DarkRed, 4);
  100. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[12], skeletonArray[13]), new Vector2(skeletonArray[14], skeletonArray[15]), Color.DarkRed, 4);
  101. // draw nack to right arm
  102. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[4], skeletonArray[5]), new Vector2(skeletonArray[16], skeletonArray[17]), Color.DarkRed, 4);
  103. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[16], skeletonArray[17]), new Vector2(skeletonArray[18], skeletonArray[19]), Color.DarkRed, 4);
  104. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[18], skeletonArray[19]), new Vector2(skeletonArray[20], skeletonArray[21]), Color.DarkRed, 4);
  105. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[20], skeletonArray[21]), new Vector2(skeletonArray[22], skeletonArray[23]), Color.DarkRed, 4);
  106. // draw center to left leg
  107. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[0], skeletonArray[1]), new Vector2(skeletonArray[24], skeletonArray[25]), Color.DarkRed, 4);
  108. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[24], skeletonArray[25]), new Vector2(skeletonArray[26], skeletonArray[27]), Color.DarkRed, 4);
  109. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[26], skeletonArray[27]), new Vector2(skeletonArray[28], skeletonArray[29]), Color.DarkRed, 4);
  110. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[28], skeletonArray[29]), new Vector2(skeletonArray[30], skeletonArray[31]), Color.DarkRed, 4);
  111. // draw center to right leg
  112. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[0], skeletonArray[1]), new Vector2(skeletonArray[32], skeletonArray[33]), Color.DarkRed, 4);
  113. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[32], skeletonArray[33]), new Vector2(skeletonArray[34], skeletonArray[35]), Color.DarkRed, 4);
  114. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[34], skeletonArray[35]), new Vector2(skeletonArray[36], skeletonArray[37]), Color.DarkRed, 4);
  115. spriteBatch.DrawSingleLine(new Vector2(skeletonArray[36], skeletonArray[37]), new Vector2(skeletonArray[38], skeletonArray[39]), Color.DarkRed, 4);
  116. base.Draw(gameTime);
  117. }
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement