GetLocalControllerAngularVelocity() public static method

Gets the angular velocity of the given Controller local to its tracking space. Only supported for Oculus LTouch and RTouch controllers. Non-tracked controllers will return Quaternion.identity.
public static GetLocalControllerAngularVelocity ( OVRInput, controllerType ) : Quaternion
controllerType OVRInput,
return Quaternion
Esempio n. 1
0
    void OnCollisionEnter(Collision collision)
    {
        Debug.Log("collided -----------------------");

        Rigidbody actorRidgedBody = GetComponent <Rigidbody>();

        if (actorRidgedBody == null)
        {
            throw new System.NullReferenceException("The actor does not have a rigidBody attached!");
        }

        float punchPower = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTrackedRemote).magnitude;
        //Vector3 punchDirection = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTrackedRemote).normalized;
        Vector3 punchDirection = avatar.transform.forward;

        Debug.Log("punchPower" + punchPower);
        Debug.Log("punchDirection" + punchPower);

        Rigidbody targetRidgedBody = collision.gameObject.GetComponent <Rigidbody>();

        Debug.Log("target " + collision.gameObject);
        if (targetRidgedBody != null)
        {
            if (punchPower > minthreashold)
            {
                Debug.Log("Punched");
                targetRidgedBody.velocity += punchDirection * Mathf.Min((punchPower * punchMagnifier), maxPunchPower);

                BreakMovingObject breakableObject = collision.gameObject.GetComponent <BreakMovingObject>();
                breakableObject.SetLaucherForThisObject(gameObject);
            }
        }
        else
        {
            throw new System.NullReferenceException("The target does not have a rigidBody attached! " + collision.gameObject);
        }
        Debug.Log("done -----------------------");
    }
Esempio n. 2
0
    protected void GrabEnd()
    {
        if (m_grabbedObj != null)
        {
            OVRPose localPose = new OVRPose {
                position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
            };
            OVRPose offsetPose = new OVRPose {
                position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation
            };
            localPose = localPose * offsetPose;

            OVRPose trackingSpace   = transform.ToOVRPose() * localPose.Inverse();
            Vector3 linearVelocity  = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_controller);
            Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_controller);

            GrabbableRelease(linearVelocity, angularVelocity);
            this.objectReleased.Invoke();
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Esempio n. 3
0
        /// <summary>
        /// Returns raw angular velocity for the selected channel identifier, according to OculusTouchChannels enum.
        /// See Oculus documentation to determine orientation of x, y, z.
        /// </summary>
        /// <param name="channel">The channel identifier.</param>
        /// <returns>Raw sensor data for the given channel.</returns>
        public override float GetRawData(string channel)
        {
            // Get the 3-axis angular velocity
            Vector3 angVel = OVRInput.GetLocalControllerAngularVelocity(controller);

            // Select channel to return.
            if (channel.Equals(OculusTouchChannels.X_Vel.ToString()))
            {
                return(angVel.x);
            }
            else if (channel.Equals(OculusTouchChannels.Y_Vel.ToString()))
            {
                return(angVel.y);
            }
            else if (channel.Equals(OculusTouchChannels.Z_Vel.ToString()))
            {
                return(angVel.z);
            }
            else
            {
                throw new System.ArgumentOutOfRangeException("The provided channel identifier is invalid, see OCULUS_TOUCH_CHANNELS enum.");
            }
        }
