예제 #1
0
    /*private IEnumerator PullPush(Vector3 target, HandRole hand, Action<Direction> action)
     * {
     *  yield return null;
     *
     *  float threshold = 20;
     *  Debug.Log("Registering Pull and Push");
     *
     *  Vector3 playerForward = target - Camera.main.transform.position;
     *  if (hand == HandRole.RightHand)
     *  {
     *      while (GetIsPressed(hand))
     *      {
     *          if (VivePose.GetAngularVelocity(hand).sqrMagnitude > 30)
     *          {
     *              if (Vector3.Cross(playerForward, VivePose.GetAngularVelocity(hand)).x < threshold * -1 && Mathf.Abs(Vector3.Dot(playerForward, VivePose.GetAngularVelocity(hand))) < 30)
     *              {
     *                  Debug.Log("Push");
     *                  action(Direction.Backward);
     *                  break;
     *              }
     *              else if (Vector3.Cross(playerForward, VivePose.GetAngularVelocity(hand)).x > threshold && Mathf.Abs(Vector3.Dot(playerForward, VivePose.GetAngularVelocity(hand))) < 30)
     *              {
     *                  Debug.Log("Pull");
     *                  action(Direction.Forward);
     *                  break;
     *              }
     *          }
     *          yield return null;
     *      }
     *  }
     *  else if (hand == HandRole.LeftHand)
     *  {
     *      while (GetIsPressed(hand))
     *      {
     *          if (VivePose.GetAngularVelocity(hand).sqrMagnitude > 30)
     *          {
     *              if (Vector3.Cross(playerForward, VivePose.GetAngularVelocity(hand)).x < threshold * -1 && Mathf.Abs(Vector3.Dot(playerForward, VivePose.GetAngularVelocity(hand))) < 30)
     *              {
     *                  Debug.Log("Pull");
     *                  action(Direction.Forward);
     *                  break;
     *              }
     *              else if (Vector3.Cross(playerForward, VivePose.GetAngularVelocity(hand)).x > threshold && Mathf.Abs(Vector3.Dot(playerForward, VivePose.GetAngularVelocity(hand))) < 30)
     *              {
     *                  Debug.Log("Push");
     *                  action(Direction.Backward);
     *                  break;
     *              }
     *          }
     *          yield return null;
     *      }
     *  }
     * }*/
    private IEnumerator PullPush(HandRole hand, Action <Direction> action)
    {
        yield return(null);

        Vector3   velocity;
        Transform camera = Camera.main.transform;

        while (GetIsPressed(hand))
        {
            velocity = VivePose.GetVelocity(hand);

            if (velocity.sqrMagnitude > 2)
            {
                if (velocity.y > -1 && velocity.y < 1)
                {
                    float dot   = Vector3.Dot(Vector3.forward, camera.InverseTransformVector(velocity) - camera.InverseTransformVector(VivePose.GetPose(hand).pos));
                    float angle = Vector3.Angle(Vector3.forward, camera.InverseTransformVector(velocity) - camera.InverseTransformVector(VivePose.GetPose(hand).pos));

                    if (angle < 60 || angle > 120)
                    {
                        showGuidingArrows = false;

                        yield return(null);

                        if (Mathf.Sign(dot) == 1)
                        {
                            DataRecorder.instance.SetEvent("Push");
                            action(Direction.Backward);

                            break;
                        }
                        else if (Mathf.Sign(dot) == -1)
                        {
                            DataRecorder.instance.SetEvent("Pull");
                            action(Direction.Forward);

                            break;
                        }
                    }
                }
            }

            yield return(null);
        }
    }
