public Vector3(Point3D start, Point3D end) { this.start = start; this.end = end; //set X,Y,Z this.X = start.X - end.X; this.Y = start.Y - end.Y; this.Z = start.Z - end.Z; }
/// <summary> /// Move the mouse according to the skeleton parameter with some conditions /// </summary> /// <param name="skeleton">the skeleton to link the movement</param> private void MoveMouse(Skeleton skeleton) { if (!OnlyTheHandIsMoving(mouse_Hand, skeleton)) { Rectangle resolution = Screen.PrimaryScreen.Bounds; Queue<Point3D> q = handControler.GetHandQueue(mouse_Hand); int weight = 0; Point3D pHand = new Point3D(); if (q.Count > 1) { //filtering noise values, i.e : from maxCursorDeviation pixels to the previous one Vector3 v = new Vector3(q.ToArray()[q.Count - 2], q.ToArray()[q.Count - 1]); if (v.Norm() > Helper.maxCursorDeviation) { q.Dequeue(); } float movingCenterY = KinectHelper.Instance.currentSkeleton.Joints[JointType.ShoulderCenter].Position.Y + Helper.virtualBoxY; float movingCenterX = (mouse_Hand == HandType.LEFT) ? -Helper.virtualBoxX : Helper.virtualBoxX; foreach (Point3D p in q) { pHand.X += (p.X - movingCenterX) * weight; pHand.Y += (p.Y - movingCenterY) * weight; weight++; } int x = (int)((pHand.X / weight) * ((resolution.Width / 2) / Helper._skeletonMaxX)); int y = -(int)((pHand.Y / weight) * ((resolution.Height / 2) / Helper._skeletonMaxY)); x = (x < resolution.Width) ? x : resolution.Width; x = (x > 0) ? x : 0; y = (y < resolution.Height) ? y : resolution.Height; y = (y > 0) ? y : 0; //Move the mouse //MouseSimulator.MoveMouseTo((int)x, (int)y); //MouseSimulator.MoveMouseBy((int)((x - mouseX) * Helper._mouseSensibility), (int)((y - mouseY))); mouseX = x; mouseY = y; } else if (q.Count == 0) { MousePoint mp = NativeMethods.GetCursorPosition(); mouseX = mp.X; mouseY = mp.Y; } } }
/// <summary> /// check if the elevation of the angle is correct for the according skeleton /// </summary> /// <param name="skeleton">the skeleton</param> private void CheckElevationAngle() { int depthResolutionWidth = (int)Helper._depthFrameWidth; int depthResolutionHeight = (int)Helper._depthFrameHeight; if (skeletonQueue.Count == skeletonQueueCount) { Point3D optimalPosition = new Point3D(depthResolutionWidth / 2.0f, depthResolutionHeight / 2.0f, 1.5f); Joint JointStart = skeletonQueue.ToArray()[0][6].ScaleToDepthResolution(); Joint JointEnd = skeletonQueue.ToArray()[skeletonQueue.Count - 1][6].ScaleToDepthResolution(); Point3D centerPositionAverage = new Point3D((JointEnd.Position.X + JointStart.Position.X) / 2.0f, (JointEnd.Position.Y - 40 + JointStart.Position.Y - 40) / 2.0f, (JointEnd.Position.Z + JointStart.Position.Z) / 2.0f); //value of the deviation Vector3 d = new Vector3(optimalPosition, centerPositionAverage); //the Kinect must point to the center of the rectangle where the hands are going to move if (Math.Abs(d.Y) > KinectHelper.maxPositionDeviation) { //elevation angle must be changed double angle = Math.Acos(centerPositionAverage.Z / Math.Sqrt(Math.Pow(centerPositionAverage.Z, 2) + Math.Pow(skeleton.Joints[JointType.ShoulderCenter].Position.Y, 2))) * 180 / Math.PI; if (d.Y > 0) { KinectHelper.Instance.elevationAngle = (int)angle; } else if (d.Y < 0) { KinectHelper.Instance.elevationAngle = (int)(-angle); } } else { } } }