Esempio n. 4
0
    //IEnumerator NormalTime()
    //{
    //    yield return new WaitForSecondsRealtime(2f);
    //    Time.timeScale = 1f;
    //}

    private float getBatForce(Rigidbody batRB, Collision collision)
    {
        float ang_vel;
        float distance;

        if (hand.righty)
        {
            ang_vel  = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).magnitude;
            distance = (collision.contacts[0].point - OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch)).magnitude;
        }
        else
        {
            ang_vel  = OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).magnitude;
            distance = (collision.contacts[0].point - OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch)).magnitude;
        }
        //Vector3 normal = collision.contacts[0].normal;

        //return ang_vel * distance / 200f * 30f;
        return(ang_vel * distance / 200f * 5f);
        //BatSpeed bs = (BatSpeed)batRB.GetComponent(typeof(BatSpeed));
        //return bs.getVelocity().magnitude /200f * 30f;
        //return batRB.velocity.magnitude / 200f * 30f;
    }
    protected void GrabEnd()
    {
        if (m_grabbedObjs != null)
        {
            for (var i = 0; i < m_grabbedObjs.Count; i++)
            {
                OVRPose localPose = new OVRPose {
                    position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
                };
                OVRPose offsetPose = new OVRPose {
                    position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation
                };
                localPose = localPose * offsetPose;

                OVRPose trackingSpace   = transform.ToOVRPose(true) * localPose.Inverse();
                Vector3 linearVelocity  = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_controller);
                Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_controller);
                GrabbableRelease(m_grabbedObjs[i], linearVelocity, angularVelocity);
            }
        }
        m_grabbedObjs = null;
        GrabVolumeEnable(true);
    }
    public void Drop()
    {
        // Destroy the joint between
        var fixJoint = gameObject.GetComponent <FixedJoint>();

        Destroy(fixJoint);
        OVRPose localPose = new OVRPose {
            position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
        };
        OVRPose offsetPose = new OVRPose {
            position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation
        };

        localPose = localPose * offsetPose;

        OVRPose trackingSpace   = transform.ToOVRPose() * localPose.Inverse();
        Vector3 linearVelocity  = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_controller);
        Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_controller);

        m_grabbedObj = null;
        grabbable.Drop(linearVelocity, angularVelocity);
        grabbable = null;
    }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        OVRInput.Update();

        Debug.Log("X: " + OVRInput.GetLocalControllerAngularVelocity(scriptL.controller).x + " Y: " + OVRInput.GetLocalControllerAngularVelocity(scriptL.controller).y + "Z: " + OVRInput.GetLocalControllerAngularVelocity(scriptL.controller).z);


        Debug.Log(OVRInput.GetLocalControllerVelocity(scriptL.controller).z);


        if (scriptL.grabbing == true && scriptL.grabbedObject.name == "maracas")
        {
            transform.localPosition = new Vector3(0.045f, 0.0138f, 0.044f);
        }


        PlaySounds();



        // If there is an increase og decrease in any xyz by 0.2f play sound.
        // The problem right now is that float values in vectors is only showing 1 decimal, while there is alot of them.
    }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.A))
        {
            Value += 0.01f;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            Value -= 0.01f;
        }

        Vector3 pos = controller.position;//OVRInput.GetLocalControllerPosition(activeController);
        //Debug.DrawLine(pos, pos + new Vector3(1, 0, 0), Color.magenta);
        float dist = Vector3.Distance(transform.position, pos);

        //Debug.Log("dist = " + dist);
        if (dist < 0.3 && OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger))
        {
            Vector3 rot = OVRInput.GetLocalControllerAngularVelocity(activeController);
            //Debug.Log(rot);
            Value += rot.z * Time.deltaTime;
        }
    }
    private void ThrowObject(Collider col)
    {
        col.transform.SetParent(null);
        Rigidbody rigidBody = col.GetComponent <Rigidbody>();

        // Debug.Log("Throwing " + col.gameObject.name);
        if (rigidBody == null)
        {
            return;
        }
        if (col.gameObject.CompareTag("Throwable"))
        {
            rigidBody.isKinematic = false;
            // col.gameObject.GetComponent<Collider>().isTrigger = true;
            rigidBody.velocity        = OVRInput.GetLocalControllerVelocity(thisController) * throwForce;
            rigidBody.angularVelocity = OVRInput.GetLocalControllerAngularVelocity(thisController);

            //set the corresponding material depending on where the player threw
            //
            if (isGrabbingObject)
            {
                BallReset ballScript           = col.gameObject.GetComponent <BallReset>();
                bool      IsStandingOnPlatform = platformCheck.IsOnPlatform();
                if (IsStandingOnPlatform)
                {
                    ballScript.ApplyGreenGlow();
                }
                else
                {
                    ballScript.ApplyRedGlow();
                }
            }
        }
        isGrabbingObject = false;

        // Debug.Log("Released Object");
    }
Esempio n. 10
0
        private void GrabEnd()
        {
            if (Grabbable != null)
            {
                OVRPose localPose = new OVRPose {
                    position = OVRInput.GetLocalControllerPosition(Controller), orientation = OVRInput.GetLocalControllerRotation(Controller)
                };
                OVRPose offsetPose = new OVRPose {
                    position = transform.localPosition, orientation = transform.localRotation
                };
                localPose = localPose * offsetPose;

                OVRPose trackingSpace   = transform.ToOVRPose() * localPose.Inverse();
                Vector3 linearVelocity  = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(Controller);
                Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(Controller);

                GrabbableRelease(linearVelocity, angularVelocity);
            }

            // Re-enable grab volumes to allow overlap events
            GrabVolumeEnable(true);

            RenderersEnable(true);
        }
Esempio n. 11
0
    protected void GrabEnd()
    {
        if (m_grabbedObj != null)
        {
            OVRPose localPose = new OVRPose {
                position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
            };
            OVRPose offsetPose = new OVRPose {
                position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation
            };
            localPose = localPose * offsetPose;

            OVRPose trackingSpace   = transform.ToOVRPose() * localPose.Inverse();
            Vector3 linearVelocity  = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_controller);
            Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_controller);

            m_playerCont.StopIgnore(m_grabbedObj); // Heikki added for test, Stop ignoring player collision

            GrabbableRelease(linearVelocity, angularVelocity);
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
    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
    }
Esempio n. 13
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();
        }
    }
Esempio n. 14
0
 public override Vector3 GetAngularVelocity(TBInput.Controller controller)
 {
     return(OVRInput.GetLocalControllerAngularVelocity(GetOculusControllerID(controller)));
 }
Esempio n. 15
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();
        }
    }
Esempio n. 16
0
 public Vector3 getSwingVelocity()
 {
     return(OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch));
 }
Esempio n. 17
0
 public Vector3 GetAngularVelocity()
 {
     return(OVRInput.GetLocalControllerAngularVelocity(controller));
 }
Esempio n. 18
0
 private void throwObject()
 {
     mHeldObject.velocity           = OVRInput.GetLocalControllerVelocity(Controller);
     mHeldObject.angularVelocity    = OVRInput.GetLocalControllerAngularVelocity(Controller) * Mathf.Deg2Rad;
     mHeldObject.maxAngularVelocity = mHeldObject.angularVelocity.magnitude;
 }
Esempio n. 19
0
    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();
        }
    }
Esempio n. 20
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
    }
Esempio n. 21
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);
            }
        }
