コード例 #1
0
    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);
    }
コード例 #2
0
    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;
    }