private MouseControlState UpdateHandMouseControl(int handIndex, MouseControlState controlState) { if (controlState == MouseControlState.ShouldClick) { if (!handGrips[handIndex]) { MouseControl.Click(); handGrips[handIndex] = true; return(MouseControlState.Clicked); } } else if (controlState == MouseControlState.ShouldPress) { if (!handGrips[handIndex]) { MouseControl.PressDown(); handGrips[handIndex] = true; return(MouseControlState.PressedDown); } } else if (controlState == MouseControlState.ShouldRelease && handGrips[handIndex]) { ReleaseGrip(handIndex); return(MouseControlState.PressedUp); } return(MouseControlState.None); }
public Data(double xPos, double yPos, MouseControlState state, double xHand, double yHand, HandState handState, TrackingConfidence trackingConfidence, TrackingState trackingState) { XHand = xHand; YHand = yHand; HandState = handState; HandConfidence = trackingConfidence; TrackingState = trackingState; XPos = xPos; YPos = yPos; State = state; }
public Data(double xPos, double yPos, MouseControlState state, Body body) { Joint RightHand = body.Joints[JointType.HandRight]; XHand = RightHand.Position.X; YHand = RightHand.Position.Y; TrackingState = RightHand.TrackingState; HandState = body.HandRightState; HandConfidence = body.HandRightConfidence; XPos = xPos; YPos = yPos; State = state; }
private void UpdateHandMouseControl(int handIndex, MouseControlState controlState) { if (controlState == MouseControlState.ShouldClick) { if (!handGrips[handIndex]) { MouseControl.Click(); handGrips[handIndex] = true; } } else if (controlState == MouseControlState.ShouldPress) { if (!handGrips[handIndex]) { MouseControl.PressDown(); handGrips[handIndex] = true; } } else if (controlState == MouseControlState.ShouldRelease && handGrips[handIndex]) { ReleaseGrip(handIndex); } }
private void Kinect_OnTrackedBody(object sender, BodyEventArgs e) { Body body = e.BodyData; if (Mode == ControlMode.Disabled) { return; } for (int i = 1; i >= 0; i--) // Starts looking from right hand. { bool isLeft = i == 0; if (body.IsHandLiftForward(isLeft)) { if (usedHandIndex == -1) { usedHandIndex = i; } else if (usedHandIndex != i) { // In two-hand control mode, non-used hand would be used for pressing/releasing mouse button. if (Mode == ControlMode.MoveGripPressing) { DoMouseControlByHandState(i, body.GetHandState(isLeft)); } continue; } MVector2 handPos = body.GetHandRelativePosition(isLeft); MVector2 targetPos = cursorMapper.GetSmoothedOutputPosition(handPos); MouseControl.MoveTo(targetPos.X, targetPos.Y); if (Mode == ControlMode.GripToPress) { MouseControlState state = DoMouseControlByHandState(i, body.GetHandState(isLeft)); Data d = new Data(targetPos.X, targetPos.Y, state, body); if (task_num != 0) { DataCollector.CollectData(d); } PositionDataUpdated?.Invoke(this, d); } else if (Mode == ControlMode.HoverToClick) { if ((targetPos - lastCursorPos).Length() > HoverRange) { ToggleHoverTimer(false); hoverClicked = false; } lastCursorPos = targetPos; } } else { if (usedHandIndex == i) { // Reset to none. usedHandIndex = NONE_USED; ReleaseGrip(i); } else if (Mode == ControlMode.MoveLiftClicking) { DoMouseClickByHandLifting(i, body.GetHandRelativePosition(isLeft)); //System.Diagnostics.Trace.WriteLine(body.GetHandRelativePosition(isLeft).Y); } else // Release mouse button when it's not regularly released, such as hand tracking lost. { ReleaseGrip(i); } } } ToggleHoverTimer(Mode == ControlMode.HoverToClick && usedHandIndex != -1); }
public void SwitchToPicker() { state = MouseControlState.Picker; UpdateControllers(); }
public void SwitchToDirector() { state = MouseControlState.Director; UpdateControllers(); }
public void SwitchToAdmin() { state = MouseControlState.Admin; UpdateControllers(); }
// Use this for initialization private void Start() { state = startingState; UpdateControllers(); }