Esempio n. 22
0
    // Update is called once per frame
    void Update()
    {
        switch (handState)
        {
        //If there is no temporary joint and the player is pressing down on the hand trigger with enough pressure (>= 0.5f in this case),
        //we set the held object’s velocity to zero, and create a temporary joint attached to it.
        //We then connect that joint to our AttachPoint (by default, the hand itself)
        //and set the hand state to HOLDING
        case HandState.TOUCH:
            //   Debug.LogWarning(mHandState);

            if (temporaryJoint == null && OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touchController) >= 0.5f)
            {
                objectHeld.velocity          = Vector3.zero;
                temporaryJoint               = objectHeld.gameObject.AddComponent <FixedJoint>();
                temporaryJoint.connectedBody = attachedPoint;
                handState = HandState.HOLD;

                //if you grab a vinyl, disable its UI, enable follow cube
                if (objectHeld.gameObject.tag == "vinyl")
                {
                    VinylScript vinylScript = objectHeld.gameObject.GetComponent <VinylScript>();
                    vinylScript.DisableUI();
                    vinylScript.spawnedFollowCube.SetActive(true);
                }
            }
            break;

        // If the hand state is already in the HOLDING state,
        //we check that we do have a temporary joint (i.e. that it is not null)
        //and that the player is releasing enough of the trigger (in this case, < 0.5f).
        //If so, we immediately destroy the temporary joint, and set it to null signifying that it is no longer in use.
        //We then throw the object using a throw method (described further below) and set the hand state to EMPTY.

        case HandState.HOLD:
            //    Debug.LogWarning(mHandState);

            //disable line renderer while holding objects
            lineRenderer.gameObject.SetActive(false);

            if (temporaryJoint != null && OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, touchController) < 0.5f)
            {
                Object.DestroyImmediate(temporaryJoint);
                temporaryJoint = null;


                //To stop collisions with hands when throwing an object
                gameObject.GetComponent <SphereCollider>().enabled = false;
                bool        isThrown    = throwObject();
                VinylScript vinylScript = objectHeld.gameObject.GetComponent <VinylScript>();

                //if object isn't thrown and its a vinyl then re-enable its UI
                if (!isThrown)
                {
                    if (objectHeld.gameObject.tag == "vinyl")
                    {
                        vinylScript.isThrown = false;
                        vinylScript.EnableUI();
                        vinylScript.FollowArtist();
                        //handState = HandState.EMPTY;
                    }
                }
                else
                {
                    //if vinyl is thrown then despawn followcube
                    Destroy(vinylScript.spawnedFollowCube);
                    vinylScript.isThrown = true;
                    //  vinylScript.spawnedFollowCube.SetActive(false);
                }
                //re enable line renderer when letting go of objects
                lineRenderer.gameObject.SetActive(true);
                gameObject.GetComponent <SphereCollider>().enabled = true;
                handState = HandState.EMPTY;
            }
            else if (objectHeld == null)
            {
                handState = HandState.EMPTY;
                //re enable line renderer when letting go of objects
                lineRenderer.gameObject.SetActive(true);
            }
            velocityOld = OVRInput.GetLocalControllerAngularVelocity(touchController);

            break;
        }
    }