예제 #2
0
    void OnGUI()
    {
        if (enableMotion && ShowDebug)
        {
            string rightFootDisplay = "";
            string leftFootDisplay  = "";

            if (rightFoot != null)
            {
                rightFootDisplay = string.Format("Right Foot - Connected:\nangular\nx [{0}]\ny [{1}]\nz [{2}]\nvel\nx [{3}]\ny [{4}]\nz [{5}]\n",
                                                 VivePose.GetAngularVelocity(rightFoot).x,
                                                 VivePose.GetAngularVelocity(rightFoot).y,
                                                 VivePose.GetAngularVelocity(rightFoot).z,
                                                 VivePose.GetVelocity(rightFoot).x,
                                                 VivePose.GetVelocity(rightFoot).y,
                                                 VivePose.GetVelocity(rightFoot).z
                                                 );
            }
            else
            {
                rightFootDisplay = string.Format("Right Foot - Disconnected");
            }

            if (leftFoot != null)
            {
                leftFootDisplay = string.Format("Left Foot - Connected:\nangular\nx [{0}]\ny [{1}]\nz [{2}]\nvel\nx [{3}]\ny [{4}]\nz [{5}]\n",
                                                VivePose.GetAngularVelocity(leftFoot).x,
                                                VivePose.GetAngularVelocity(leftFoot).y,
                                                VivePose.GetAngularVelocity(leftFoot).z,
                                                VivePose.GetVelocity(leftFoot).x,
                                                VivePose.GetVelocity(leftFoot).y,
                                                VivePose.GetVelocity(leftFoot).z
                                                );
            }
            else
            {
                rightFootDisplay = string.Format("Left Foot - Disconnected");
            }

            GUI.Label(new Rect(10, 10, 500, 300), rightFootDisplay);
            GUI.Label(new Rect(10, 350, 500, 300), leftFootDisplay);
        }
    }
예제 #3
0
    void Update()
    {
        if (!enableMotion)
        {
            return;
        }

        if (VivePose.GetVelocity(headSet).y > 0)
        {
            if (direction < 0)
            {
                direction = 0;
            }
            direction++;
        }
        else if (VivePose.GetVelocity(headSet).y < 0)
        {
            if (direction > 0)
            {
                direction = 0;
            }
            direction--;
        }

        if (enableMotion && Mathf.Abs(direction) < yMovementLimit && leftFoot != null)
        {
            LeftAngularVelocity = Mathf.Abs(VivePose.GetAngularVelocity(leftFoot).x) + Mathf.Abs(VivePose.GetAngularVelocity(leftFoot).y) + Mathf.Abs(VivePose.GetAngularVelocity(leftFoot).z);
            LeftVelocity        = Mathf.Abs(VivePose.GetVelocity(leftFoot).x) + Mathf.Abs(VivePose.GetVelocity(leftFoot).y) + Mathf.Abs(VivePose.GetVelocity(leftFoot).z);
            Vector3 movementVector = Vector3.ProjectOnPlane(ReverseControllerDirection.transform.up, Vector3.up);
            movementMultiplier = Time.deltaTime * (LeftAngularVelocity + LeftVelocity);
            if (movementMultiplier > maxMovementMultiplier)
            {
                movementMultiplier = maxMovementMultiplier;
            }
            else if (movementMultiplier < minMovementMultiplier)
            {
                movementMultiplier = 0f;
            }

            Vector3 MovementLeftAmount = movementVector * movementMultiplier * movementScale;

            player.SimpleMove(MovementLeftAmount);
        }

        if (enableMotion && Mathf.Abs(direction) < yMovementLimit && rightFoot != null)
        {
            RightAngularVelocity = Mathf.Abs(VivePose.GetAngularVelocity(rightFoot).x) + Mathf.Abs(VivePose.GetAngularVelocity(rightFoot).y) + Mathf.Abs(VivePose.GetAngularVelocity(rightFoot).z);
            RightVelocity        = Mathf.Abs(VivePose.GetVelocity(rightFoot).x) + Mathf.Abs(VivePose.GetVelocity(rightFoot).y) + Mathf.Abs(VivePose.GetVelocity(rightFoot).z);

            Vector3 movementVector = Vector3.ProjectOnPlane(ReverseControllerDirection.transform.up, Vector3.up);

            movementMultiplier = Time.deltaTime * (RightAngularVelocity + RightVelocity);
            if (movementMultiplier > maxMovementMultiplier)
            {
                movementMultiplier = maxMovementMultiplier;
            }
            else if (movementMultiplier < minMovementMultiplier)
            {
                movementMultiplier = 0f;
            }
            Vector3 MovementRightAmount = movementVector * movementMultiplier * movementScale;

            player.SimpleMove(MovementRightAmount);
        }
        player.SimpleMove(new Vector3(0, 0, 0));
    }