GetLocalControllerAcceleration() public static method

Gets the linear acceleration of the given Controller local to its tracking space. Only supported for Oculus LTouch and RTouch controllers. Non-tracked controllers will return Vector3.zero.
public static GetLocalControllerAcceleration ( OVRInput, controllerType ) : Vector3
controllerType OVRInput,
return Vector3
    void Update()
    {
        string status = ""
                        + "<b>Active: </b>" + OVRInput.GetActiveController() + "\n"
                        + "<b>Connected: </b>" + OVRInput.GetConnectedControllers() + "\n";

        status += "Orientation: " + OVRInput.GetLocalControllerRotation(OVRInput.GetActiveController()) + "\n";
        status += "AngVel: " + OVRInput.GetLocalControllerAngularVelocity(OVRInput.GetActiveController()) + "\n";
        status += "AngAcc: " + OVRInput.GetLocalControllerAngularAcceleration(OVRInput.GetActiveController()) + "\n";
        status += "Position: " + OVRInput.GetLocalControllerPosition(OVRInput.GetActiveController()) + "\n";
        status += "Vel: " + OVRInput.GetLocalControllerVelocity(OVRInput.GetActiveController()) + "\n";
        status += "Acc: " + OVRInput.GetLocalControllerAcceleration(OVRInput.GetActiveController()) + "\n";
        status += "PrimaryTouchPad: " + OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad) + "\n";
        status += "SecondaryTouchPad: " + OVRInput.Get(OVRInput.Axis2D.SecondaryTouchpad) + "\n";

        for (int i = 0; i < monitors.Count; i++)
        {
            monitors[i].Update();
            status += monitors[i].ToString() + "\n";
        }

        if (uiText != null)
        {
            uiText.text = status;
        }
    }
    void UpdateMotion()
    {
        switch (motion_type)
        {
        case type.set_velocity_from_velocity:
            rb.velocity = OVRInput.GetLocalControllerVelocity(hand) / damper_value;
            break;

        case type.set_velocity_from_acceleration:
            rb.velocity = OVRInput.GetLocalControllerAcceleration(hand) / damper_value;     //forgive me physics
            break;

        case type.add_velocity_from_velocity:
            rb.velocity = rb.velocity + (OVRInput.GetLocalControllerVelocity(hand) / damper_value);
            break;

        case type.add_velocity_from_acceleration:
            rb.velocity += OVRInput.GetLocalControllerAcceleration(hand) / damper_value;
            break;

        case type.add_force_from_acceleration:
            rb.AddForce(OVRInput.GetLocalControllerAcceleration(hand) / damper_value);
            break;

        case type.add_force_from_velocity:
            rb.AddForce(OVRInput.GetLocalControllerVelocity(hand) / damper_value);
            break;
        }
    }
Beispiel #3
0
 // Throw object with force of controller
 public void TossObject(Rigidbody rigidBody)
 {
     if (!Application.isEditor)
     {
         rigidBody.AddForce(OVRInput.GetLocalControllerAcceleration(controller) * throwSpeed, ForceMode.Impulse);
     }
 }
Beispiel #4
0
    // Update is called once per frame
    void Update()
    {
        IsPushA             = false;
        IsPushB             = false;
        IsPushRIndexTrigger = false;
        IsPushRHandTrigger  = false;

        Ldirection = OVRInput.Get(OVRInput.RawAxis2D.LThumbstick);
        // playerCamera.transform.position += new Vector3(Ldirection.x, 0f, Ldirection.y) * speed;
        playerAvatar.transform.position += new Vector3(Ldirection.x, 0f, Ldirection.y) * speed;

        RightAccel = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);
        LeftAccel  = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);

        if (OVRInput.Get(OVRInput.RawButton.A))
        {
            IsPushA = true;
        }
        if (OVRInput.Get(OVRInput.RawButton.B))
        {
            IsPushB = true;
        }
        if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger))
        {
            IsPushRIndexTrigger = true;
        }
        if (OVRInput.Get(OVRInput.RawButton.RHandTrigger))
        {
            IsPushRHandTrigger = true;
        }
    }
Beispiel #5
0
        private void _GetHandVelocityAndAceleration(out Vector3[] velocity, out Vector3[] acceleration)
        {
            velocity     = new Vector3[2];
            acceleration = new Vector3[2];

            if (HandLeft)
            {
                velocity[(int)HandType.Left]     = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch);
                acceleration[(int)HandType.Left] = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);
            }
            else
            {
                velocity[(int)HandType.Left]     = new Vector3();
                acceleration[(int)HandType.Left] = new Vector3();
            }

            if (HandRight)
            {
                velocity[(int)HandType.Right]     = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
                acceleration[(int)HandType.Right] = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);
            }
            else
            {
                velocity[(int)HandType.Right]     = new Vector3();
                acceleration[(int)HandType.Right] = new Vector3();
            }
        }
    //Gear Controller code snippet at end of this Update() function
    void Update()
    {
        string status = ""
                        + "<b>Active: </b>" + OVRInput.GetActiveController() + "\n"
                        + "<b>Connected: </b>" + OVRInput.GetConnectedControllers() + "\n";

        status += "Orientation: " + OVRInput.GetLocalControllerRotation(OVRInput.GetActiveController()) + "\n";
        status += "AngVel: " + OVRInput.GetLocalControllerAngularVelocity(OVRInput.GetActiveController()) + "\n";
        status += "AngAcc: " + OVRInput.GetLocalControllerAngularAcceleration(OVRInput.GetActiveController()) + "\n";
        status += "Position: " + OVRInput.GetLocalControllerPosition(OVRInput.GetActiveController()) + "\n";
        status += "Vel: " + OVRInput.GetLocalControllerVelocity(OVRInput.GetActiveController()) + "\n";
        status += "Acc: " + OVRInput.GetLocalControllerAcceleration(OVRInput.GetActiveController()) + "\n";
        status += "PrimaryTouchPad: " + OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad) + "\n";
        status += "SecondaryTouchPad: " + OVRInput.Get(OVRInput.Axis2D.SecondaryTouchpad) + "\n";

        for (int i = 0; i < monitors.Count; i++)
        {
            monitors[i].Update();
            status += monitors[i].ToString() + "\n";
        }

        if (uiText != null)
        {
            uiText.text = status;
        }

        // This queries if the trigger button of the primary hand has just been released
        if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger))
        {
            //if released, shoot projectile
            shootProjectile();
        }
    }
 private void UpdateMomentums()
 {
     leftHand.UpdateMomentum(
         OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch),
         OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch),
         OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch),
         OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch));
     rightHand.UpdateMomentum(
         OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch),
         OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch),
         OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch),
         OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch));
 }