Esempio n. 23
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // If holding a menu
        if (menuObject && OVRInput.Get(OVRInput.RawButton.RIndexTrigger) && isHolding)
        {
            // Holding a gravity slider
            if (menuObject.CompareTag("Gravity"))
            {
                Vector3 oldPosition = menuObject.transform.position;
                menuObject.transform.position = new Vector3(finger.transform.position.x, oldPosition.y, oldPosition.z);
            }
            // Holding a size dial
            else if (menuObject.CompareTag("Size"))
            {
                // Assign rotation to size dial
                float rotateAmount = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).eulerAngles.y - prevControllerRotation.y;
                menuObject.transform.eulerAngles = new Vector3(-180.0f, prevDialRotation.y + rotateAmount + 180.0f, 0.0f);

                // Change size of object
                if (selectedObject)
                {
                    float scaleAmount = 0.01f * (menuObject.transform.eulerAngles.y);
                    // Object is prism
                    if (selectedObject.CompareTag("Prism"))
                    {
                        selectedObject.transform.localScale = new Vector3(scaleAmount, 3.0f * scaleAmount, scaleAmount);
                    }
                    // Object is not a prism
                    else
                    {
                        selectedObject.transform.localScale = new Vector3(scaleAmount, scaleAmount, scaleAmount);
                    }
                }
            }
            // Pressing red button
            else if (menuObject.CompareTag("Red"))
            {
                // Change color of selected object
                if (selectedObject)
                {
                    selectedObject.GetComponent <MeshRenderer>().material.color = Color.red;
                }
            }
            // Pressing green button
            else if (menuObject.CompareTag("Green"))
            {
                // Change color of selected object
                if (selectedObject)
                {
                    selectedObject.GetComponent <MeshRenderer>().material.color = Color.green;
                }
            }
            // Pressing blue button
            else if (menuObject.CompareTag("Blue"))
            {
                // Change color of selected object
                if (selectedObject)
                {
                    selectedObject.GetComponent <MeshRenderer>().material.color = Color.blue;
                }
            }
            // Pressing yellow button
            else if (menuObject.CompareTag("Yellow"))
            {
                // Change color of selected object
                if (selectedObject)
                {
                    selectedObject.GetComponent <MeshRenderer>().material.color = Color.yellow;
                }
            }
        }
        // If pressing trigger and not already holding something
        else if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger) && !isHolding)
        {
            // If there is something to grab
            if (collidingObject)
            {
                // Mark that you are now holding something
                isHolding = true;

                // If colliding with building block
                if (collidingObject.CompareTag("Block") || collidingObject.CompareTag("Prism"))
                {
                    // Remember previously selected
                    prevSelectedObject = selectedObject;

                    // Mark that collidingObject is now selected
                    selectedObject = collidingObject;

                    // Unhighlight previously selectedObject
                    if (prevSelectedObject)
                    {
                        prevSelectedObject.GetComponent <Outline>().enabled = false;
                    }

                    // Highlight selectedObject
                    selectedObject.GetComponent <Outline>().enabled = true;

                    // Disable gravity and momentum on selected object
                    Rigidbody rb = selectedObject.GetComponent <Rigidbody>();
                    if (rb)
                    {
                        rb.isKinematic = true;
                    }

                    // Have object follow transformations of hand
                    selectedObject.transform.SetParent(this.transform);
                }
                // Colliding with stationary menu
                else if (collidingObject.CompareTag("CreateSphere") || collidingObject.CompareTag("CreateCylinder") || collidingObject.CompareTag("CreateCube") || collidingObject.CompareTag("CreatePrism"))
                {
                    isHolding = false;
                    // Instantiate an object
                    if (collidingObject.CompareTag("CreateSphere"))
                    {
                        collidingObject = Instantiate(sphere, finger.transform.position, Quaternion.identity);
                    }
                    else if (collidingObject.CompareTag("CreateCylinder"))
                    {
                        collidingObject = Instantiate(cylinder, finger.transform.position, Quaternion.identity);
                    }
                    else if (collidingObject.CompareTag("CreateCube"))
                    {
                        collidingObject = Instantiate(cube, finger.transform.position, Quaternion.identity);
                    }
                    else if (collidingObject.CompareTag("CreatePrism"))
                    {
                        collidingObject = Instantiate(prism, finger.transform.position, Quaternion.identity);
                    }
                    else
                    {
                        isHolding = true;
                    }
                }
                // If colliding with a menuObject
                else
                {
                    // Indicate that a menuObject is being held
                    menuObject = collidingObject;

                    // If it's the size dial remember rotations and scale
                    if (menuObject.CompareTag("Size"))
                    {
                        prevDialRotation       = menuObject.transform.eulerAngles;
                        prevControllerRotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch).eulerAngles;
                    }

                    // Highlight menuObject
                    menuObject.GetComponent <Outline>().enabled = true;
                }
            }
        }
        // If not pressing trigger and holding something
        else if (!OVRInput.Get(OVRInput.RawButton.RIndexTrigger) && isHolding)
        {
            // Mark that you are not holding
            isHolding = false;

            // Reenable gravity and momentum
            if (selectedObject)
            {
                Rigidbody rb = selectedObject.GetComponent <Rigidbody>();
                if (rb)
                {
                    rb.isKinematic     = false;
                    rb.velocity        = trackingSpace.rotation * (2.0f * OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch));
                    rb.angularVelocity = 0.5f * OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch);
                }

                // No longer inherit transforms
                selectedObject.transform.SetParent(null);
            }

            // Releasing a menu object
            if (menuObject)
            {
                menuObject.GetComponent <Outline>().enabled = false;
                menuObject = null;
            }
        }
    }
 void DoGetVelocity()
 {
     controllerAngularVelocity.Value = OVRInput.GetLocalControllerAngularVelocity(controllerInput);
 }
Esempio n. 25
0
        /// <summary>
        /// Update the controller data from the provided platform state
        /// </summary>
        /// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform</param>
        public void UpdateController(OVRCameraRig ovrRigRoot, OVRInput.Controller ovrController)
        {
            if (!Enabled || ovrRigRoot == null)
            {
                return;
            }

            IsPositionAvailable = OVRInput.GetControllerPositionValid(ovrController);
            IsRotationAvailable = OVRInput.GetControllerOrientationValid(ovrController);

            Transform playSpaceTransform = ovrRigRoot.transform;

            // Update transform
            Vector3 localPosition = OVRInput.GetLocalControllerPosition(ovrController);
            Vector3 worldPosition = playSpaceTransform.TransformPoint(localPosition);
            // Debug.Log("Controller " + Handedness + " - local: " + localPosition + " - world: " + worldPosition);

            Quaternion localRotation = OVRInput.GetLocalControllerRotation(ovrController);
            Quaternion worldRotation = playSpaceTransform.rotation * localRotation;

            // Update velocity
            Vector3 localVelocity = OVRInput.GetLocalControllerVelocity(ovrController);

            Velocity = playSpaceTransform.TransformDirection(localVelocity);

            Vector3 localAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(ovrController);

            AngularVelocity = playSpaceTransform.TransformDirection(localAngularVelocity);

            if (IsPositionAvailable)
            {
                currentPointerPose.Position = currentGripPose.Position = worldPosition;
            }

            if (IsRotationAvailable)
            {
                currentPointerPose.Rotation = currentGripPose.Rotation = worldRotation;
            }

            // Todo: Complete touch controller mapping

            bool isTriggerPressed = false;

            if (ControllerHandedness == Handedness.Left)
            {
                isTriggerPressed = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > cTriggerDeadZone;
            }
            else
            {
                isTriggerPressed = OVRInput.Get(OVRInput.Axis1D.SecondaryIndexTrigger) > cTriggerDeadZone;
            }

            UpdateJointPoses();

            for (int i = 0; i < Interactions?.Length; i++)
            {
                switch (Interactions[i].InputType)
                {
                case DeviceInputType.SpatialPointer:
                    Interactions[i].PoseData = currentPointerPose;
                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, currentPointerPose);
                    }
                    break;

                case DeviceInputType.SpatialGrip:
                    Interactions[i].PoseData = currentGripPose;
                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, currentGripPose);
                    }
                    break;

                case DeviceInputType.Select:
                    Interactions[i].BoolData = isTriggerPressed;

                    if (Interactions[i].Changed)
                    {
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    break;

                case DeviceInputType.TriggerPress:
                    Interactions[i].BoolData = isTriggerPressed;

                    if (Interactions[i].Changed)
                    {
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    break;

                case DeviceInputType.IndexFinger:
                    UpdateIndexFingerData(Interactions[i]);
                    break;
                }
            }
        }
