private int CheckAimConditions(SkeletonData latestSkeleton) { int gestureResult = (int)ResultCodes.Success; do { bool aim = false; bool isInsideAim = false; if (latestSkeleton == null) { gestureResult = (int)ResultCodes.OutOfMemory; break; } if (!this.aimDetected) { aim = IsAimTrue(latestSkeleton); } if (aim && !this.aimDetected) { MouseEventData mouseData = new MouseEventData(); mouseData.MouseAction = (int)MouseButton.RIGHT_MOUSE_BUTTON; mouseData.XCoordinate = -1; mouseData.YCoordinate = -1; mouseData.KeyPersistance = (int)MousePresistance.PRESS_AND_RELEASE; this.RaiseMouseEvent(mouseData); this.aimDetected = true; break; } isInsideAim = JackInManojsBox(latestSkeleton); if (!isInsideAim && this.aimDetected) { MouseEventData mouseData = new MouseEventData(); mouseData.MouseAction = (int)MouseButton.RIGHT_MOUSE_BUTTON; mouseData.XCoordinate = -1; mouseData.YCoordinate = -1; mouseData.KeyPersistance = (int)MousePresistance.PRESS_AND_RELEASE; this.RaiseMouseEvent(mouseData); this.aimDetected = false; break; } } while (false); return gestureResult; }
void shootGesture_mouseGestureAction(object sender, MouseEventData eventData) { SendMouseCommand(eventData.MouseAction, eventData.KeyPersistance, eventData.XCoordinate, eventData.YCoordinate); }
private int ProcessNewGestureData(NuiElement newGestureData) { SkeletonData latestSkeleton = (from skeletons in newGestureData.GetSkeletonFrame().Skeletons where skeletons.TrackingState == SkeletonTrackingState.Tracked select skeletons).FirstOrDefault(); if (latestSkeleton == null) { return (int)ResultCodes.OutOfMemory; } bool isInside = IsInsideBox(latestSkeleton); //IsFistRolled(latestSkeleton); if (isInside) { //this.logger.Debug("Hand inside the box is true"); float depthX, depthY, tmpX, tmpY, scaledDepthX, scaledDepthY; Joint leftHand = latestSkeleton.Joints[JointID.WristLeft]; Joint leftHip = latestSkeleton.Joints[JointID.HipLeft]; Joint leftShoulder = latestSkeleton.Joints[JointID.ShoulderLeft]; Joint rightHip = latestSkeleton.Joints[JointID.HipRight]; depthX = leftHand.Position.X; depthY = leftHand.Position.Y; if (frameNumber <= 1) { prevDepthX = depthX; prevDepthY = depthY; frameNumber++; } else { //applying relativety tmpX = depthX; tmpY = depthY; depthX = depthX - prevDepthX; depthY = depthY - prevDepthY; prevDepthX = tmpX; prevDepthY = tmpY; //applying scaling scaledDepthX = depthX * 800; scaledDepthY = -1 * depthY * 600; this.logger.Debug("FrameNumber = " + frameNumber); this.logger.Debug("Moving relativly X by = " + scaledDepthX); this.logger.Debug("Moving relativly Y by = " + scaledDepthY); MouseEventData mouseData = new MouseEventData(); mouseData.MouseAction = (int)MouseButton.MOUSE_MOVE; mouseData.XCoordinate = (int)scaledDepthX; mouseData.YCoordinate = (int)scaledDepthY; this.RaiseMouseEvent(mouseData); } } else { frameNumber = 0; } return 0; }
//Check various conditions to detect shoot gesture private int CheckShootConditions(SkeletonData latestSkeleton, NuiElement newGestureData) { int gestureResult = (int)ResultCodes.Success; do { bool shoot = false; bool isInsideBox = false; if (!this.shootDetected) { shoot = IsShootTrue(newGestureData); } // This condition becomes true when shoot is triggerd but it was not detected previously // If the user is already in shoot mode and still pulls the hand back this condition will not pass // Unless or until he moves his hand out of the box (set shootDetected to false) and // does shoot gesture again this condition will not pass. if (shoot && !this.shootDetected) { MouseEventData mouseData = new MouseEventData(); mouseData.MouseAction = (int)MouseButton.LEFT_MOUSE_BUTTON; mouseData.XCoordinate = -1; mouseData.YCoordinate = -1; mouseData.KeyPersistance = (int)MousePresistance.DOUBLE_CLICK_HOLD; this.RaiseMouseEvent(mouseData); this.shootDetected = true; logger.Debug(" Shoot detected first time"); break; } isInsideBox = IsInSideShootBox(newGestureData); if (this.shootDetected) { logger.Debug("ttt shootinggggg "); } //Orig end //New start if (this.shootDetected) { if (IsShootcancel(newGestureData)) { logger.Debug("ttt Shoot Cancel gesture detected!!"); MouseEventData mouseData = new MouseEventData(); mouseData.MouseAction = (int)MouseButton.LEFT_MOUSE_BUTTON; mouseData.XCoordinate = -1; mouseData.YCoordinate = -1; mouseData.KeyPersistance = (int)MousePresistance.RELEASE; this.RaiseMouseEvent(mouseData); this.shootDetected = false; this.trueCondtionSkeleton = null; logger.Debug(" Shoot detected while outside the box Negative "); break; } } //New end } while (false); return gestureResult; }
protected void RaiseMouseEvent(MouseEventData eventData) { if (mouseGestureAction != null) mouseGestureAction(this, eventData); }