Beispiel #8
0
    /// <summary>
    /// ロストしているかもしれないチェック
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    private void CalculateMaybeTrackingLost(int index)
    {
        // HMDはロストしない
        if (index == TrackerIndex.HIP)
        {
            return;
        }

        var oldPoss = oldPositions[index];

        // 前回の値と前々回の値で計算する
        // 閾値よりも移動している場合はロストしていないとする
        float observedDistance = Vector3.Distance(oldPoss.OriginalPositionBefore, oldPoss.OriginalPositionBeforeLast);

        if (observedDistance > TrackingConst.THRESHOLD_TRACKING_LOST)
        {
            maybeTrackingLostCount[index] = Math.Max(maybeTrackingLostCount[index] - 1, 0);
            if (maybeTrackingLostCount[index] == 0)
            {
                SetTrackingLost(index, false);
            }
            return;
        }

        Vector3 acceleration = (index == TrackerIndex.RIGHT_LEG)
            ? OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch)
            : OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);

        Vector3 calcPos = oldPoss.OriginalPositionBeforeLast + acceleration * Time.deltaTime;

        // 観測した移動値と、計測した移動値が閾値以内の場合はロストしていないとする
        float calcDistance = Vector3.Distance(calcPos, oldPoss.OriginalPositionBeforeLast);

        if (Math.Abs(observedDistance - calcDistance) < TrackingConst.THRESHOLD_TRACKING_LOST_DISTANCE)
        {
            maybeTrackingLostCount[index] = Math.Max(maybeTrackingLostCount[index] - 1, 0);
            if (maybeTrackingLostCount[index] == 0)
            {
                SetTrackingLost(index, false);
            }
            return;
        }

        maybeTrackingLostCount[index] = Math.Min(maybeTrackingLostCount[index] + 1, TrackingConst.TRACKING_LOST_CONTINUES_COUNT);

        // ロストしていそう
        if (maybeTrackingLostCount[index] == TrackingConst.TRACKING_LOST_CONTINUES_COUNT)
        {
            SetTrackingLost(index, true);
        }
    }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        if (OVRInput.Get(OVRInput.Axis1D.SecondaryHandTrigger, OVRInput.Controller.Touch) > 0f)
        {
            // Debug.Log("Dpad right up");
        }
        if (OVRInput.Get(OVRInput.Button.Two))
        {
            Debug.Log("77777777777777");
        }


        //t.text = "value: " + OVRInput.Get(OVRInput.Touch.SecondaryThumbRest);
        t.text = "Acceleration : " + OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);
    }
        public override void OnUpdate()
        {
            OVRInput.Controller activeController = OVRInput.GetActiveController();

            rotation.Value = OVRInput.GetLocalControllerRotation(activeController);

            angularVelocity.Value = OVRInput.GetLocalControllerAngularVelocity(activeController);

            angularAcceleration.Value = OVRInput.GetLocalControllerAngularAcceleration(activeController);

            position.Value = OVRInput.GetLocalControllerPosition(activeController);

            velocity.Value = OVRInput.GetLocalControllerVelocity(activeController);

            acceleration.Value = OVRInput.GetLocalControllerAcceleration(activeController);
        }
Beispiel #11
0
    float GetFallingSpeed(Vector3 dir)
    {
        Vector3 contRotL = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);
        Vector3 contRotR = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);

        if (contRotL.y < -9.5f && contRotR.y < -9.5f)
        {
            fallSpeed += addSpeed;
            return(fallSpeed);
        }

        if (dir != -Vector3.up)
        {
            return(1.0f);//must move one block
        }
        return(fallSpeed);
    }
Beispiel #12
0
 // Update is called once per frame
 void Update()
 {
     if (isLeft)
     {
         acc = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);
     }
     else
     {
         acc = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);
     }
     if (drink)
     {
         float sum = Mathf.Abs(acc.x) + Mathf.Abs(acc.y) + Mathf.Abs(acc.z);
         if (sum > 1.0f)
         {
             Shakes += sum;
         }
         Shakes = Mathf.Max(100000, Shakes);
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (selectedObj != null)
     {
         try{
             Vector3 accel = OVRInput.GetLocalControllerAcceleration(controller.Controller) * ForceMultiplier;
             Accels.Enqueue(accel);
             if (Accels.Count >= MaxQueue)
             {
                 Accels.Dequeue();
             }
             Vector3   accelResult = Vector3.zero;
             float     mult        = 1;
             Vector3[] list        = new Vector3[MaxQueue];
             Accels.CopyTo(list, 0);
             //print(list.Length);
             for (int i = list.Length - 1; i >= 0; i--)
             {
                 mult = mult * 0.75f;
                 //print(list[i]);
                 accelResult += list[i] * mult;
             }
             line.SetPosition(0, selectedObj.transform.position);
             line.SetPosition(1, (selectedObj.transform.position) + accelResult);
             if (accelResult.magnitude > ForceLimit)
             {
                 print(accelResult.magnitude);
                 //selectedObj.AddForce(accelResult);
                 AccelSoma += accelResult;
                 accelCount++;
                 if (accelCount >= LaunchCount)
                 {
                     holdScript.DeselectObj();
                     selectedObj.AddForce(AccelSoma / accelCount);
                     accelCount = 0;
                     AccelSoma  = Vector3.zero;
                 }
             }
         } catch {}
     }
 }
Beispiel #14
0
        private bool isAccOver(Func <Vector3, bool> isOver)
        {
            if (Time.frameCount < ignoreAccOverFrame)
            {
                return(false);
            }

            var     controller  = OVRInput.GetActiveController();
            Vector3 accVec      = OVRInput.GetLocalControllerAcceleration(controller);
            Vector3 localAccVec = _rightHandAnchor.InverseTransformVector(accVec);

            if (isOver(localAccVec))
            {
                ignoreAccOverFrame = Time.frameCount + 30;         // 以降しばらくは無視
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #15
0
    void Update()
    {
        switch (motion_type)
        {
        case type.velocity_set:
            transform.position = OVRInput.GetLocalControllerVelocity(hand) / damper_value;
            break;

        case type.acceleration_set:
            transform.position = OVRInput.GetLocalControllerAcceleration(hand) / damper_value;
            break;

        case type.velocity_add:
            transform.position += OVRInput.GetLocalControllerVelocity(hand) / damper_value;
            break;

        case type.acceleration_add:
            transform.position += OVRInput.GetLocalControllerAcceleration(hand) / damper_value;
            break;
        }
    }
        public override void OnUpdate()
        {
            OVRInput.Controller activeController = OVRInput.GetActiveController();

            rotation.Value = OVRInput.GetLocalControllerRotation(activeController);

            x.Value = rotation.Value.x;
            y.Value = rotation.Value.y;
            z.Value = rotation.Value.z;

            position.Value = OVRInput.GetLocalControllerPosition(activeController);

            acceleration.Value = OVRInput.GetLocalControllerAcceleration(activeController);

            // Controller pointing events

            if (position.Value.y >= upLimit.Value)
            {
                Fsm.Event(pointingUp);
            }

            else if (position.Value.y <= downLimit.Value)
            {
                Fsm.Event(pointingDown);
            }

            // Controller rotation events

            if (z.Value >= minRotationLeft.Value && acceleration.Value.z <= accelerationLeft.Value)
            {
                Fsm.Event(rotatedLeft);
            }

            else if (z.Value <= minRotationRight.Value && acceleration.Value.z >= accelerationRight.Value)
            {
                Fsm.Event(rotatedRight);
            }
        }
    public void loop()
    {
#if VADR_GEARVR
        if (OVRInput.GetActiveController() == OVRInput.Controller.RTrackedRemote)
        {
            orientation                   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTrackedRemote);
            controllerPosition            = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTrackedRemote);
            controllerVelocity            = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTrackedRemote);
            controllerAcceleration        = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTrackedRemote);
            controllerAngularVelocity     = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTrackedRemote);
            controllerAngularAcceleration = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTrackedRemote);
            Infos info = new Infos(19);
            // Changing between left handed and right handed system.
            // Refer https://gamedev.stackexchange.com/questions/129204/switch-axes-and-handedness-of-a-quaternion
            info.Add("Orientation X", orientation.x);
            info.Add("Orientation Y", -1 * orientation.y);
            info.Add("Orientation Z", -1 * orientation.z);
            info.Add("Orientation W", orientation.w);
            info.Add("Position X", -1 * controllerPosition.x);
            info.Add("Position Y", controllerPosition.y);
            info.Add("Position Z", controllerPosition.z);
            info.Add("Velocity X", -1 * controllerVelocity.x);
            info.Add("Velocity Y", controllerVelocity.y);
            info.Add("Velocity Z", controllerVelocity.z);
            info.Add("Acceleration X", -1 * controllerAcceleration.x);
            info.Add("Acceleration Y", controllerAcceleration.y);
            info.Add("Acceleration Z", controllerAcceleration.z);
            info.Add("Ang Velocity X", controllerAngularVelocity.x);
            info.Add("Ang Velocity Y", -1 * controllerAngularVelocity.y);
            info.Add("Ang Velocity Z", -1 * controllerAngularVelocity.z);
            info.Add("Ang Acceleration X", controllerAngularAcceleration.x);
            info.Add("Ang Acceleration Y", -1 * controllerAngularAcceleration.y);
            info.Add("Ang Acceleration Z", -1 * controllerAngularAcceleration.z);
            VadRAnalyticsManager.RegisterEvent("vadrGearVR Controller Orientation", userCamera.transform.position, filterDictionary["RController"], info);
        }
        if (OVRInput.GetActiveController() == OVRInput.Controller.LTrackedRemote)
        {
            orientation                   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTrackedRemote);
            controllerPosition            = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTrackedRemote);
            controllerVelocity            = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTrackedRemote);
            controllerAcceleration        = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTrackedRemote);
            controllerAngularVelocity     = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTrackedRemote);
            controllerAngularAcceleration = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTrackedRemote);
            Infos info = new Infos(19);
            // Changing between left handed and right handed system.
            // Refer https://gamedev.stackexchange.com/questions/129204/switch-axes-and-handedness-of-a-quaternion
            info.Add("Orientation X", orientation.x);
            info.Add("Orientation Y", -1 * orientation.y);
            info.Add("Orientation Z", -1 * orientation.z);
            info.Add("Orientation W", orientation.w);
            info.Add("Position X", -1 * controllerPosition.x);
            info.Add("Position Y", controllerPosition.y);
            info.Add("Position Z", controllerPosition.z);
            info.Add("Velocity X", -1 * controllerVelocity.x);
            info.Add("Velocity Y", controllerVelocity.y);
            info.Add("Velocity Z", controllerVelocity.z);
            info.Add("Acceleration X", -1 * controllerAcceleration.x);
            info.Add("Acceleration Y", controllerAcceleration.y);
            info.Add("Acceleration Z", controllerAcceleration.z);
            info.Add("Ang Velocity X", controllerAngularVelocity.x);
            info.Add("Ang Velocity Y", -1 * controllerAngularVelocity.y);
            info.Add("Ang Velocity Z", -1 * controllerAngularVelocity.z);
            info.Add("Ang Acceleration X", controllerAngularAcceleration.x);
            info.Add("Ang Acceleration Y", -1 * controllerAngularAcceleration.y);
            info.Add("Ang Acceleration Z", -1 * controllerAngularAcceleration.z);
            VadRAnalyticsManager.RegisterEvent("vadrGearVR Controller Orientation", userCamera.transform.position, filterDictionary["LController"], info);
        }