Esempio n. 26
0
 public void ActivePhysics(Hand hand, float force, float angularForce)
 {
     m_rigidbody.isKinematic     = false;
     m_rigidbody.velocity        = trackingSpace.rotation * OVRInput.GetLocalControllerVelocity(hand.m_controller) * force;
     m_rigidbody.angularVelocity = OVRInput.GetLocalControllerAngularVelocity(hand.m_controller) * angularForce;
 }
Esempio n. 27
0
        // Update is called once per frame
        void Update()
        {
            if ((OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).magnitude < Constants.PUNCH_VELOCITY_RESET_THRESHOLD &&
                 OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).magnitude < Constants.PUNCH_ANGULAR_VELOCITY_RESET_THRESHOLD) &&
                (OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).magnitude < Constants.PUNCH_VELOCITY_RESET_THRESHOLD &&
                 OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).magnitude < Constants.PUNCH_ANGULAR_VELOCITY_RESET_THRESHOLD))
            {
                // Debug.Log("m_bDidPlayerPunch: " + m_bDidPlayerPunch);
                if (m_bDidPlayerPunch)
                {
                    Debug.Log("m_topPunchVel: " + m_topLeftPunchVel);
                    Debug.Log("m_topPunchAngularVel: " + m_topLeftPunchAngularVel);
                    ResetPunchVariables();
                }
            }
            else if (OVRInput.GetLocalControllerVelocity(OVRInput.Controller.LTouch).magnitude >= Constants.PUNCH_VELOCITY_THRESHOLD ||
                     OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.LTouch).magnitude >= Constants.PUNCH_ANGULAR_VELOCITY_THRESHOLD)
            {
                m_bDidPlayerPunch = true;
                m_bCanPlayerPunch = false;
                Debug.Log("Punching Left");
                GetLeftPunchVelocity();
                GetLeftPunchAngularVelocity();
            }
            else if (OVRInput.GetLocalControllerVelocity(OVRInput.Controller.RTouch).magnitude >= Constants.PUNCH_ANGULAR_VELOCITY_THRESHOLD ||
                     OVRInput.GetLocalControllerAngularVelocity(OVRInput.Controller.RTouch).magnitude >= Constants.PUNCH_ANGULAR_VELOCITY_THRESHOLD)
            {
                m_bDidPlayerPunch = true;
                m_bCanPlayerPunch = false;
                Debug.Log("Punching Right");
                GetRightPunchVelocity();
                GetRightPunchAngularVelocity();
            }

            #region ControllerButtons

            if (mHead != null)
            {
                // save previous frame's head rotation reading and calculate delta rotation from previous and current frames
                prevHeadRot    = currentHeadRot;
                currentHeadRot = mHead.transform.eulerAngles;
                currentHeadRot = new Vector3(
                    (currentHeadRot.x > 180) ? currentHeadRot.x - 360 : currentHeadRot.x,
                    (currentHeadRot.y > 180) ? currentHeadRot.y - 360 : currentHeadRot.y,
                    (currentHeadRot.z > 180) ? currentHeadRot.z - 360 : currentHeadRot.z
                    );
                deltaHeadRot = currentHeadRot - prevHeadRot;
                if (deltaHeadRot != Vector3.zero)
                {
                    if (aHeadRotChanged != null)
                    {
                        aHeadRotChanged(prevHeadRot, currentHeadRot, deltaHeadRot);
                    }
                }
            }

                        #if ANDROID_DEVICE && PicoBuild
            if (IsRemoteConnected())
            {
                m_rightHandTransform.rotation = Pvr_UnitySDKAPI.Controller.UPvr_GetControllerQUA(0);
                m_leftHandTransform.rotation  = Pvr_UnitySDKAPI.Controller.UPvr_GetControllerQUA(1);
            }
                        #elif OculusBuild
            m_rightHandTransform.rotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);
            m_rightHandTransform.position = OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch);
            m_leftHandTransform.rotation  = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
            m_leftHandTransform.position  = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
                        #endif

            prevAcc    = currentAcc;
            currentAcc = Pvr_UnitySDKAPI.Controller.Upvr_GetAcceleration();

            deltaAcc = currentAcc - prevAcc;

            if (deltaAcc != Vector3.zero)
            {
                if (aAccChanged != null)
                {
                    aAccChanged(prevAcc, currentAcc, deltaAcc);
                }
            }

                #if PicoBuild
            if (Pvr_UnitySDKAPI.Controller.UPvr_GetSwipeDirection(0) == Pvr_UnitySDKAPI.SwipeDirection.SwipeLeft ||
                Pvr_UnitySDKAPI.Controller.UPvr_GetSwipeDirection(0) == Pvr_UnitySDKAPI.SwipeDirection.SwipeRight ||
                Pvr_UnitySDKAPI.Controller.UPvr_GetSwipeDirection(1) == Pvr_UnitySDKAPI.SwipeDirection.SwipeLeft ||
                Pvr_UnitySDKAPI.Controller.UPvr_GetSwipeDirection(1) == Pvr_UnitySDKAPI.SwipeDirection.SwipeRight)
            {
                if (aXButtonDown != null)
                {
                    aXButtonDown();
                }
            }

            /*
             * Touchpad
             */
            if (Pvr_UnitySDKAPI.Controller.UPvr_GetKeyDown(0, Pvr_UnitySDKAPI.Pvr_KeyCode.TOUCHPAD) || Input.GetKeyDown(KeyCode.Z))
            {
                if (aAButtonDown != null)
                {
                    aAButtonDown();
                }
            }
            else if (Pvr_UnitySDKAPI.Controller.UPvr_GetKey(0, Pvr_UnitySDKAPI.Pvr_KeyCode.TOUCHPAD) || Input.GetKey(KeyCode.Z))
            {
                if (aAButtonPressed != null)
                {
                    aAButtonPressed();
                }
            }
            else if (Pvr_UnitySDKAPI.Controller.UPvr_GetKeyUp(0, Pvr_UnitySDKAPI.Pvr_KeyCode.TOUCHPAD) || Input.GetKeyUp(KeyCode.Z))
            {
                if (aAButtonUp != null)
                {
                    aAButtonUp();
                }
                Pvr_UnitySDKManager.SDK.newPicovrTriggered = true;
            }

            /*
             * Home Button
             */
            if (Pvr_UnitySDKAPI.Controller.UPvr_GetKeyLongPressed(0, Pvr_UnitySDKAPI.Pvr_KeyCode.HOME) || Input.GetKeyDown(KeyCode.M))
            {
                if (aLButtonPressed != null)
                {
                    aLButtonPressed();
                }
            }

            /*
             * App Button
             */
            if (Pvr_UnitySDKAPI.Controller.UPvr_GetKeyDown(0, Pvr_UnitySDKAPI.Pvr_KeyCode.APP) || Input.GetKeyDown(KeyCode.Space))
            {
                if (aBackButtonDown != null)
                {
                    aBackButtonDown();
                }
            }
            else if (Pvr_UnitySDKAPI.Controller.UPvr_GetKey(0, Pvr_UnitySDKAPI.Pvr_KeyCode.APP))
            {
                if (aBackButtonPressed != null)
                {
                    aBackButtonPressed();
                }
            }
            else if (Pvr_UnitySDKAPI.Controller.UPvr_GetKeyUp(0, Pvr_UnitySDKAPI.Pvr_KeyCode.APP))
            {
                if (aBackButtonUp != null)
                {
                    aBackButtonUp();
                }
            }
                #elif OculusBuild
            if (bcanSwitch == true)
            {
                Vector2 primaryTouchpad   = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
                Vector2 secondaryTouchpad = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);

                if (secondaryTouchpad.x < 0 || secondaryTouchpad.x > 0 || primaryTouchpad.x < 0 || primaryTouchpad.x > 0)
                {
                    delayCoroutine = DelaySwitch(0.5f);

                    if (aXButtonDown != null)
                    {
                        aXButtonDown();
                    }

                    StopCoroutine(delayCoroutine);
                    StartCoroutine(delayCoroutine);
                    bcanSwitch = false;
                }
            }
                #endif

            /*
             * Controller Mapping
             * - Mapping is based on Pico Neo gamepad
             */

            /*
             * Up/Down Buttons
             */
            if (Input.GetAxis("Vertical") == 1)
            {
                if (aUpButtonPressed != null)
                {
                    aUpButtonPressed();
                }
            }
            if (Input.GetAxis("Vertical") == -1)
            {
                if (aDownButtonPressed != null)
                {
                    aDownButtonPressed();
                }
            }

            /*
             * Left/Right Buttons
             */
            if (Input.GetAxis("Horizontal") == 1)
            {
                if (aRightButtonPressed != null)
                {
                    aRightButtonPressed();
                }
            }
            if (Input.GetAxis("Horizontal") == -1)
            {
                if (aLeftButtonPressed != null)
                {
                    aLeftButtonPressed();
                }
            }

            /*
             * Menu Button
             */
            if (Input.GetKeyDown(KeyCode.Menu))
            {
                if (aMenuButtonDown != null)
                {
                    aMenuButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Menu))
            {
                if (aMenuButtonPressed != null)
                {
                    aMenuButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Menu))
            {
                if (aMenuButtonUp != null)
                {
                    aMenuButtonUp();
                }
            }

            /*
             * Back Button
             */
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (aBackButtonDown != null)
                {
                    aBackButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Escape))
            {
                if (aBackButtonPressed != null)
                {
                    aBackButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (aBackButtonUp != null)
                {
                    aBackButtonUp();
                }
            }

            #endregion

            #region ControllerPosition

                        #if PicoBuild
            Debug.Log("----------------------------------------------------------------------------------");
            Debug.Log("Acceleration: " + Pvr_UnitySDKAPI.Controller.Upvr_GetAcceleration());
            Debug.Log("Angular Velocity Right: " + Pvr_UnitySDKAPI.Controller.Upvr_GetAngularVelocity(0));
            Debug.Log("Angular Velocity Left: " + Pvr_UnitySDKAPI.Controller.Upvr_GetAngularVelocity(1));

            #region RightHandPos

            //Front Block Right
            if ((GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Up) > 0 &&
                (GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Front) == 0 &&
                (GetReferencePointDirection(m_rightHandTransform.forward) & AxisDirection.Right) > 0)
            {
                // Debug.Log("Right Front Block");
                if (aRightFrontBlock != null)
                {
                    aRightFrontBlock();
                }
            }

            //Hook Block Right
            if ((GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Up) > 0 &&
                (GetReferencePointDirection(m_rightHandTransform.forward) & AxisDirection.Back) > 0)
            {
                // Debug.Log("Right Side Block");
                if (aRightSideBlock != null)
                {
                    aRightSideBlock();
                }
            }

            //Cross Right
            if ((GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Front) > 0 &&
                (GetReferencePointDirection(m_rightHandTransform.forward) & AxisDirection.Left) > 0)
            {
                // Debug.Log("Cross Right");
                if (aRightCross != null)
                {
                    aRightCross();
                }
            }

            //Uppercut Right
            if ((GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Up) > 0 &&
                (GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Front) > 0 &&
                (GetReferencePointDirection(m_rightHandTransform.forward) & AxisDirection.Right) > 0)
            {
                // Debug.Log("Uppercut Right");
                if (aRightUppercut != null)
                {
                    aRightUppercut();
                }
            }

            //Hook Right
            if ((GetReferencePointDirection(-m_rightHandTransform.up) & AxisDirection.Left) > 0 &&
                (GetReferencePointDirection(m_rightHandTransform.forward) & (AxisDirection.Up | AxisDirection.Back)) > 0)
            {
                // Debug.Log("Hook Right");
                if (aRightHook != null)
                {
                    aRightHook();
                }
            }

            #endregion

            #region LeftHandPos

            //Front Block Left
            if ((GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Up) > 0 &&
                (GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Front) == 0 &&
                (GetReferencePointDirection(m_leftHandTransform.forward) & AxisDirection.Left) > 0)
            {
                // Debug.Log("Left Front Block");
                if (aLeftFrontBlock != null)
                {
                    aLeftFrontBlock();
                }
            }

            //Hook Block Left
            if ((GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Up) > 0 &&
                (GetReferencePointDirection(m_leftHandTransform.forward) & AxisDirection.Back) > 0)
            {
                // Debug.Log("Left Side Block");
                if (aLeftSideBlock != null)
                {
                    aLeftSideBlock();
                }
            }

            //Jab Left
            if ((GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Front) > 0 &&
                (GetReferencePointDirection(m_leftHandTransform.forward) & AxisDirection.Right) > 0)
            {
                // Debug.Log("Jab Left");
                if (aLeftJab != null)
                {
                    aLeftJab();
                }
            }

            //Uppercut Left
            if ((GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Up) > 0 &&
                (GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Front) > 0 &&
                (GetReferencePointDirection(m_leftHandTransform.forward) & AxisDirection.Left) > 0)
            {
                // Debug.Log("Uppercut Left");
                if (aLeftUppercut != null)
                {
                    aLeftUppercut();
                }
            }

            //Hook Left
            if ((GetReferencePointDirection(-m_leftHandTransform.up) & AxisDirection.Right) > 0 &&
                (GetReferencePointDirection(m_leftHandTransform.forward) & (AxisDirection.Up | AxisDirection.Back)) > 0)
            {
                // Debug.Log("Hook Left");
                if (aLeftHook != null)
                {
                    aLeftHook();
                }
            }

            #endregion

            #endregion

            /*
             * A Button
             */
            if (Input.GetKeyDown(KeyCode.Joystick1Button0))            // || Input.GetKeyDown(KeyCode.Z)){// || Input.GetButtonDown("Fire1")
            {
                if (aAButtonDown != null)
                {
                    // aAButtonDown ();
                    aRButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Joystick1Button0))            // || Input.GetButton("Fire1") || Input.GetKey(KeyCode.Z)) {;
            {
                if (aAButtonPressed != null)
                {
                    aAButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Joystick1Button0))            // || Input.GetKeyUp(KeyCode.Z)) {//|| Input.GetButtonUp("Fire1") ) {
            {
                if (aAButtonUp != null)
                {
                    aAButtonUp();
                }
            }

            /*
             * B Button
             */
            if (Input.GetKeyDown(KeyCode.Joystick1Button1) || Input.GetKeyDown(KeyCode.X))
            {
                if (aBButtonDown != null)
                {
                    aBButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Joystick1Button1) || Input.GetKey(KeyCode.X))
            {
                if (aBButtonPressed != null)
                {
                    aBButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Joystick1Button1) || Input.GetKeyUp(KeyCode.X))
            {
                if (aBButtonUp != null)
                {
                    aBButtonUp();
                }
            }

            /*
             * X Button
             */
            if (Input.GetKeyDown(KeyCode.Joystick1Button2) || Input.GetKeyDown(KeyCode.C))
            {
                if (aXButtonDown != null)
                {
                    aXButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Joystick1Button2) || Input.GetKey(KeyCode.C))
            {
                if (aXButtonPressed != null)
                {
                    aXButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Joystick1Button2) || Input.GetKeyUp(KeyCode.C))
            {
                if (aXButtonUp != null)
                {
                    aXButtonUp();
                }
            }

            /*
             * Y Button
             */
            if (Input.GetKeyDown(KeyCode.Joystick1Button3))
            {
                if (aYButtonDown != null)
                {
                    aYButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Joystick1Button3))
            {
                if (aYButtonPressed != null)
                {
                    aYButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Joystick1Button3))
            {
                if (aYButtonUp != null)
                {
                    aYButtonUp();
                }
            }

            /*
             * L Button
             */
            if (Input.GetKeyDown(KeyCode.Joystick1Button4))
            {
                if (aLButtonDown != null)
                {
                    aLButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Joystick1Button4))
            {
                if (aLButtonPressed != null)
                {
                    aLButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Joystick1Button4))
            {
                if (aLButtonUp != null)
                {
                    aLButtonUp();
                }
            }

            /*
             * R Button
             */
            if (Input.GetKeyDown(KeyCode.Joystick1Button5))
            {
                if (aRButtonDown != null)
                {
                    aRButtonDown();
                }
            }
            else if (Input.GetKey(KeyCode.Joystick1Button5))
            {
                if (aRButtonPressed != null)
                {
                    aRButtonPressed();
                }
            }
            else if (Input.GetKeyUp(KeyCode.Joystick1Button5))
            {
                if (aRButtonUp != null)
                {
                    aRButtonUp();
                }
            }
        }
