/// <summary> /// Adds a Kinect3DObject (3D Models) /// </summary> /// <param name="kinectObject">A Kinect3DObject</param> public void AddKinectObject(Kinect3DObject kinectObject) { if (kinect3DObjects == null) { kinect3DObjects = new List <Kinect3DObject>(); } kinect3DObjects.Add(kinectObject); if (this.RenderObjects) { KinectDraw.RenderKinect3DObjects(ModelVisual, kinect3DObjects); } }
/// <summary> /// The Body reader evnet /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) { using (var frame = e.FrameReference.AcquireFrame()) { if (frame != null && this.maxBodyCount > 0) { var bodies = new Body[this.maxBodyCount]; frame.GetAndRefreshBodyData(bodies); var closestBody = KinectUtils.GetClosestBody(frame); Canvas.Children.Clear(); foreach (Body body in bodies) { if (body.IsTracked && body != null) { //Draw The Skeleton if (this.DrawDots) { KinectDraw.DrawDots(Canvas, kinectSensor, body); } //Draw the images if (this.DrawImages) { KinectDraw.DrawKinectObjects(Canvas, kinectSensor, body, kinectObjects); } //Render 3D Objects if (this.RenderObjects) { KinectDraw.UpdateKinect3DObjects(body, kinect3DObjects); } //Use the Kinect to control the mouse and it is the closest body if (this.KinectAsMouse && closestBody != null && body.TrackingId == closestBody.TrackingId) { CameraSpacePoint mousePoint = body.Joints[Mouse].Position; CameraSpacePoint spinePoint = body.Joints[JointType.SpineBase].Position; //Is the hand in front of the person? if (mousePoint.Z - spinePoint.Z < -0.15f) { Point curPos = MouseOverride.GetCursorPosition(); MouseOverride.SetCursorPos((int)(curPos.X + (mousePoint.X * 2f * (int)SystemParameters.PrimaryScreenWidth - curPos.X) * 0.4), (int)(curPos.Y + (((spinePoint.Y - mousePoint.Y + 0.5f) + 0.25f) * 2f * (int)SystemParameters.PrimaryScreenHeight - curPos.Y) * 0.4)); if (body.HandRightState == HandState.Closed) { if (!grippedHand) { // If the hand is closed hold down the left mouse button MouseOverride.MouseLeftDown(); grippedHand = true; System.Windows.Input.Mouse.OverrideCursor = Cursor; } } else if (body.HandRightState == HandState.Open) { if (grippedHand) { // If the hand is opened let go of the left mouse button MouseOverride.MouseLeftUp(); grippedHand = false; System.Windows.Input.Mouse.OverrideCursor = null; } } } else { grippedHand = true; } } } } } } }