#endif
    }
Beispiel #18
0
    void Update()
    {
        OVRInput.Controller activeController = OVRInput.GetActiveController();

        data.Length = 0;
        byte recenterCount = OVRInput.GetControllerRecenterCount();

        data.AppendFormat("RecenterCount: {0}\n", recenterCount);

        byte battery = OVRInput.GetControllerBatteryPercentRemaining();

        data.AppendFormat("Battery: {0}\n", battery);

        float framerate = OVRPlugin.GetAppFramerate();

        data.AppendFormat("Framerate: {0:F2}\n", framerate);

        string activeControllerName = activeController.ToString();

        data.AppendFormat("Active: {0}\n", activeControllerName);

        string connectedControllerNames = OVRInput.GetConnectedControllers().ToString();

        data.AppendFormat("Connected: {0}\n", connectedControllerNames);

        data.AppendFormat("PrevConnected: {0}\n", prevConnected);

        controllers.Update();
        controllers.AppendToStringBuilder(ref data);

        prevConnected = connectedControllerNames;

        Vector3 rot = OVRInput.GetLocalControllerRotation(activeController).eulerAngles;

        if (rot.x > 180f)
        {
            rot.x -= 360f;
        }
        if (rot.y > 180f)
        {
            rot.y -= 360f;
        }
        if (rot.z > 180f)
        {
            rot.z -= 360f;
        }

        data.AppendFormat("Orientation: ({0:F2}, {1:F2}, {2:F2})\n", rot.x, rot.y, rot.z);
        //Quaternion rot = OVRInput.GetLocalControllerRotation(activeController);
        //data.AppendFormat("Orientation: ({0:F2}, {1:F2}, {2:F2})\n", rot.x, rot.y, rot.z, rot.w);

        Vector3 angVel = OVRInput.GetLocalControllerAngularVelocity(activeController);

        data.AppendFormat("AngVel: ({0:F2}, {1:F2}, {2:F2})\n", angVel.x, angVel.y, angVel.z);

        Vector3 angAcc = OVRInput.GetLocalControllerAngularAcceleration(activeController);

        data.AppendFormat("AngAcc: ({0:F2}, {1:F2}, {2:F2})\n", angAcc.x, angAcc.y, angAcc.z);

        Vector3 pos = OVRInput.GetLocalControllerPosition(activeController);

        data.AppendFormat("Position: ({0:F2}, {1:F2}, {2:F2})\n", pos.x, pos.y, pos.z);

        Vector3 vel = OVRInput.GetLocalControllerVelocity(activeController);

        data.AppendFormat("Vel: ({0:F2}, {1:F2}, {2:F2})\n", vel.x, vel.y, vel.z);

        Vector3 acc = OVRInput.GetLocalControllerAcceleration(activeController);

        data.AppendFormat("Acc: ({0:F2}, {1:F2}, {2:F2})\n", acc.x, acc.y, acc.z);

        Vector2 primaryTouchpad = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);

        data.AppendFormat("PrimaryTouchpad: ({0:F2}, {1:F2})\n", primaryTouchpad.x, primaryTouchpad.y);

        Vector2 secondaryTouchpad = OVRInput.Get(OVRInput.Axis2D.SecondaryTouchpad);

        data.AppendFormat("SecondaryTouchpad: ({0:F2}, {1:F2})\n", secondaryTouchpad.x, secondaryTouchpad.y);

        float indexTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger);

        data.AppendFormat("PrimaryIndexTriggerAxis1D: ({0:F2})\n", indexTrigger);

        float handTrigger = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger);

        data.AppendFormat("PrimaryHandTriggerAxis1D: ({0:F2})\n", handTrigger);

        for (int i = 0; i < monitors.Count; i++)
        {
            monitors[i].Update();
            monitors[i].AppendToStringBuilder(ref data);
        }

        if (uiText != null)
        {
            uiText.text = data.ToString();
        }
    }
    // Update is called once per frame
    void Update()
    {
        //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 10f, Color.white);
        if (!holdingInteractable)
        {
            if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 50f, layerMask))
            {
                if (!hitInteractive)
                {
                    lastHit = hit.collider.gameObject;
                    hit.collider.GetComponent <Outline>().enabled = true;
                    hitInteractive = true;
                }
                if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger) || (Input.GetMouseButtonDown(0)))//(Application.isEditor && Input.GetMouseButtonDown(0))) //commented out for WebGL build
                {
                    lastHit.GetComponent <Collider>().enabled      = false;
                    lastHit.GetComponent <Rigidbody>().useGravity  = false;
                    lastHit.GetComponent <Rigidbody>().isKinematic = true;
                    lastHit.transform.parent = transform;
                    holdingInteractable      = true;
                    lastHit.GetComponent <Outline>().enabled = false;
                    hitInteractive = false;
                }
                if (OVRInput.Get(OVRInput.Button.Up) || Input.GetKey(KeyCode.W))
                {
                    lastHit.GetComponent <Collider>().enabled      = true;
                    lastHit.GetComponent <Rigidbody>().useGravity  = true;
                    lastHit.GetComponent <Rigidbody>().isKinematic = false;
                    lastHit.transform.parent = null;
                    holdingInteractable      = false;
                    lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.forward) * forceStrength);
                }

                if (OVRInput.Get(OVRInput.Button.Right) || Input.GetKey(KeyCode.D))
                {
                    lastHit.GetComponent <Collider>().enabled      = true;
                    lastHit.GetComponent <Rigidbody>().useGravity  = true;
                    lastHit.GetComponent <Rigidbody>().isKinematic = false;
                    lastHit.transform.parent = null;
                    holdingInteractable      = false;
                    lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.right) * forceStrength);
                }

                if (OVRInput.Get(OVRInput.Button.Down) || Input.GetKey(KeyCode.S))
                {
                    lastHit.GetComponent <Collider>().enabled      = true;
                    lastHit.GetComponent <Rigidbody>().useGravity  = true;
                    lastHit.GetComponent <Rigidbody>().isKinematic = false;
                    lastHit.transform.parent = null;
                    holdingInteractable      = false;
                    lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.back) * forceStrength);
                }

                if (OVRInput.Get(OVRInput.Button.Left) || Input.GetKey(KeyCode.A))
                {
                    lastHit.GetComponent <Collider>().enabled      = true;
                    lastHit.GetComponent <Rigidbody>().useGravity  = true;
                    lastHit.GetComponent <Rigidbody>().isKinematic = false;
                    lastHit.transform.parent = null;
                    holdingInteractable      = false;
                    lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.left) * forceStrength);
                }
            }
            else
            {
                hitInteractive = false;
            }
            if (lastFrameHit && !hitInteractive)
            {
                lastHit.GetComponent <Outline>().enabled = false;
            }
            lastFrameHit = hitInteractive;
        }
        else
        {
            if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger) || (Input.GetMouseButtonDown(0)))//(Application.isEditor && Input.GetMouseButtonDown(0))) //commented out for WebGL build
            {
                lastHit.GetComponent <Collider>().enabled      = true;
                lastHit.GetComponent <Rigidbody>().useGravity  = true;
                lastHit.GetComponent <Rigidbody>().isKinematic = false;
                lastHit.transform.parent = null;
                holdingInteractable      = false;
                lastHit.GetComponent <Rigidbody>().AddForce(OVRInput.GetLocalControllerAcceleration(OVRInput.GetActiveController()) * 200f);
            }

            if (OVRInput.Get(OVRInput.Button.Up) || Input.GetKey(KeyCode.W))
            {
                lastHit.GetComponent <Collider>().enabled      = true;
                lastHit.GetComponent <Rigidbody>().useGravity  = true;
                lastHit.GetComponent <Rigidbody>().isKinematic = false;
                lastHit.transform.parent = null;
                holdingInteractable      = false;
                lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.forward) * forceStrength);
            }

            if (OVRInput.Get(OVRInput.Button.Right) || Input.GetKey(KeyCode.D))
            {
                lastHit.GetComponent <Collider>().enabled      = true;
                lastHit.GetComponent <Rigidbody>().useGravity  = true;
                lastHit.GetComponent <Rigidbody>().isKinematic = false;
                lastHit.transform.parent = null;
                holdingInteractable      = false;
                lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.right) * forceStrength);
            }

            if (OVRInput.Get(OVRInput.Button.Down) || Input.GetKey(KeyCode.S))
            {
                lastHit.GetComponent <Collider>().enabled      = true;
                lastHit.GetComponent <Rigidbody>().useGravity  = true;
                lastHit.GetComponent <Rigidbody>().isKinematic = false;
                lastHit.transform.parent = null;
                holdingInteractable      = false;
                lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.back) * forceStrength);
            }

            if (OVRInput.Get(OVRInput.Button.Left) || Input.GetKey(KeyCode.A))
            {
                lastHit.GetComponent <Collider>().enabled      = true;
                lastHit.GetComponent <Rigidbody>().useGravity  = true;
                lastHit.GetComponent <Rigidbody>().isKinematic = false;
                lastHit.transform.parent = null;
                holdingInteractable      = false;
                lastHit.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.left) * forceStrength);
            }
        }
    }