Esempio n. 28
0
 /// <summary>Get raw angular velocity of the player hand</summary>
 public static Vector3 GetHandAngularVelocity(this InputOculus self, Side side)
 {
     return(OVRInput.GetLocalControllerAngularVelocity(side == Side.Right ? OVRInput.Controller.RTouch : OVRInput.Controller.LTouch));
 }
        /// <summary>
        /// Update the controller data from the provided platform state
        /// </summary>
        /// <param name="interactionSourceState">The InteractionSourceState retrieved from the platform</param>
        public void UpdateController(OVRInput.Controller ovrController, Transform trackingRoot)
        {
            if (!Enabled || trackingRoot == null)
            {
                return;
            }

            IsPositionAvailable = OVRInput.GetControllerPositionValid(ovrController);
            IsRotationAvailable = OVRInput.GetControllerOrientationValid(ovrController);

            // Update transform
            Vector3 localPosition = OVRInput.GetLocalControllerPosition(ovrController);
            Vector3 worldPosition = trackingRoot.TransformPoint(localPosition);
            // Debug.Log("Controller " + Handedness + " - local: " + localPosition + " - world: " + worldPosition);

            Quaternion localRotation = OVRInput.GetLocalControllerRotation(ovrController);
            Quaternion worldRotation = trackingRoot.rotation * localRotation;

            // Update velocity
            Vector3 localVelocity = OVRInput.GetLocalControllerVelocity(ovrController);

            Velocity = trackingRoot.TransformDirection(localVelocity);

            Vector3 localAngularVelocity = OVRInput.GetLocalControllerAngularVelocity(ovrController);

            AngularVelocity = trackingRoot.TransformDirection(localAngularVelocity);

            UpdateJointPoses();

            // If not rendering avatar hands, pointer pose is not available, so we approximate it
            if (IsPositionAvailable)
            {
                currentPointerPose.Position = currentGripPose.Position = worldPosition;
            }

            if (IsRotationAvailable)
            {
                currentPointerPose.Rotation = currentGripPose.Rotation = worldRotation;
            }

            // Todo: Complete touch controller mapping
            bool  isTriggerPressed;
            float triggerValue;

            bool  isGripPressed;
            float gripValue;

            Vector2 stickInput;

            if (ControllerHandedness == Handedness.Left)
            {
                triggerValue     = OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger);
                isTriggerPressed = triggerValue > cTriggerDeadZone;

                gripValue     = OVRInput.Get(OVRInput.RawAxis1D.LHandTrigger);
                isGripPressed = gripValue > cTriggerDeadZone;

                stickInput = OVRInput.Get(OVRInput.RawAxis2D.LThumbstick);
            }
            else
            {
                triggerValue     = OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger);
                isTriggerPressed = triggerValue > cTriggerDeadZone;

                gripValue     = OVRInput.Get(OVRInput.RawAxis1D.RHandTrigger);
                isGripPressed = gripValue > cTriggerDeadZone;

                stickInput = OVRInput.Get(OVRInput.RawAxis2D.RThumbstick);
            }

            UpdateHandPinchStrength(Mathf.Max(triggerValue, gripValue));

            bool isSelecting = isTriggerPressed || isGripPressed;

            UpdateTeleport(stickInput);

            for (int i = 0; i < Interactions?.Length; i++)
            {
                switch (Interactions[i].InputType)
                {
                case DeviceInputType.SpatialPointer:
                    Interactions[i].PoseData = currentPointerPose;
                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, currentPointerPose);
                    }
                    break;

                case DeviceInputType.SpatialGrip:
                    Interactions[i].PoseData = currentGripPose;
                    if (Interactions[i].Changed)
                    {
                        CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, currentGripPose);
                    }
                    break;

                case DeviceInputType.Select:
                    Interactions[i].BoolData = isSelecting;

                    if (Interactions[i].Changed)
                    {
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    break;

                case DeviceInputType.TriggerPress:
                    Interactions[i].BoolData = isSelecting;

                    if (Interactions[i].Changed)
                    {
                        if (Interactions[i].BoolData)
                        {
                            CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                        else
                        {
                            CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction);
                        }
                    }
                    break;

                case DeviceInputType.IndexFinger:
                    UpdateIndexFingerData(Interactions[i]);
                    break;
                }
            }
        }
Esempio n. 30
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();
    }