public SpaceGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); pushAlienTimer = 0; killCount = 0; stars = new Star[100]; for (int i = 0; i < 100; i++) { stars[i] = new Star(Game1.GameRandom.Next() % 3000); } ein = Game1.ein; aliens = new List<Alien>(); bullets = new List<PlayerBullet>(); particles = new List<Particle>(); for (int i = 0; i < 4; i++) { aliens.Add(new Alien(this)); } }
public PaddleMiniGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); tutorialTimer = 0; ein = Game1.ein; circleTexture = CreateCircle(8, graphicsDevice); gameState = MiniGameState.Initialized; physicsWorld = new World(new Vector2(0, 0.8f)); paddle = BodyFactory.CreateRectangle(physicsWorld, paddle_width * pixelToUnit, paddle_height * pixelToUnit, 1000f); paddle.BodyType = BodyType.Static; paddle.Position = new Vector2(320 * pixelToUnit, 240 * pixelToUnit); paddle_size = new Vector2(paddle_width * pixelToUnit, paddle_height * pixelToUnit); ball = BodyFactory.CreateCircle(physicsWorld, ball_radius * pixelToUnit, 1000f); ball.BodyType = BodyType.Dynamic; ball.Position = new Vector2(320 * pixelToUnit, 100 * pixelToUnit); ball.SleepingAllowed = false; }
public PinballMiniGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); ein = new Kinect(0, 0); ein.Init(); circleTexture = CreateCircle(ball_radius, graphicsDevice); gameState = MiniGameState.Initialized; physicsWorld = new World(new Vector2(0, .982f)); paddleSize = new Vector2(300, 16); paddleLeft = BodyFactory.CreateRectangle(physicsWorld, paddleSize.X * 2 * pixelToUnit, paddleSize.Y * pixelToUnit, 1000f); paddleLeft.BodyType = BodyType.Dynamic; paddleLeft.Position = new Vector2(8 * pixelToUnit, (GameConstants.MiniGameCanvasHeight - 100) * pixelToUnit); paddleLeft.LocalCenter = new Vector2(0, 0); paddleLeft.SleepingAllowed = false; paddleLeft.Restitution = 1.0f; paddleLeft.IgnoreGravity = true; ball = BodyFactory.CreateCircle(physicsWorld, (ball_radius) * pixelToUnit, 1000f); ball.BodyType = BodyType.Dynamic; ball.Position = new Vector2(100 * pixelToUnit, 100 * pixelToUnit); ball.Restitution = 1.0f; ball.SleepingAllowed = false; }
/// <summary> /// Creates a new instance of ScreenManager. /// </summary> public ScreenManager(Microsoft.Xna.Framework.Game game, Kinect kinect) : base(game) { this.Kinect = kinect; base.Initialize(); }
private void btnSelectCamera_Click(object sender, EventArgs e) { VideoCaptureDeviceForm form = new VideoCaptureDeviceForm(); if (form.ShowDialog() == DialogResult.OK) { int deviceId = form.DeviceId; kinectDevice = Kinect.GetDevice(deviceId); if (videoCamera == null) { videoCamera = kinectDevice.GetVideoCamera(); videoCamera.CameraMode = VideoCameraMode.Color; controller.Device = videoCamera; controller.Start(); controller.NewFrame += new AForge.Video.NewFrameEventHandler(controller_NewFrame); } if (depthCamera == null) { //depthCamera = kinectDevice.GetDepthCamera(); depthCamera = new KinectDepthCamera(deviceId, CameraResolution.Medium, true); videoSourcePlayer1.VideoSource = depthCamera; videoSourcePlayer1.Start(); } toolStripStatusLabel1.Text = "Initializing..."; } }
// Update is called once per frame void Update() { // Update status of accelerometer/motor etc. kinect.UpdateStatus(); // Process any pending events. Kinect.ProcessEvents(); }
public SpaceGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); pushAlienTimer = 0; killCount = 0; stars = new Star[100]; for (int i = 0; i < 100; i++) { stars[i] = new Star(Game1.GameRandom.Next() % 3000); } ein = Game1.ein; aliens = new List <Alien>(); bullets = new List <PlayerBullet>(); particles = new List <Particle>(); for (int i = 0; i < 4; i++) { aliens.Add(new Alien(this)); } }
private void Disconnect() { // Stop the update thread this.updateStatusThread.Abort(); while (this.updateStatusThread.IsAlive) { // wait... Application.DoEvents(); Thread.Sleep(1000); Console.WriteLine("waiting for disconnect..."); } this.updateStatusThread = null; // Disable update timer first this.infoUpdateTimer.Enabled = false; // Disconnect from the device this.kinect.Close(); this.kinect = null; // Disable controls again this.bottomPanel.Enabled = false; // Enable connect this.connectButton.Enabled = true; this.disconnectButton.Enabled = false; }
public PlatformerGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; ein = Game1.ein; height = 50; width = 50; density = .5f; posx = 350; posy = 0; enemy_height = 20; enemy_width = 20; enemy_density = 1f; enemy_posx = GameConstants.MiniGameCanvasWidth - 50; enemy_posy = 150; floor_height = 20; floor_width = GameConstants.MiniGameCanvasWidth; floor_density = .5f; floor_posx = GameConstants.MiniGameCanvasWidth / 2; floor_posy = (GameConstants.MiniGameCanvasHeight - 50); fixpt_height = 1; fixpt_width = 1; fixpt_density = 1f; sb = new SpriteBatch(graphicsDevice); backgroundColor = new Color((float)Game1.GameRandom.NextDouble(), (float)Game1.GameRandom.NextDouble(), (float)Game1.GameRandom.NextDouble(), 1); gravity = 9.8f; world = new World(new Vector2(0, gravity)); body = BodyFactory.CreateRectangle(world, width * pixelToUnit, height * pixelToUnit, density); body.BodyType = BodyType.Dynamic; body.SleepingAllowed = false; size = new Vector2(width, height); Size = size; body.Position = new Vector2(posx * pixelToUnit, posy * pixelToUnit); enemy_body = BodyFactory.CreateRectangle(world, enemy_width * pixelToUnit, enemy_height * pixelToUnit, enemy_density); enemy_body.BodyType = BodyType.Dynamic; enemy_size = new Vector2(enemy_width, enemy_height); enemy_Size = enemy_size; enemy_body.Position = new Vector2(enemy_posx * pixelToUnit, enemy_posy * pixelToUnit); floor_body = BodyFactory.CreateRectangle(world, floor_width * pixelToUnit, floor_height * pixelToUnit, floor_density); floor_body.BodyType = BodyType.Static; floor_size = new Vector2(floor_width, floor_height); floor_Size = floor_size; floor_body.Position = new Vector2(floor_posx * pixelToUnit, floor_posy * pixelToUnit); //playerRod = JointFactory.CreateWeldJoint(world, rod_body, floor_body, Vector2.Zero, new Vector2(0, rod_height/2 * pixelToUnit)); //FarseerPhysics.Factories.JointFactory.CreateRevoluteJoint(world, rod_body, floor_body, new Vector2(0, rod_height / 2 * pixelToUnit)); gameState = MiniGameState.Initialized; }
public override void Update(Kinect.SkeletonInfo info) { //Vector3 newRight = info.LocationToGestureSpace(info.rightWrist); //Vector3 newLeft = info.LocationToGestureSpace(info.leftWrist); if (wasUncontrolled) { rightVel = Vector3.Zero; leftVel = Vector3.Zero; } else { rightVel = info.rightWristVel; leftVel = info.leftWristVel; } rightWrist = info.LocationToGestureSpace(info.rightWrist); leftWrist = info.LocationToGestureSpace(info.leftWrist); if (!ragdoll.asleep && ragdoll.Possessed) { wasUncontrolled = false; } }
public static void Init(Kinect kinect) { if (Kinect.DeviceCount > 0) { // Connect to first device kinect.Open(); // Setup event handlers kinect.VideoCamera.DataReceived += HandleKinectVideoCameraDataReceived; kinect.DepthCamera.DataReceived += HandleKinectDepthCameraDataReceived; // Start cameras kinect.VideoCamera.Start(); kinect.DepthCamera.Start(); // Set LED to Yellow kinect.LED.Color = LEDColor.Yellow; /* * // Start update thread * Thread t = new Thread(new ThreadStart(delegate () * { * while (true) * { * // Update status of accelerometer/motor etc. * kinect.UpdateStatus(); * * // Process any pending events. * Kinect.ProcessEvents(); * } * }));*/ } }
public HeadBallGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); ein = Game1.ein; circleTexture = CreateCircle(8, graphicsDevice); gameState = MiniGameState.Initialized; physicsWorld = new World(new Vector2(0, 0.8f)); paddle = BodyFactory.CreateRectangle(physicsWorld, paddle_width * pixelToUnit, paddle_height * pixelToUnit, 1000f); paddle.BodyType = BodyType.Static; paddle.Position = new Vector2(320 * pixelToUnit, 240 * pixelToUnit); paddle_size = new Vector2(paddle_width * pixelToUnit, paddle_height * pixelToUnit); paddle.Rotation = 0; ball = BodyFactory.CreateCircle(physicsWorld, ball_radius * pixelToUnit, 1000f); ball.BodyType = BodyType.Dynamic; ball.Position = new Vector2(320 * pixelToUnit, 100 * pixelToUnit); ball.SleepingAllowed = false; }
/// <summary> /// Constructor for the standby window /// </summary> /// <param name="_sensor">An open kinect sensor, or null</param> public StandbyWindow(String[] names) { InitializeComponent(); Kinect kinect = Kinect.getInstance(); // Initialize load text standbyMsg.Text = (kinect.isAvailable()) ? gbtis.Properties.Resources.msgStart : gbtis.Properties.Resources.msgNoSensor; kinect.BitMapReady += BitMapArrived; kinect.SensorStatusChanged += OnSensorStatusChanged; // Initialize the names topName.Text = ""; centerName.Text = ""; bottomName.Text = ""; if (names.Length == 0) { this.names = DEFAULT_NAMES; } else { this.names = names; } // Start the timer for the name animation Timer timer = new Timer(nameFadeInterval); timer.Elapsed += HandleTimer; timer.Start(); HandleTimer(null, null); }
public override void Update(Kinect.SkeletonInfo info) { base.Update(info); if (!thrustOn && !ragdoll.asleep && ticksAfterThrust >= 0) { if (ticksAfterThrust < 20) { Vector2 bodyVel = ragdoll.Body.LinearVelocity; stoppingThrustVector = -.6f * bodyVel; ApplyStoppingForce(); ticksAfterThrust++; } else { stoppingThrustVector = Vector2.Zero; ticksAfterThrust = -1; } } }
public void RunRealKinect() { int index = 0; while (Kinect == null && index < KinectSensor.KinectSensors.Count) { try { Kinect = KinectSensor.KinectSensors[index]; Kinect.Start(); } catch (Exception e) { Kinect = null; } index++; } if (Kinect != null) { Kinect.SkeletonStream.Enable(new TransformSmoothParameters { Smoothing = 0.5f, Correction = 0.5f, Prediction = 0.5f, JitterRadius = 0.05f, MaxDeviationRadius = 0.04f }); Kinect.SkeletonFrameReady += TKinect.SensorSkeletonFrameHandler; return; } Console.WriteLine("NO REAL KINECT DETECTED"); }
private void PublishGetSensorStatus(KinectSensor newSensor, ChooserStatus newStatus) { if (Kinect != newSensor) { if (Kinect != null) { Kinect.Stop(); Kinect.AudioSource.Stop(); } Kinect = newSensor; if (this.PropertyCallback != null) { PropertyCallback(new KeyValuePair() { key = "Kinect", value = Kinect }); } if (this.SensorCallback != null) { SensorCallback(new KinectSensorChangedEventData() { sensor = Kinect, status = newStatus }); } } if (Status != newStatus) { if (this.PropertyCallback != null) { PropertyCallback(new KeyValuePair() { key = "Status", value = newStatus }); } } }
/// <summary> /// Disconnects from teh currently connected Kinect device /// </summary> private void Disconnect() { // Are we running? if (this.isRunning == false) { return; } // Stop updating status this.statusUpdateTimer.Enabled = false; // No longer running this.isRunning = false; // Wait till update thread closes down this.updateThread.Interrupt(); this.updateThread.Join(); this.updateThread = null; // Disconnect from the kinect this.kinect.Close(); this.kinect = null; // Disable video/depth mode chooser this.selectVideoModeGroup.Enabled = false; // Disable disconnect button and enable the connect/refresh ones this.disconnectButton.Visible = false; this.connectButton.Visible = true; this.refreshButton.Visible = true; this.selectDeviceCombo.Enabled = true; // Disable content areas this.contentPanel.Enabled = false; }
public MoveableBodyPart(Kinect kinect, SkeletonSelector bodyPart) : base(kinect) { this._bodyPart = bodyPart; this.SetupInfo(); this.SetupEvents(); }
public ColorGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); ein = Game1.ein; resetDisplay(); }
/// <summary> /// Initializes a new instance of the <see cref="KinectTest"/> class. /// </summary> public KinectTest() { kinectSensor = Isolate.Fake.Instance <KinectSensor>(); Isolate.WhenCalled(() => kinectSensor.Open()).DoInstead(x => isOpen = true); Isolate.WhenCalled(() => kinectSensor.Close()).DoInstead(x => isOpen = false); kinect = Kinect.Instance; Isolate.NonPublic.InstanceField(kinect, "kinect").Value = kinectSensor; }
public void StartTracking() { var buffer = new KinectDataBuffer(); ProgramState.StartedTracking(); ProcessingCommandsQueue.Add(new StartTrackingMessage(buffer)); Kinect = new Kinect(ProcessingCommandsQueue, buffer, this); }
public void Initialize(string Path, Kinect kinect, Vector2 Position) { texturePath = Path; this.kinect = kinect; position = Position; textureBoundsSet = false; hoverColor = new Color(255, 255, 255, 220); }
// Connect to Kinect cameras private bool Connect() { bool ret = false; Cursor = Cursors.WaitCursor; if (Kinect.DeviceCount != 0) { int deviceID = devicesCombo.SelectedIndex; try { kinectDevice = Kinect.GetDevice(deviceID); if (videoCamera == null) { videoCamera = kinectDevice.GetVideoCamera(); videoCamera.CameraMode = (videoModeCombo.SelectedIndex == 0) ? VideoCameraMode.Color : ((videoModeCombo.SelectedIndex == 1) ? VideoCameraMode.Bayer : VideoCameraMode.InfraRed); videoCameraPlayer.VideoSource = videoCamera; videoCameraPlayer.Start(); } if (depthCamera == null) { depthCamera = kinectDevice.GetDepthCamera(); depthCameraPlayer.VideoSource = depthCamera; depthCameraPlayer.Start(); } ledColorCombo.SelectedIndex = 0; if (tiltUpDown.Value != 0) { tiltUpDown.Value = 0; } else { kinectDevice.SetMotorTilt((int)tiltUpDown.Value); } timer.Start(); ret = true; } catch (Exception ex) { MessageBox.Show("Failed connecting to Kinect device.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Disconnect(); } } Cursor = Cursors.Default; return(ret); }
public ColorCallMiniGame(GraphicsDevice graphicsDevice) { sb = new SpriteBatch(graphicsDevice); ein = new Kinect(0, 0); ein.Init(); gameState = MiniGameState.Initialized; }
public PointerGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); pointerPosition = new Vector2(GameConstants.MiniGameCanvasWidth, GameConstants.MiniGameCanvasHeight); ein = Game1.ein; }
public float getAnalog(Kinect.AnalogId analog) { if (!this.useKinect) { return(0.5f); } return(Kinect.getAnalogValue(analog)); }
/// <summary> /// Class constructor for 1 player mode. /// </summary> /// <remarks> /// </remarks> public UserAvatar(Kinect kinect, ContentManager content, GraphicsDevice graphicsDevice, SpriteBatch spriteBatch) { this.kinect = kinect; this.graphics = graphicsDevice; screenWidth = graphics.Viewport.Width; screenHeight = graphics.Viewport.Height; this.spriteBatch = spriteBatch; this.content = content; allAvatars = new Texture2D[4]; }
public void LeftHelloDetected() { var fileStream = new FileStream(RecordingPath, FileMode.Open); Kinect.ReplayStart(fileStream); Thread.Sleep(8000); fileStream.Close(); Assert.True(_leftHello); }
public Skeleton(int x, int y, Kinect kinect, Posture posture) : base(x, y) { this.posture = posture; this.sensor = kinect.kinectSensor; if (this.sensor != null) { this.mapper = new CoordinateMapper(this.sensor); } }
public void Initialize(string Path, Kinect kinect, Vector2 Position, int buttonWidth, int buttonHeight) { texturePath = Path; this.kinect = kinect; position = Position; textureWidth = buttonWidth; textureHeight = buttonHeight; textureBoundsSet = true; hoverColor = new Color(255, 255, 255, 220); }
public void StopTracking(bool gameFinished = false) { TrackingResultProcessing.Reset(); Kinect.Dispose(); Kinect = null; if (!gameFinished) { ProgramState.StoppedTracking(); } }
public Robot() { com = new MyCom(this); omniDrive = new OmniDrive(); bumper = new Bumper(); kinect = new MyKinect(this); omniDrive.setComId(com.id()); bumper.setComId(com.id()); kinect.setComId(com.id()); }
public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; graphics.IsFullScreen = false; Content.RootDirectory = "Content"; Kinect = new Kinect(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); screenManager = new ScreenManager(this, Kinect); Components.Add(screenManager); }
void Start() { kinect = new Kinect (); kinect.Start(); DepthGenerator depth = kinect.GetDepthGenerator(); MapOutputMode mapMode = depth.GetMapOutputMode(); texture = new Texture2D ((int)mapMode.nXRes, (int)mapMode.nYRes, TextureFormat.RGB24, false); texture.wrapMode = TextureWrapMode.Clamp; renderer.material.mainTexture = texture; }
public override void Init(FarseerPhysics.Dynamics.World w, Kinect.RagdollManager r) { world = w; target = r.ragdoll; body.setWorld(w); body.OnCollision += new OnCollisionEventHandler(body_OnCollision); world.ProcessChanges(); IsOperational = true; }
public Matrix44f getSensorMatrix(Kinect.TrackerId sensor) { if (!this.useKinect) { return(null); } Cave.Matrix44f m = Kinect.getTracker(sensor); return(m); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { var kinect = new Kinect(); App.Current.Exit += ((s, args) => { kinect.ShouldRun = false; }); this.DataContext = App.ViewModel; }
public Game1() { graphics = new GraphicsDeviceManager(this); ein = new Kinect(0, 0); ein.Init(); graphics.PreferredBackBufferWidth = GameConstants.GameResolutionWidth; graphics.PreferredBackBufferHeight = GameConstants.GameResolutionHeight; graphics.ToggleFullScreen(); Content.RootDirectory = "Content"; }
public MainWindow() { InitializeComponent(); controlDevices = new IControl[3]; controlDevices[0] = new GamePad(PadStatusChanged); controlDevices[1] = new Keyboard(); controlDevices[2] = new Kinect(); currentDevice = Device.Keyboard; connection = new Connection(controlDevices, currentDevice); this.Closing += OnWindowClosing; ((Kinect) controlDevices[2]).SkeletonTracked += KinectSkeletonTracked; DataContext = controlDevices[2]; }
static void Main(string[] args) { // Start the KinectService process in a minimized window. This is required for any Kinect application to run. Console.WriteLine("Starting KinectService.exe..."); ProcessStartInfo KinectService = new ProcessStartInfo(@"C:\Windows\System32\KinectService.exe"); KinectService.WindowStyle = ProcessWindowStyle.Minimized; Process KinectProcess = Process.Start(KinectService); server.Start(socket => { socket.OnOpen = () => { Console.WriteLine("Opening a new socket..."); // Add the socket address to the master list allSockets.Add(socket); Console.WriteLine("Initializing Kinect..."); // Initialize a new Kinect object Kinect alpha = new Kinect(); alpha.InitializeKinect(); }; socket.OnClose = () => { Console.WriteLine("Closing all connections..."); // Remove the socket record from the master list allSockets.Remove(socket); }; }); // Logic to allow for a soft quit of the server when "exit" is input at the CLI var input = Console.ReadLine(); if (input == "exit") { // Purge the KinectService process and close the console window KinectProcess.CloseMainWindow(); KinectProcess.Close(); // Close the main console window System.Environment.Exit(0); } else { while (input != "exit") { input = Console.ReadLine(); } } }
/// <summary> /// Creates a new instance of ScreenManager. /// </summary> public ScreenManager(Microsoft.Xna.Framework.Game game, Kinect.Kinect kinect) : base(game) { this.Kinect = kinect; if (Kinect.trackedSkeleton != null) { Constants.posY = Kinect.trackedSkeleton.Joints[JointType.HipCenter].Position.Y; Constants.posZ = Kinect.trackedSkeleton.Joints[JointType.ElbowRight].Position.Z; Constants.elbowPosY = Kinect.trackedSkeleton.Joints[JointType.ElbowRight].Position.Y; Constants.diffHandElbow = Kinect.trackedSkeleton.Joints[JointType.HandRight].Position.Z - Kinect.trackedSkeleton.Joints[JointType.ElbowRight].Position.Z; Constants.HipPosX = Kinect.trackedSkeleton.Joints[JointType.HipCenter].Position.X; } base.Initialize(); }
public Kardashian(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); random = new Random(); ein = Game1.ein; height = 50; width = 50; density = 1f; posx = 200; posy = 50; height2 = 50; width2 = 50; density2 = 1f; posx2 = 200; posy2 = 200; gravity = 0f; // TODO: Add your initialization logic here world = new World(new Vector2(0, gravity)); PlainTexture = new Texture2D(this.graphicsDevice, 1, 1); PlainTexture.SetData(new[] { Color.White }); GoalTexture = new Texture2D(this.graphicsDevice, 1, 1); GoalTexture.SetData(new[] { Color.Red }); body = BodyFactory.CreateRectangle(world, width * pixelToUnit, height * pixelToUnit, density); body.BodyType = BodyType.Dynamic; size = new Vector2(width, height); Size = size; body.Position = new Vector2(posx * pixelToUnit, posy * pixelToUnit); body.SleepingAllowed = false; body2 = BodyFactory.CreateRectangle(world, width2 * pixelToUnit, height2 * pixelToUnit, density2); body2.BodyType = BodyType.Dynamic; size2 = new Vector2(width2, height2); Size2 = size2; body2.Position = new Vector2(random.Next(1, GameConstants.MiniGameCanvasWidth) * pixelToUnit, random.Next(1, GameConstants.MiniGameCanvasHeight) * pixelToUnit); body2.SleepingAllowed = false; }
/// <summary> /// Gets the sensor. /// </summary> /// <returns> /// The sensor. /// </returns> /// <param name='sensor'> /// Sensor. /// </param> public Vector3 getSensor( Kinect.TrackerId sensor ) { if ( !Config.Instance.UseKinect ) { return new Vector3 (); } Cave.Matrix44f m = Kinect.getTracker ( sensor ); //if (Config.Instance.IsStandalone) // vec.y += Config.Instance.bodyHeightLocalKinect; // Der Server verwendet ein rechtshändiges Koordinatensystem (Z zeigt nach hinten), // Unity ein linkshändiges (Z zeigt nach vorn), deswegen Z umdrehen. Vector3 vec = new Vector3 ( m [ 0, 3 ], m [ 1, 3 ], m [ 2, 3 ] ); vec.z *= -1; return vec; }
public override void Update(Kinect.SkeletonInfo info) { base.Update(info); flappedLeft = flappedRight = false; if (ShouldFlap(leftWrist, leftVel)) { flappedLeft = true; ExertFlapLeft(leftVel); } if (ShouldFlap(rightWrist, rightVel)) { flappedRight = true; ExertFlapRight(rightVel); } }
public override void Update(Kinect.SkeletonInfo info) { base.Update(info); if (leftHandGrabGrace > 0) leftHandGrabGrace--; if (rightHandGrabGrace > 0) rightHandGrabGrace--; if (!rightGrip && info.rightHand.Z < info.torso.Z + grabPlane && rightVel.Z < grabVel) { rightHandGrabGrace = grabGrace; //TryRightGrip(); } if (rightHandGrabGrace > 0) { TryRightGrip(); } else if (rightGrip && info.rightHand.Z > info.torso.Z + releasePlane) { ReleaseRightGrip(); } if (!leftGrip && info.leftHand.Z < info.torso.Z + grabPlane && leftVel.Z < grabVel) { leftHandGrabGrace = grabGrace; //TryLeftGrip(); } if (leftHandGrabGrace > 0) { TryLeftGrip(); } else if (leftGrip && info.leftHand.Z > info.torso.Z + releasePlane) { ReleaseLeftGrip(); } }
public FootGame(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; ein = Game1.ein; if ((new Random()).Next() % 2 == 0) { foot = "left"; } else { foot = "right"; } sb = new SpriteBatch(graphicsDevice); backgroundColor = new Color((float)Game1.GameRandom.NextDouble(), (float)Game1.GameRandom.NextDouble(), (float)Game1.GameRandom.NextDouble(), 1); gameState = MiniGameState.Initialized; }
/// <summary> /// Get all bones orientation based on the skeleton passed in /// </summary> /// <returns> /// Bone Orientation in struct of NuiSkeletonBoneOrientation, quarternion and matrix /// </returns> NuiSkeletonBoneOrientation[] KinectInterface.getBoneOrientations(Kinect.NuiSkeletonData skeletonData) { NuiSkeletonBoneOrientation[] boneOrientations = new NuiSkeletonBoneOrientation[(int)(NuiSkeletonPositionIndex.Count)]; NativeMethods.NuiSkeletonCalculateBoneOrientations(ref skeletonData, boneOrientations); return boneOrientations; }
//Takes a skeleton frame and an activity step, and checks if it is correct public Boolean IsSkeletonMatch(SkeletonFrame skelFrame, Kinect.ActivityStep currentStep) { if (currentStep == null) { return false; } Skeletons = new Skeleton[skelFrame.SkeletonArrayLength]; skelFrame.CopySkeletonDataTo(Skeletons); //flag, so that we can return false if no skeleton compared bool isGoodJoint = false; //flag to set as false if a joint comparison isn't run foreach (Skeleton Skel in Skeletons) { if (Skel.TrackingState == SkeletonTrackingState.NotTracked || Skel.TrackingState == SkeletonTrackingState.PositionOnly) { continue; } if (currentStep.usesNewRotationFormat) { foreach (Kinect.BoneOrientationCharacteristics boneIdealBone in currentStep.BoneComparison) //new format { if (boneIdealBone == null) { continue; } Joint jnt1 = new Joint(); Joint jnt2 = new Joint(); foreach (Joint skelJoint in Skel.Joints) { if (skelJoint.JointType == boneIdealBone.FirstJoint) { jnt1 = skelJoint; } if (skelJoint.JointType == boneIdealBone.SecondJoint) { jnt2 = skelJoint; } } boneIdealBone.tempMatched = boneIdealBone.boolBoneOrientationIsMatch(jnt1, jnt2); } foreach (Kinect.BoneOrientationCharacteristics boneIdealBone in currentStep.BoneComparison) { if (boneIdealBone == null) { continue; } if (boneIdealBone.tempMatched) { isGoodJoint = true; } else { return false; } } } else //Old format comparison { bool jointflag = false; foreach (Kinect.JointOrientationCharacteristics jntIdealJoint in currentStep.JointComparison) { if (jntIdealJoint != null) { foreach (Joint skelJoint in Skel.Joints) { isGoodJoint = true; if (skelJoint.JointType == jntIdealJoint.JointTypeID) { jointflag = true; //run comparison and stop comparing if if (compareIsSame(skelJoint, jntIdealJoint) == false) { //stop checking through bones, comparison doesn't work return false; } break; } } if (jointflag == false) { //returns false if not every joint has been available for comparison return false; } } } } } //return true if comparison run and no false joints found if (isGoodJoint == true) { return true; } else { return false; } }
public Boolean isSkelMatchTimed(SkeletonFrame skelFrame, Kinect.ActivityStep currentStep) { if (IsSkeletonMatch(skelFrame, currentStep) == true) { if (currentStep.IsHoldInProgress() == true) { if (currentStep.isHeldLongEnough() == true) { return true; } else { return false; } } else { currentStep.SetHoldTimer(); } } else { currentStep.ClearHoldTimer(); } return false; }
public override void Update(Kinect.SkeletonInfo info) { base.Update(info); //Vector3 newLeft = info.LocationToGestureSpace(info.leftWrist); //Vector3 newRight = info.LocationToGestureSpace(info.rightWrist); //Vector2 shoulderBump = KinectLocationToFarseerLocation((info.centerShoulder - info.torso) * .2f, info); leftShoulder = info.LocationToGestureSpace(info.leftShoulder); rightShoulder = info.LocationToGestureSpace(info.rightShoulder); //leftShoulderFarseer = GestureLocationToFarseerLocation(leftShoulder, info); //if (!wasAsleep && wasPossessed) //{ if (rightCooldown > 0) { rightCooldown--; } else { //Vector3 rightVel = (newRight - rightWrist) / info.TimeDiff; if (shouldFire(rightWrist, rightVel, rightShoulder)) { fire(rightWrist, rightVel, true); rightCooldown = cooldown; } } if (leftCooldown > 0) { leftCooldown--; } else { //Vector3 leftVel = (newLeft - leftHand) / info.TimeDiff; if (shouldFire(leftWrist, leftVel, leftShoulder)) { fire(leftWrist, leftVel, false); leftCooldown = cooldown; } } //} //rightHand = newRight; //leftHand = newLeft; }
void Start() { camHolder = GameObject.Find ( "CamHolder" ).transform; body = GameObject.Find ( "Player" ).GetComponent<CapsuleCollider> (); leftArm = GameObject.Find ( "LeftArm" ); rightArm = GameObject.Find ( "RightArm" ); armaturePlayer1 = new BodyArmature ( "PlayerMainAvatar" ); if ( Config.Instance.UseKinect ) { Logger.Log ( "Verbinde zu Kinect: " + Config.Instance.KinectAddress ); Kinect = new Kinect ( Config.Instance.KinectAddress ); } }
public BrickMiniGame(GraphicsDevice graphicsDevice) { targets = new List<Body>(); this.graphicsDevice = graphicsDevice; sb = new SpriteBatch(graphicsDevice); ein = Game1.ein; circleTexture = CreateCircle(ballRadius, graphicsDevice); paddleTexture = CreateCircle(paddleRadius, graphicsDevice); targetTexture = CreateCircle(targetRadius, graphicsDevice); gameState = MiniGameState.Initialized; physicsWorld = new World(new Vector2(0, 0f)); Random rand = new Random(DateTime.Now.Ticks.GetHashCode()); for (int i = 0; i < 2; i++) { Body body = BodyFactory.CreateCircle(physicsWorld, targetRadius * pixelToUnit, 1000f); body.BodyType = BodyType.Static; body.Position = new Vector2((float)(32 + rand.NextDouble() * (GameConstants.MiniGameCanvasWidth - 64)) * pixelToUnit, (float)(32 + rand.NextDouble() * (GameConstants.MiniGameCanvasHeight - 150)) * pixelToUnit); targets.Add(body); } paddle = BodyFactory.CreateCircle(physicsWorld, paddleRadius * pixelToUnit, 1000f); paddle.BodyType = BodyType.Dynamic; paddle.Position = new Vector2(GameConstants.MiniGameCanvasWidth / 2 * pixelToUnit, (GameConstants.MiniGameCanvasHeight+20) * pixelToUnit); paddle.SleepingAllowed = false; paddle.Restitution = 1.0f; paddle.IgnoreGravity = true; paddle.Mass = 10000000; paddle.Friction = 0; wallLeft = BodyFactory.CreateRectangle(physicsWorld, 16 * pixelToUnit, GameConstants.MiniGameCanvasHeight * pixelToUnit, 1000f); wallLeft.BodyType = BodyType.Static; wallLeft.Position = new Vector2(0, GameConstants.MiniGameCanvasHeight / 2f * pixelToUnit); wallLeft.SleepingAllowed = false; wallLeft.Restitution = 1.0f; wallLeft.Friction = 0; wallRight = BodyFactory.CreateRectangle(physicsWorld, 16 * pixelToUnit, GameConstants.MiniGameCanvasHeight * pixelToUnit, 1000f); wallRight.BodyType = BodyType.Static; wallRight.Position = new Vector2(GameConstants.MiniGameCanvasWidth * pixelToUnit, GameConstants.MiniGameCanvasHeight / 2f * pixelToUnit); wallRight.SleepingAllowed = false; wallRight.Restitution = 1.0f; wallRight.Friction = 0; wallTop = BodyFactory.CreateRectangle(physicsWorld, GameConstants.MiniGameCanvasWidth * pixelToUnit, 16 * pixelToUnit, 1000f); wallTop.BodyType = BodyType.Static; wallTop.Position = new Vector2(GameConstants.MiniGameCanvasWidth / 2 * pixelToUnit, 0); wallTop.SleepingAllowed = false; wallTop.Restitution = 1.0f; wallTop.Friction = 0; ball = BodyFactory.CreateCircle(physicsWorld, (ballRadius) * pixelToUnit, 1000f); ball.BodyType = BodyType.Dynamic; ball.Position = new Vector2(GameConstants.MiniGameCanvasWidth / 2 * pixelToUnit, (GameConstants.MiniGameCanvasHeight - 100) * pixelToUnit); ball.Restitution = 1.0f; ball.Mass = 200; ball.SleepingAllowed = false; ball.AngularDamping = 1.0f; ball.FixedRotation = true; ball.Friction = 0; float speed = 8; float theta = (float)(Math.PI / 4 + new Random().NextDouble() * Math.PI / 2); float x = (float)Math.Cos(theta) * speed; float y = (float)-Math.Sin(theta) * speed; ball.LinearVelocity = new Vector2(x, y); while (Math.Abs(ball.LinearVelocity.X) < 0.1 && Math.Abs(ball.LinearVelocity.Y) < 0.1) { theta = (float)(Math.PI / 4 + new Random().NextDouble() * Math.PI / 2); x = (float)Math.Cos(theta) * speed; y = (float)-Math.Sin(theta) * speed; ball.LinearVelocity = new Vector2(x, y); } }
void OnGestureRecognized(object sender, Kinect.Gestures.GestureEventArgs e) { Debug.Log(e.GestureName.ToString()); LastRecognizedGesture = e.GestureName.ToString(); }
public TwoBodyPartsAction(Kinect kinect, SkeletonSelector bodyParts) : base(kinect) { this._bodyParts = bodyParts; }
public KinectConverters(Kinect kinect) { _kinect = kinect; }
public BodyPartAction(Kinect kinect) { this._kinect = kinect; if (this._kinect != null) this._kinect.SkeletonUpdate += new Action<uint, Skeleton>(this.SkeletonUpdate); }