Beispiel #20
0
 public override Vector3 GetAcceleration(TBInput.Controller controller)
 {
     return(OVRInput.GetLocalControllerAcceleration(GetOculusControllerID(controller)));
 }
Beispiel #21
0
 void DoGetAcceleration()
 {
     controllerAcceleration.Value = OVRInput.GetLocalControllerAcceleration(controllerInput);
 }
Beispiel #22
0
        //only called if there is a subscriber calculates values and fires off the delegate
        void deriveMotionEvents()
        {
            myMotion.lastFrameVel = myMotion.currentVel;

#if UNITY_EDITOR
            if (Input.GetKey(KeyCode.LeftAlt) && Input.GetMouseButton(0))
            {
                //camera simulation
                isController      = false;
                isCamera          = true;
                currentMousePos.x = Input.mousePosition.x;
                currentMousePos.y = -Input.mousePosition.y;
                if (lastFrameMousePos != EasyInputConstants.NOT_TOUCHING)
                {
                    delta = currentMousePos - lastFrameMousePos;
                }
                else
                {
                    delta = EasyInputConstants.NOT_TOUCHING;
                }
            }
            //motion simulation
            else if (Input.GetKey(KeyCode.LeftControl) && Input.GetMouseButton(0))
            {
                //motion simulation
                isController      = true;
                isCamera          = false;
                currentMousePos.x = Input.mousePosition.x;
                currentMousePos.y = -Input.mousePosition.y;
                if (lastFrameMousePos != EasyInputConstants.NOT_TOUCHING)
                {
                    delta = currentMousePos - lastFrameMousePos;
                }
                else
                {
                    delta = EasyInputConstants.NOT_TOUCHING;
                }
            }
            else
            {
                isController    = false;
                isCamera        = false;
                currentMousePos = EasyInputConstants.NOT_TOUCHING;
                delta           = EasyInputConstants.NOT_TOUCHING;
            }

            if (delta != EasyInputConstants.NOT_TOUCHING && delta != Vector2.zero)
            {
                OrientationDelta.z = 0f;
                OrientationDelta.y = delta.x;
                OrientationDelta.x = delta.y;
            }
            else
            {
                OrientationDelta = Vector3.zero;
            }

            if (isCamera)
            {
                Camera.main.transform.localEulerAngles += OrientationDelta;
            }

            if (isController)
            {
                myMotion.currentOrientationEuler += OrientationDelta;
                myMotion.currentOrientation       = Quaternion.Euler(myMotion.currentOrientationEuler);
            }


            myMotion.currentPos = new Vector3(.5f, -.2f, .5f);

            myMotion.currentOrientationEuler = myMotion.currentOrientation.eulerAngles;
            myMotion.currentAngVel           = Vector3.zero;
            myMotion.currentAcc = Vector3.zero;

            lastFrameMousePos = currentMousePos;
#endif

#if !UNITY_EDITOR && UNITY_ANDROID
            //real data
            if (isGearVR)
            {
                myMotion.currentOrientation      = OVRInput.GetLocalControllerRotation(OVRInput.GetActiveController());
                myMotion.currentOrientationEuler = myMotion.currentOrientation.eulerAngles;
                myMotion.currentAngVel           = OVRInput.GetLocalControllerAngularVelocity(OVRInput.GetActiveController());
                myMotion.currentPos = OVRInput.GetLocalControllerPosition(OVRInput.GetActiveController());
                myMotion.currentAcc = OVRInput.GetLocalControllerAcceleration(OVRInput.GetActiveController());
            }
#endif

            //derived data section

            //filter out noisy accel values that are close to zero
            temp   = myMotion.currentAcc;
            temp.x = (temp.x <= .15f && temp.x >= -.2f) ? 0f : temp.x;
            temp.y = (temp.y <= .3f && temp.y >= -.35f) ? 0f : temp.y;
            temp.z = (temp.z <= .15f && temp.z >= -.2f) ? 0f : temp.z;

            //another filter for the largest of magnitudes which is usually the stop of a motion
            temp.x = (temp.x >= 5f) ? 0f : temp.x;
            temp.y = (temp.y >= 5f) ? 0f : temp.y;
            temp.z = (temp.z >= 5f) ? 0f : temp.z;

            myMotion.currentVel = (temp * Time.deltaTime) + myMotion.lastFrameVel;

            //can still have propogated velocity that we need to filter out
            framesVelocitySameX = (myMotion.currentVel.x == myMotion.lastFrameVel.x) ? (framesVelocitySameX + 1) : 0;
            framesVelocitySameY = (myMotion.currentVel.y == myMotion.lastFrameVel.y) ? (framesVelocitySameY + 1) : 0;
            framesVelocitySameZ = (myMotion.currentVel.z == myMotion.lastFrameVel.z) ? (framesVelocitySameZ + 1) : 0;



            if (framesVelocitySameX >= 2)
            {
                myMotion.lastFrameVel.x = 0f;
                myMotion.currentVel.x   = 0f;
                framesVelocitySameX     = 0;
            }
            if (framesVelocitySameY >= 2)
            {
                myMotion.lastFrameVel.y = 0f;
                myMotion.currentVel.y   = 0f;
                framesVelocitySameY     = 0;
            }
            if (framesVelocitySameZ >= 2)
            {
                myMotion.lastFrameVel.z = 0f;
                myMotion.currentVel.z   = 0f;
                framesVelocitySameZ     = 0;
            }


            myMotion.posSinceLastReset             += (myMotion.currentVel * Time.deltaTime);
            myMotion.totalVelSinceLastReset        += myMotion.currentVel;
            myMotion.totalAngularVelSinceLastReset += myMotion.currentAngVel;

            //fire off the delegate
            if (On_Motion != null)
            {
                On_Motion(myMotion);
            }
        }
    private void Update()
    {
        OVRInput.Controller activeController = OVRInput.GetActiveController();
        this.data.Length = 0;
        byte controllerRecenterCount = OVRInput.GetControllerRecenterCount(OVRInput.Controller.Active);

        this.data.AppendFormat("RecenterCount: {0}\n", controllerRecenterCount);
        byte controllerBatteryPercentRemaining = OVRInput.GetControllerBatteryPercentRemaining(OVRInput.Controller.Active);

        this.data.AppendFormat("Battery: {0}\n", controllerBatteryPercentRemaining);
        float appFramerate = OVRPlugin.GetAppFramerate();

        this.data.AppendFormat("Framerate: {0:F2}\n", appFramerate);
        string arg = activeController.ToString();

        this.data.AppendFormat("Active: {0}\n", arg);
        string arg2 = OVRInput.GetConnectedControllers().ToString();

        this.data.AppendFormat("Connected: {0}\n", arg2);
        this.data.AppendFormat("PrevConnected: {0}\n", OVRGearVrControllerTest.prevConnected);
        OVRGearVrControllerTest.controllers.Update();
        OVRGearVrControllerTest.controllers.AppendToStringBuilder(ref this.data);
        OVRGearVrControllerTest.prevConnected = arg2;
        Quaternion localControllerRotation = OVRInput.GetLocalControllerRotation(activeController);

        this.data.AppendFormat("Orientation: ({0:F2}, {1:F2}, {2:F2}, {3:F2})\n", new object[]
        {
            localControllerRotation.x,
            localControllerRotation.y,
            localControllerRotation.z,
            localControllerRotation.w
        });
        Vector3 localControllerAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(activeController);

        this.data.AppendFormat("AngVel: ({0:F2}, {1:F2}, {2:F2})\n", localControllerAngularVelocity.x, localControllerAngularVelocity.y, localControllerAngularVelocity.z);
        Vector3 localControllerAngularAcceleration = OVRInput.GetLocalControllerAngularAcceleration(activeController);

        this.data.AppendFormat("AngAcc: ({0:F2}, {1:F2}, {2:F2})\n", localControllerAngularAcceleration.x, localControllerAngularAcceleration.y, localControllerAngularAcceleration.z);
        Vector3 localControllerPosition = OVRInput.GetLocalControllerPosition(activeController);

        this.data.AppendFormat("Position: ({0:F2}, {1:F2}, {2:F2})\n", localControllerPosition.x, localControllerPosition.y, localControllerPosition.z);
        Vector3 localControllerVelocity = OVRInput.GetLocalControllerVelocity(activeController);

        this.data.AppendFormat("Vel: ({0:F2}, {1:F2}, {2:F2})\n", localControllerVelocity.x, localControllerVelocity.y, localControllerVelocity.z);
        Vector3 localControllerAcceleration = OVRInput.GetLocalControllerAcceleration(activeController);

        this.data.AppendFormat("Acc: ({0:F2}, {1:F2}, {2:F2})\n", localControllerAcceleration.x, localControllerAcceleration.y, localControllerAcceleration.z);
        Vector2 vector = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad, OVRInput.Controller.Active);

        this.data.AppendFormat("PrimaryTouchpad: ({0:F2}, {1:F2})\n", vector.x, vector.y);
        Vector2 vector2 = OVRInput.Get(OVRInput.Axis2D.SecondaryTouchpad, OVRInput.Controller.Active);

        this.data.AppendFormat("SecondaryTouchpad: ({0:F2}, {1:F2})\n", vector2.x, vector2.y);
        float num = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.Active);

        this.data.AppendFormat("PrimaryIndexTriggerAxis1D: ({0:F2})\n", num);
        float num2 = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.Active);

        this.data.AppendFormat("PrimaryHandTriggerAxis1D: ({0:F2})\n", num2);
        for (int i = 0; i < this.monitors.Count; i++)
        {
            this.monitors[i].Update();
            this.monitors[i].AppendToStringBuilder(ref this.data);
        }
        if (this.uiText != null)
        {
            this.uiText.text = this.data.ToString();
        }
    }
