public override TypingStatus ProcessNewFrame(Point3D cursor, ICollection<TypingGesture> gestures, Microsoft.Kinect.Skeleton stableSkeleton, double deltaTimeMilliseconds, TypingDexterity dexterity) { double columnData = cursor.X; double rowData = cursor.Y; double constraintData = cursor.Z; if (cursor.IsFrozen) { columnData = cursor.FrozenX; rowData = cursor.FrozenY; constraintData = cursor.FrozenZ; } if (columnData < 0 || rowData < 0) return new TypingStatus(); double stepX = 1.0 / layoutCols; double stepY = 1.0 / layoutRows; int col = (int)(columnData / stepX); int row = (int)(rowData / stepY); TypingStatus status = new TypingStatus(); status.HighlightedKey = layout[row * layoutCols + col]; if (gestures != null && gestures.Count > 0 && gestures.ElementAt(0).Type == GestureType.Tap) { TypingGesture gesture = gestures.ElementAt(0); col = (int)(gesture.Position.X / stepX); row = (int)(gesture.Position.Y / stepY); status.SelectedKey = layout[row * layoutCols + col]; } return status; }
public override TypingStatus ProcessNewFrame(Point3D cursor, ICollection<TypingGesture> gestures, Microsoft.Kinect.Skeleton stableSkeleton, double deltaTimeMilliseconds, TypingDexterity dexterity) { double columnData = cursor.X; double rowData = cursor.Y; double constraintData = cursor.Z; if (columnData < 0 || rowData < 0) return new TypingStatus(); double stepX = 1.0 / layoutCols; double stepY = 1.0 / layoutRows; int col = (int)(columnData / stepX); int row = (int)(rowData / stepY); currentPointingIndex = row * layoutCols + col; TypingStatus status = new TypingStatus(); if (currentSequenceIndex == 36) { return status; } if (layout[currentPointingIndex] == sequence[currentSequenceIndex]) { status.HighlightedKey = layout[currentPointingIndex]; if (currentSequenceIndex < sequence.Length) { currentSequenceIndex++; if (!started) started = true; else correctCount++; } } else { if (currentPointingIndex != previousPointingIndex) { if (started) { errorCount++; } } } if (gestures != null && gestures.Count > 0 && gestures.ElementAt(0).Type == GestureType.Tap) { TypingGesture gesture = gestures.ElementAt(0); col = (int)(gesture.Position.X / stepX); row = (int)(gesture.Position.Y / stepY); currentPointingIndex = row * layoutCols + col; status.SelectedKey = layout[currentPointingIndex]; } previousPointingIndex = currentPointingIndex; return status; }
internal override Point3D FindCursorPosition(Skeleton skeleton, LayoutAnchoring anchoring, System.Windows.Size layoutSize, TypingDexterity dexterity, SelectionMethod selectionM, ArmStretch armStretch) { TypingDexterity opposite = TypingDexterity.Right; if (dexterity == TypingDexterity.Right) opposite = TypingDexterity.Left; SetJointsForDexterity(opposite); Joint shoulder = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Shoulder); Joint hand = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Hand); Joint wrist = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Wrist); Joint hip = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Hip); double pointerPosX = (hand.Position.X + wrist.Position.X) / 2; double pointerPosY = (hand.Position.Y + wrist.Position.Y) / 2; double pointerPosZ = (hand.Position.Z + wrist.Position.Z) / 2; //this positions are calculated from the hip double posX = Math.Abs(pointerPosX - hip.Position.X); double posY = Math.Abs(pointerPosY - hip.Position.Y); double posZ = Math.Abs(pointerPosZ - hip.Position.Z); return new Point3D(posX, posY, posZ); }
public override TypingStatus ProcessNewFrame(Point3D cursor, ICollection<TypingGesture> gestures, Skeleton stableSkeleton, double deltaTimeMilliseconds, TypingDexterity dexterity) { throw new NotImplementedException(); }
internal virtual Point3D FindCursorPosition(Skeleton skeleton, LayoutAnchoring anchoring, Size layoutSize, TypingDexterity dexterity, SelectionMethod selectionM, ArmStretch armStretch) { SetJointsForDexterity(dexterity); Joint shoulder = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Shoulder); Joint hand = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Hand); Joint wrist = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Wrist); Joint hip = skeleton.Joints.SingleOrDefault(tmp => tmp.JointType == Hip); double width = layoutSize.Width / 100; double height = layoutSize.Height / 100; if (anchoring == LayoutAnchoring.VerticalShoulderLevel) { planeCenter.X = shoulder.Position.X + width / 2; planeCenter.Y = shoulder.Position.Y; } else if (anchoring == LayoutAnchoring.VerticalBodyCenterLevel) { planeCenter.X = shoulder.Position.X + width / 2; planeCenter.Y = (shoulder.Position.Y + hip.Position.Y) / 2; } else if (anchoring == LayoutAnchoring.HorizontalBottomLevel) { planeCenter.X = shoulder.Position.X + width / 2 + 0.05; //because of the coordinate direction planeCenter.Z = shoulder.Position.Z - height / 2 - 0.05; } double pointerPosX = (hand.Position.X + wrist.Position.X) / 2; double distX = pointerPosX - planeCenter.X; double pointerPosY = (hand.Position.Y + wrist.Position.Y) / 2; double distY = pointerPosY - planeCenter.Y; double pointerPosZ = (hand.Position.Z + wrist.Position.Z) / 2; double distZ = pointerPosZ - planeCenter.Z; Point3D pointer = new Point3D(pointerPosX, pointerPosY, pointerPosZ); Point3D origin = new Point3D(shoulder.Position.X, shoulder.Position.Y, shoulder.Position.Z); System.Windows.Media.Media3D.Vector3D distanceFromOrigin = ToolBox.CalculateDisplacement( (System.Windows.Media.Media3D.Vector3D)pointer, (System.Windows.Media.Media3D.Vector3D)origin); Point3D cursorP = new Point3D(-1, -1, -1); if (armStretch == ArmStretch.Long && distanceFromOrigin.Length < LONG_ARM_CONSTRAIN) return lastPos = cursorP; if (armStretch == ArmStretch.Short) { if (anchoring == LayoutAnchoring.VerticalShoulderLevel || anchoring == LayoutAnchoring.VerticalBodyCenterLevel) { if (Math.Abs(distanceFromOrigin.Z) > SHORT_ARM_CONSTRAIN) return lastPos = cursorP; } else if (anchoring == LayoutAnchoring.HorizontalBottomLevel) { if (Math.Abs(distanceFromOrigin.Y) > SHORT_ARM_CONSTRAIN) return lastPos = cursorP; } } //if the pointer is close enough to plane if (anchoring == LayoutAnchoring.VerticalShoulderLevel || anchoring == LayoutAnchoring.VerticalBodyCenterLevel) { //out of width boundary if (Math.Abs(distX) > width / 2) return lastPos = cursorP; //out of height boundary if (Math.Abs(distY) > height / 2) return lastPos = cursorP; double absX = distX + width / 2; double absY = height - ((height / 2) + distY); cursorP.X = absX / width; cursorP.Y = absY / height; cursorP.Z = distZ; cursorP = FreezeMovementesForSelectionGesture(cursorP, selectionM); lastPos = cursorP; } else //if (anchoring == LayoutAnchoring.HorizontalBottomLevel) { //out of column boundary if (Math.Abs(distX) > width / 2) return lastPos = cursorP; //out of row boundary if (Math.Abs(distZ) > height / 2) return lastPos = cursorP; double absX = distX + width / 2; double absZ = ((height / 2) + distZ); cursorP.X = absX / width; cursorP.Y = absZ / height; cursorP.Z = distY; cursorP = FreezeMovementesForSelectionGesture(cursorP, selectionM); lastPos = cursorP; } //if not close to plane, return an invalid cursorP return lastPos = cursorP; }
//this method is to be overridden by each particular typing method public abstract TypingStatus ProcessNewFrame(Point3D cursor, ICollection<TypingGesture> gestures, Skeleton stableSkeleton, double deltaTimeMilliseconds, TypingDexterity dexterity);
protected void SetJointsForDexterity(TypingDexterity dexterity) { if (dexterity == TypingDexterity.Right) { Shoulder = JointType.ShoulderRight; Elbow = JointType.ElbowRight; Wrist = JointType.WristRight; Hand = JointType.HandRight; Hip = JointType.HipRight; } else if (dexterity == TypingDexterity.Left) { Shoulder = JointType.ShoulderLeft; Elbow = JointType.ElbowLeft; Wrist = JointType.WristLeft; Hand = JointType.HandLeft; Hip = JointType.HipLeft; } }