Beispiel #24
0
    void AddData()
    {
        RightP_X = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch).x.ToString();
        RightP_Y = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch).y.ToString();
        RightP_Z = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch).z.ToString();

        RightR_W = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).w.ToString();
        RightR_X = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).x.ToString();
        RightR_Y = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).y.ToString();
        RightR_Z = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).z.ToString();


        LeftP_X = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch).x.ToString();
        LeftP_Y = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch).y.ToString();
        LeftP_Z = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch).z.ToString();

        LeftR_W = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).w.ToString();
        LeftR_X = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).x.ToString();
        LeftR_Y = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).y.ToString();
        LeftR_Z = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch).z.ToString();


        playerpos_X = Camera.main.gameObject.transform.position.x.ToString();
        playerpos_Y = Camera.main.gameObject.transform.position.y.ToString();
        playerpos_Z = Camera.main.gameObject.transform.position.z.ToString();


        playerrot_W = Camera.main.gameObject.transform.rotation.w.ToString();
        playerrot_X = Camera.main.gameObject.transform.rotation.x.ToString();
        playerrot_Y = Camera.main.gameObject.transform.rotation.y.ToString();
        playerrot_Z = Camera.main.gameObject.transform.rotation.z.ToString();

        Raccel_X = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).x.ToString();
        Raccel_Y = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).y.ToString();
        Raccel_Z = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).z.ToString();

        Laccel_X = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch).x.ToString();
        Laccel_Y = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch).y.ToString();
        Laccel_Z = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch).z.ToString();

        Cam_pos_X = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye).x.ToString();
        Cam_pos_Y = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye).y.ToString();
        Cam_pos_Z = UnityEngine.XR.InputTracking.GetLocalPosition(UnityEngine.XR.XRNode.CenterEye).z.ToString();

        Cam_rot_X = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).x.ToString();
        Cam_rot_Y = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).y.ToString();
        Cam_rot_Z = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).z.ToString();
        Cam_rot_W = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye).w.ToString();

        Raaccel_X = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch).x.ToString();
        Raaccel_Y = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch).y.ToString();
        Raaccel_Z = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch).z.ToString();

        Laaccel_X = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch).x.ToString();
        Laaccel_Y = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch).y.ToString();
        Laaccel_Z = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch).z.ToString();

        Rvel_X = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).x.ToString();
        Rvel_Y = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).y.ToString();
        Rvel_Z = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).z.ToString();

        Lvel_X = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).x.ToString();
        Lvel_Y = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).y.ToString();
        Lvel_Z = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).z.ToString();

        Ravel_X = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).x.ToString();
        Ravel_Y = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).y.ToString();
        Ravel_Z = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).z.ToString();

        Lavel_X = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).x.ToString();
        Lavel_Y = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).y.ToString();
        Lavel_Z = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).z.ToString();

        PrimaryHandTrigger   = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.LTouch).ToString();
        SecondaryHandTrigger = OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch).ToString();



        string[]        rowDataTemp = new string[55];
        List <string[]> rowData1    = new List <string[]>();

        // You can add up the values in as many cells as you want.

        rowDataTemp    = new string[55];
        rowDataTemp[0] = Time.frameCount.ToString();
        rowDataTemp[1] = RightP_X;
        rowDataTemp[2] = RightP_Y;
        rowDataTemp[3] = RightP_Z;

        rowDataTemp[4] = RightR_W;
        rowDataTemp[5] = RightR_X;
        rowDataTemp[6] = RightR_Y;
        rowDataTemp[7] = RightR_Z;

        rowDataTemp[8]  = LeftP_X;
        rowDataTemp[9]  = LeftP_Y;
        rowDataTemp[10] = LeftP_Z;

        rowDataTemp[11] = LeftR_W;
        rowDataTemp[12] = LeftR_X;
        rowDataTemp[13] = LeftR_Y;
        rowDataTemp[14] = LeftR_X;

        rowDataTemp[15] = playerpos_X;
        rowDataTemp[16] = playerpos_Y;
        rowDataTemp[17] = playerpos_Z;

        rowDataTemp[18] = playerrot_W;
        rowDataTemp[19] = playerrot_X;
        rowDataTemp[20] = playerrot_Y;
        rowDataTemp[21] = playerrot_Z;

        rowDataTemp[22] = Raccel_X;
        rowDataTemp[23] = Raccel_Y;
        rowDataTemp[24] = Raccel_Z;

        rowDataTemp[25] = Laccel_X;
        rowDataTemp[26] = Laccel_Y;
        rowDataTemp[27] = Laccel_Z;

        rowDataTemp[28] = Cam_pos_X;
        rowDataTemp[29] = Cam_pos_Y;
        rowDataTemp[30] = Cam_pos_Z;

        rowDataTemp[31] = Cam_rot_W;
        rowDataTemp[32] = Cam_rot_X;
        rowDataTemp[33] = Cam_rot_Y;
        rowDataTemp[34] = Cam_rot_Z;

        rowDataTemp[35] = Raaccel_X;
        rowDataTemp[36] = Raaccel_X;
        rowDataTemp[37] = Raaccel_X;

        rowDataTemp[38] = Laaccel_X;
        rowDataTemp[39] = Laaccel_Y;
        rowDataTemp[40] = Laaccel_Z;

        rowDataTemp[41] = Rvel_X;
        rowDataTemp[42] = Rvel_X;
        rowDataTemp[43] = Rvel_X;

        rowDataTemp[44] = Lvel_X;
        rowDataTemp[45] = Lvel_Y;
        rowDataTemp[46] = Lvel_Z;

        rowDataTemp[47] = Ravel_X;
        rowDataTemp[48] = Ravel_X;
        rowDataTemp[49] = Ravel_X;

        rowDataTemp[50] = Lavel_X;
        rowDataTemp[51] = Lavel_Y;
        rowDataTemp[52] = Lavel_Z;

        rowDataTemp[53] = PrimaryHandTrigger;
        rowDataTemp[54] = SecondaryHandTrigger;



        rowData1.Add(rowDataTemp);

        string[][] output = new string[rowData.Count][];

        for (int i = 0; i < output.Length; i++)
        {
            output[i] = rowData1[i];
        }

        int    length    = output.GetLength(0);
        string delimiter = ",";

        StringBuilder sb1 = new StringBuilder();

        for (int index = 0; index < length; index++)
        {
            sb1.AppendLine(string.Join(delimiter, output[index]));
        }


        StreamWriter outStream = File.AppendText(filePath + fileName);

        outStream.Write(sb1);
        outStream.Close();
    }
Beispiel #25
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.M))
        {
            _active = !_active;
        }

        _left.Position              = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
        _right.Position             = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
        _left.AngularVelocity       = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch);
        _right.LinearVelocity       = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
        _left.LinearAccelleration   = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);
        _right.AngularAccelleration = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);

        _left.Rotation              = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
        _right.Rotation             = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);
        _left.AngularVelocity       = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch);
        _right.AngularVelocity      = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch);
        _left.AngularAccelleration  = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch);
        _right.AngularAccelleration = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch);

        var indexL = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch);
        var indexR = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.RTouch);

        float x = 0f;
        float y = 0f;

        // Shift look up and down by linearly moving controller
        // Todo: linear, but seen from which perspective? Hands and arms trace arcs. Use that.
        x += _right.LinearVelocity.x * (0.5f + 0.5f * indexR) * 100f;
        y += _right.LinearVelocity.y * (0.5f + 0.5f * indexR) * -100f;

        // Shift look by rotating
        x += _right.AngularVelocity.y * (0.5f + 0.5f * indexR) * 13f;
        y += _right.AngularVelocity.x * (0.5f + 0.5f * indexR) * 13f;

        // Push look by rotating
        float angleX = AngleAroundAxis(_right.Rotation * Vector3.forward, Vector3.forward, Vector3.up);
        float angleY = AngleAroundAxis(_right.Rotation * Vector3.forward, Vector3.forward, Vector3.right);

        x += (Mathf.Sign(angleX) * Mathf.Pow(Mathf.Min(Mathf.Abs(angleX) / 75f, 1f), 2f)) * -120f;
        y += (Mathf.Sign(angleY) * Mathf.Pow(Mathf.Min(Mathf.Abs(angleY) / 75f, 1f), 2f)) * -120f;

        if (_active)
        {
            // Look
            SimMouse.ActRaw(SimMouse.Action.MoveOnly, Mathf.RoundToInt(x), Mathf.RoundToInt(y));

            //Vector2 moveAnalog = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch);

            // Shoot
            HandleKey(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.RTouch, DirectInput.ScanCode.H);

            // Move
            HandleKey(OVRInput.Button.Up, OVRInput.Controller.LTouch, DirectInput.ScanCode.W);
            HandleKey(OVRInput.Button.Down, OVRInput.Controller.LTouch, DirectInput.ScanCode.S);
            HandleKey(OVRInput.Button.Left, OVRInput.Controller.LTouch, DirectInput.ScanCode.A);
            HandleKey(OVRInput.Button.Right, OVRInput.Controller.LTouch, DirectInput.ScanCode.D);

            HandleKey(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.LTouch, DirectInput.ScanCode.Space);
            HandleKey(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.LTouch, DirectInput.ScanCode.LControl);

            // Switch weapons
            HandleKey(OVRInput.Button.Left, OVRInput.Controller.RTouch, DirectInput.ScanCode.Q);
            HandleKey(OVRInput.Button.Right, OVRInput.Controller.RTouch, DirectInput.ScanCode.E);
            HandleKey(OVRInput.Button.One, OVRInput.Controller.RTouch, DirectInput.ScanCode.R);
            HandleKey(OVRInput.Button.Up, OVRInput.Controller.RTouch, DirectInput.ScanCode.Two);
            HandleKey(OVRInput.Button.Down, OVRInput.Controller.RTouch, DirectInput.ScanCode.Three);
            HandleKey(OVRInput.Button.PrimaryThumbstick, OVRInput.Controller.RTouch, DirectInput.ScanCode.One);

            // Zoom
            HandleKey(OVRInput.Button.PrimaryHandTrigger, OVRInput.Controller.RTouch, DirectInput.ScanCode.J);
        }
    }
Beispiel #26
0
    void Update()
    {
        OVRInput.Controller activeController = OVRInput.GetActiveController();

        data.Length = 0;

        float framerate = OVRPlugin.GetAppFramerate();

        data.AppendFormat("Framerate: {0:F2}\n", framerate);

        string activeControllerName = activeController.ToString();

        data.AppendFormat("Active: {0}\n", activeControllerName);

        string connectedControllerNames = OVRInput.GetConnectedControllers().ToString();

        data.AppendFormat("Connected: {0}\n", connectedControllerNames);

        Quaternion rot = OVRInput.GetLocalControllerRotation(activeController);

        data.AppendFormat("Orientation: ({0:F2}, {1:F2}, {2:F2}, {3:F2})\n", rot.x, rot.y, rot.z, rot.w);

        Vector3 angVel = OVRInput.GetLocalControllerAngularVelocity(activeController);

        data.AppendFormat("AngVel: ({0:F2}, {1:F2}, {2:F2})\n", angVel.x, angVel.y, angVel.z);

        Vector3 angAcc = OVRInput.GetLocalControllerAngularAcceleration(activeController);

        data.AppendFormat("AngAcc: ({0:F2}, {1:F2}, {2:F2})\n", angAcc.x, angAcc.y, angAcc.z);

        Vector3 pos = OVRInput.GetLocalControllerPosition(activeController);

        data.AppendFormat("Position: ({0:F2}, {1:F2}, {2:F2})\n", pos.x, pos.y, pos.z);

        Vector3 vel = OVRInput.GetLocalControllerVelocity(activeController);

        data.AppendFormat("Vel: ({0:F2}, {1:F2}, {2:F2})\n", vel.x, vel.y, vel.z);

        Vector3 acc = OVRInput.GetLocalControllerAcceleration(activeController);

        data.AppendFormat("Acc: ({0:F2}, {1:F2}, {2:F2})\n", acc.x, acc.y, acc.z);

        Vector2 primaryTouchpad = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);

        data.AppendFormat("PrimaryTouchpad: ({0:F2}, {1:F2})\n", primaryTouchpad.x, primaryTouchpad.y);

        Vector2 secondaryTouchpad = OVRInput.Get(OVRInput.Axis2D.SecondaryTouchpad);

        data.AppendFormat("SecondaryTouchpad: ({0:F2}, {1:F2})\n", secondaryTouchpad.x, secondaryTouchpad.y);

        for (int i = 0; i < monitors.Count; i++)
        {
            monitors[i].Update();
            monitors[i].AppendToStringBuilder(ref data);
        }

        if (uiText != null)
        {
            uiText.text = data.ToString();
        }
    }
Beispiel #27
0
    // Update is called once per frame
    void Update()
    {
        OVRInput.Update();
        float lTriggerVal = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch);

        //if (OVRInput.GetDown(OVRInput.Button.One))
        //if(OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, OVRInput.Controller.LTouch) == 1.0f);
        Debug.Log(_selectorScript.instSelection);
        if (lTriggerVal > 0.5f)
        {
            UnityEngine.XR.InputTracking.Recenter();
        }
        timer += Time.deltaTime;
        double keyTime = AudioSettings.dspTime - _inputDelay;

        if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickRight, OVRInput.Controller.LTouch))
        {
            switch (_selectorScript.instSelection)
            {
            case 0: _selectorScript.instSelection = 2; break;

            case 1: _selectorScript.instSelection = 4; break;

            case 2: _selectorScript.instSelection = 1; break;

            case 3: _selectorScript.instSelection = 0; break;

            case 4: _selectorScript.instSelection = 3; break;

            default: _selectorScript.instSelection = 3; break;
            }
            _selectorScript.MoveSelector(_selectorScript.instSelection);
        }
        else if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickLeft, OVRInput.Controller.LTouch))
        {
            switch (_selectorScript.instSelection)
            {
            case 0: _selectorScript.instSelection = 3; break;

            case 1: _selectorScript.instSelection = 2; break;

            case 2: _selectorScript.instSelection = 0; break;

            case 3: _selectorScript.instSelection = 4; break;

            case 4: _selectorScript.instSelection = 1; break;

            default: _selectorScript.instSelection = 3; break;
            }
            _selectorScript.MoveSelector(_selectorScript.instSelection);
        }

        // Display/hide ui element
        //beatObject.SetActive(KeyTimeGoodEnough(keyTime));

        /*if ( Input.GetKeyDown(KeyCode.Space) )
         * {
         *  if (KeyTimeGoodEnough( keyTime ))
         *      _gameScore++;
         *  else
         *      _gameScore--;
         * }*/

        //Debug.Log(timer);

        /*
         * Timer events for requiring music to be adjusted
         */

        // 15 second mark
        if (timer >= 15f && timer <= 15f + 0.2f)
        {
            pianoMusic.volume        = 0.8f;
            pianoVisualizer.volscale = 8f;
            pianoVisualizerObj.SetActive(true);
        }

        // 30 second mark
        if (timer >= 30f && timer <= 30f + 0.2f)
        {
            trumpetMusic.volume        = 0.8f;
            trumpetVisualizer.volscale = 8f;
            trumpetVisualizerObj.SetActive(true);
        }

        // 45 second mark
        if (timer >= 45f && timer <= 45f + 0.2f)
        {
            violinMusic.volume        = 0.8f;
            violinVisualizer.volscale = 8f;
            violinVisualizerObj.SetActive(true);
        }

        // 1 minute mark
        if (timer >= 15f * 4 && timer <= 15f * 4 + 0.2f)
        {
            drumMusic.volume        = 0.8f;
            drumVisualizer.volscale = 8f;
            drumVisualizerObj.SetActive(true);
        }

        // 1 minute 15 second mark
        if (timer >= 15f * 5 && timer <= 15f * 5 + 0.2f)
        {
            harpMusic.volume        = 0.3f;
            harpVisualizer.volscale = 3f;
            harpVisualizerObj.SetActive(true);
        }

        // 1 minute 30 second mark
        if (timer >= 15f * 6 && timer <= 15f * 6 + 0.2f)
        {
            trumpetMusic.volume        = 1.0f;
            trumpetVisualizer.volscale = 10f;
            trumpetVisualizerObj.SetActive(true);
        }

        // 1 minute 45 second mark
        if (timer >= 15f * 7 && timer <= 15f * 7 + 0.2f)
        {
            violinMusic.volume        = 0.6f;
            violinVisualizer.volscale = 6f;
            violinVisualizerObj.SetActive(true);
        }

        // 2 minute 0 second mark
        if (timer >= 15f * 8 && timer <= 15f * 8 + 0.2f)
        {
            trumpetMusic.volume        = 0.3f;
            trumpetVisualizer.volscale = 3f;
            trumpetVisualizerObj.SetActive(true);
        }

        // 2 minute 15 second mark
        if (timer >= 15f * 9 && timer <= 15f * 9 + 0.2f)
        {
            harpMusic.volume        = 0.8f;
            harpVisualizer.volscale = 8f;
            harpVisualizerObj.SetActive(true);
        }

        // 2 minute 30 second mark
        if (timer >= 15f * 10 && timer <= 15f * 10 + 0.2f)
        {
            drumMusic.volume        = 0.1f;
            drumVisualizer.volscale = 1f;
            drumVisualizerObj.SetActive(true);
        }

        // 2 minute 45 second mark
        if (timer >= 15f * 11 && timer <= 15f * 11 + 0.2f)
        {
            violinMusic.volume        = 0.7f;
            violinVisualizer.volscale = 7f;
            violinVisualizerObj.SetActive(true);
        }

        // 3 minute 0 second mark
        if (timer >= 15f * 12 && timer <= 15f * 12 + 0.2f)
        {
            trumpetMusic.volume        = 0.3f;
            trumpetVisualizer.volscale = 3f;
            trumpetVisualizerObj.SetActive(true);
        }

        // 3 minute 15 second mark
        if (timer >= 15f * 13 && timer <= 15f * 13 + 0.2f)
        {
            harpMusic.volume        = 0.9f;
            harpVisualizer.volscale = 9f;
            harpVisualizerObj.SetActive(true);
        }

        // 3 minute 30 second mark
        if (timer >= 15f * 14 && timer <= 15f * 14 + 0.2f)
        {
            drumMusic.volume        = 0.8f;
            drumVisualizer.volscale = 8f;
            drumVisualizerObj.SetActive(true);
        }

        // 3 minute 45 second mark
        if (timer >= 15f * 15 && timer <= 15f * 15 + 0.2f)
        {
            trumpetMusic.volume        = 0.2f;
            trumpetVisualizer.volscale = 2f;
            trumpetVisualizerObj.SetActive(true);
        }

        // 4 minute 0 second mark
        if (timer >= 15f * 16 && timer <= 15f * 16 + 0.2f)
        {
            violinMusic.volume        = 0.8f;
            violinVisualizer.volscale = 8f;
            violinVisualizerObj.SetActive(true);
        }

        // 4 minute 15 second mark
        if (timer >= 15f * 17 && timer <= 15f * 17 + 0.2f)
        {
            drumMusic.volume        = 0.8f;
            drumVisualizer.volscale = 8f;
            drumVisualizerObj.SetActive(true);
        }

        // Decrease volume with downward swipe
        if (OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.RTouch) && OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).y > 4)
        {
            switch (_selectorScript.instSelection)
            {
            case 3:
                if (trumpetMusic.volume > 0.5f)
                {
                    trumpetMusic.volume        = 0.5f;
                    trumpetVisualizer.volscale = 5f;
                    trumpetVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 0:
                if (drumMusic.volume > 0.5f)
                {
                    drumMusic.volume        = 0.5f;
                    drumVisualizer.volscale = 5f;
                    drumVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 2:
                if (pianoMusic.volume > 0.5f)
                {
                    pianoMusic.volume        = 0.5f;
                    pianoVisualizer.volscale = 5f;
                    pianoVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 1:
                if (harpMusic.volume > 0.5f)
                {
                    harpMusic.volume        = 0.5f;
                    harpVisualizer.volscale = 5f;
                    harpVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 4:
                if (violinMusic.volume > 0.5f)
                {
                    violinMusic.volume        = 0.5f;
                    violinVisualizer.volscale = 5f;
                    violinVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;
            }
        }

        // Increase volume with upward swipe
        if (OVRInput.Get(OVRInput.Button.One, OVRInput.Controller.RTouch) && OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch).y < -4)
        {
            switch (_selectorScript.instSelection)
            {
            case 3:
                if (trumpetMusic.volume < 0.5f)
                {
                    trumpetMusic.volume        = 0.5f;
                    trumpetVisualizer.volscale = 5f;
                    trumpetVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 0:
                if (drumMusic.volume < 0.5f)
                {
                    drumMusic.volume        = 0.5f;
                    drumVisualizer.volscale = 5f;
                    drumVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 2:
                if (pianoMusic.volume < 0.5f)
                {
                    pianoMusic.volume        = 0.5f;
                    pianoVisualizer.volscale = 5f;
                    pianoVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 1:
                if (harpMusic.volume < 0.5f)
                {
                    harpMusic.volume        = 0.5f;
                    harpVisualizer.volscale = 5f;
                    harpVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;

            case 4:
                if (violinMusic.volume < 0.5f)
                {
                    violinMusic.volume        = 0.5f;
                    violinVisualizer.volscale = 5f;
                    violinVisualizerObj.SetActive(false);
                    _gameScore += 100;
                }
                break;
            }
        }
        scoreObject.text = "Score: " + _gameScore;
    }
Beispiel #28
0
    public void loop()
    {
#if VADR_RIFT
        Infos info       = new Infos(38);
        bool  activeFlag = false;
        if (OVRInput.GetActiveController() == OVRInput.Controller.RTouch || OVRInput.GetActiveController() == OVRInput.Controller.Touch)
        {
            activeFlag                     = true;
            rOrientation                   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);
            rControllerPosition            = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
            rControllerVelocity            = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch);
            rControllerAcceleration        = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.RTouch);
            rControllerAngularVelocity     = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch);
            rControllerAngularAcceleration = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.RTouch);
            // Changing between left handed and right handed system.
            // Refer https://gamedev.stackexchange.com/questions/129204/switch-axes-and-handedness-of-a-quaternion
            info.Add("Right Orientation X", rOrientation.x);
            info.Add("Right Orientation Y", -1 * rOrientation.y);
            info.Add("Right Orientation Z", -1 * rOrientation.z);
            info.Add("Right Orientation W", rOrientation.w);
            info.Add("Right Position X", -1 * rControllerPosition.x);
            info.Add("Right Position Y", rControllerPosition.y);
            info.Add("Right Position Z", rControllerPosition.z);
            info.Add("Right Velocity X", -1 * rControllerVelocity.x);
            info.Add("Right Velocity Y", rControllerVelocity.y);
            info.Add("Right Velocity Z", rControllerVelocity.z);
            info.Add("Right Acceleration X", -1 * rControllerAcceleration.x);
            info.Add("Right Acceleration Y", rControllerAcceleration.y);
            info.Add("Right Acceleration Z", rControllerAcceleration.z);
            info.Add("Right Ang Velocity X", rControllerAngularVelocity.x);
            info.Add("Right Ang Velocity Y", -1 * rControllerAngularVelocity.y);
            info.Add("Right Ang Velocity Z", -1 * rControllerAngularVelocity.z);
            info.Add("Right Ang Acceleration X", rControllerAngularAcceleration.x);
            info.Add("Right Ang Acceleration Y", -1 * rControllerAngularAcceleration.y);
            info.Add("Right Ang Acceleration Z", -1 * rControllerAngularAcceleration.z);
        }
        if (OVRInput.GetActiveController() == OVRInput.Controller.LTouch || OVRInput.GetActiveController() == OVRInput.Controller.Touch)
        {
            activeFlag                     = true;
            lOrientation                   = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
            lControllerPosition            = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
            lControllerVelocity            = OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch);
            lControllerAcceleration        = OVRInput.GetLocalControllerAcceleration(OVRInput.Controller.LTouch);
            lControllerAngularVelocity     = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch);
            lControllerAngularAcceleration = OVRInput.GetLocalControllerAngularAcceleration(OVRInput.Controller.LTouch);
            // Changing between left handed and right handed system.
            // Refer https://gamedev.stackexchange.com/questions/129204/switch-axes-and-handedness-of-a-quaternion
            info.Add("Left Orientation X", lOrientation.x);
            info.Add("Left Orientation Y", -1 * lOrientation.y);
            info.Add("Left Orientation Z", -1 * lOrientation.z);
            info.Add("Left Orientation W", lOrientation.w);
            info.Add("Left Position X", -1 * lControllerPosition.x);
            info.Add("Left Position Y", lControllerPosition.y);
            info.Add("Left Position Z", lControllerPosition.z);
            info.Add("Left Velocity X", -1 * lControllerVelocity.x);
            info.Add("Left Velocity Y", lControllerVelocity.y);
            info.Add("Left Velocity Z", lControllerVelocity.z);
            info.Add("Left Acceleration X", -1 * lControllerAcceleration.x);
            info.Add("Left Acceleration Y", lControllerAcceleration.y);
            info.Add("Left Acceleration Z", lControllerAcceleration.z);
            info.Add("Left Ang Velocity X", lControllerAngularVelocity.x);
            info.Add("Left Ang Velocity Y", -1 * lControllerAngularVelocity.y);
            info.Add("Left Ang Velocity Z", -1 * lControllerAngularVelocity.z);
            info.Add("Left Ang Acceleration X", lControllerAngularAcceleration.x);
            info.Add("Left Ang Acceleration Y", -1 * lControllerAngularAcceleration.y);
            info.Add("Left Ang Acceleration Z", -1 * lControllerAngularAcceleration.z);
        }
        if (activeFlag)
        {
            VadRAnalyticsManager.RegisterEvent("vadrRift Controller Orientation", userCamera.transform.position, info);
        }
#endif
    }