Пример #1
0
    void Update()
    {
        #if UNITY_EDITOR || !UNITY_WEBGL
        bool quickToggleEnabled = toggleVRKeyName != null && toggleVRKeyName != "";
        if (quickToggleEnabled && Input.GetKeyUp(toggleVRKeyName))
        {
            toggleVrState();
        }
        #endif

        if (OnHeadsetUpdate != null)
        {
            Matrix4x4 leftProjectionMatrix  = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(0));
            Matrix4x4 rightProjectionMatrix = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(1));
            Matrix4x4 leftViewMatrix        = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(2));
            Matrix4x4 rightViewMatrix       = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(3));
            Matrix4x4 sitStandMatrix        = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(4));

            sitStand = sitStandMatrix;

            OnHeadsetUpdate(
                leftProjectionMatrix,
                rightProjectionMatrix,
                leftViewMatrix,
                rightViewMatrix,
                sitStand);
        }
    }
Пример #2
0
    void LateUpdate()
    {
        if (OnHeadsetUpdate != null && this.vrState == WebVRState.ENABLED)
        {
            Matrix4x4 leftProjectionMatrix  = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(0));
            Matrix4x4 rightProjectionMatrix = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(1));
            Matrix4x4 leftViewMatrix        = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(2));
            Matrix4x4 rightViewMatrix       = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(3));
            Matrix4x4 sitStandMatrix        = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(4));
            if (!this.capabilities.hasPosition)
            {
                sitStandMatrix = Matrix4x4.Translate(new Vector3(0, this.DefaultHeight, 0));
            }

            Matrix4x4 trs = WebVRMatrixUtil.TransformViewMatrixToTRS(leftViewMatrix);
            headRotation = WebVRMatrixUtil.GetRotationFromMatrix(trs);
            headPosition = WebVRMatrixUtil.GetTranslationFromMatrix(trs);
            sitStand     = sitStandMatrix;

            if (cameraAttachment)
            {
                cameraAttachment.VRCamera.localRotation = headRotation;
                cameraAttachment.VRCamera.localPosition = headPosition;
            }

            OnHeadsetUpdate(
                leftProjectionMatrix,
                rightProjectionMatrix,
                leftViewMatrix,
                rightViewMatrix,
                sitStandMatrix);
        }
    }
Пример #3
0
    //float timeSinceLast = 0.0f;

    private void onControllerUpdate(string id,
                                    int index,
                                    string handValue,
                                    bool hasOrientation,
                                    bool hasPosition,
                                    Quaternion orientation,
                                    Vector3 position,
                                    Vector3 linearAcceleration,
                                    Vector3 linearVelocity,
                                    WebVRControllerButton[] buttonValues,
                                    float[] axesValues)
    {
        if (handFromString(handValue) == hand)
        {
            SetVisible(true);

            Quaternion sitStandRotation = WebVRMatrixUtil.GetRotationFromMatrix(WebVRManager.Instance.sitStand);
            Quaternion rotation         = sitStandRotation * orientation;
            velocity.Update(linearVelocity);

            if (!hasPosition || this.simulate3dof)
            {
                position = applyArmModel(
                    WebVRManager.Instance.sitStand.MultiplyPoint(WebVRManager.Instance.headPosition),
                    rotation,
                    WebVRManager.Instance.headRotation);
            }
            else
            {
                position = WebVRManager.Instance.sitStand.MultiplyPoint(position);
            }

            transform.localRotation = rotation;
            transform.localPosition = position;

            UpdateButtons(buttonValues);
            this.axes = axesValues;

            if (axes.Length >= 2)
            {
                axes[1] = -axes[1];
            }

            //if (Time.time - timeSinceLast > 1.0f)
            //{
            //    Debug.Log("Buttons for hand " + hand.ToString());
            //    foreach(var button in buttonStates)
            //    {
            //        Debug.Log(string.Format("Button {0}: {1}", button.Key, button.Value.pressed));
            //    }

            //    timeSinceLast = Time.time;
            //}
        }
    }
Пример #4
0
    private void onHeadsetUpdate(Matrix4x4 leftProjectionMatrix,
                                 Matrix4x4 rightProjectionMatrix,
                                 Matrix4x4 leftViewMatrix,
                                 Matrix4x4 rightViewMatrix,
                                 Matrix4x4 sitStandMatrix)
    {
        Matrix4x4 trs = WebVRMatrixUtil.TransformViewMatrixToTRS(leftViewMatrix);

        this.headRotation = WebVRMatrixUtil.GetRotationFromMatrix(trs);
        this.headPosition = WebVRMatrixUtil.GetTranslationFromMatrix(trs);
    }
Пример #5
0
 private void onHeadsetUpdate(
     Matrix4x4 leftProjectionMatrix,
     Matrix4x4 rightProjectionMatrix,
     Matrix4x4 leftViewMatrix,
     Matrix4x4 rightViewMatrix,
     Matrix4x4 sitStandMatrix)
 {
     if (vrActive)
     {
         WebVRMatrixUtil.SetTransformFromViewMatrix(cameraL.transform, leftViewMatrix * sitStandMatrix.inverse);
         cameraL.projectionMatrix = leftProjectionMatrix;
         WebVRMatrixUtil.SetTransformFromViewMatrix(cameraR.transform, rightViewMatrix * sitStandMatrix.inverse);
         cameraR.projectionMatrix = rightProjectionMatrix;
     }
 }
Пример #6
0
    private void onControllerUpdate(string id,
                                    int index,
                                    string handValue,
                                    bool hasOrientation,
                                    bool hasPosition,
                                    Quaternion orientation,
                                    Vector3 position,
                                    Vector3 linearAcceleration,
                                    Vector3 linearVelocity,
                                    Matrix4x4 sitStand,
                                    WebVRControllerButton[] buttonValues,
                                    float[] axesValues)
    {
        if (handFromString(handValue) == hand)
        {
            SetVisible(true);

            Quaternion sitStandRotation = WebVRMatrixUtil.GetRotationFromMatrix(sitStand);
            Quaternion rotation         = sitStandRotation * orientation;

            if (!hasPosition || this.simulate3dof)
            {
                position = applyArmModel(
                    sitStand.MultiplyPoint(this.headPosition),
                    rotation,
                    this.headRotation);
            }
            else
            {
                position = sitStand.MultiplyPoint(position);
            }

            transform.rotation = rotation;
            transform.position = position;

            UpdateButtons(buttonValues);
            this.axes = axesValues;
        }
    }
    void LateUpdate()
    {
        if (OnHeadsetUpdate != null && this.vrState == WebVRState.ENABLED)
        {
            Matrix4x4 leftProjectionMatrix  = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(0));
            Matrix4x4 rightProjectionMatrix = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(1));
            Matrix4x4 leftViewMatrix        = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(2));
            Matrix4x4 rightViewMatrix       = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(3));
            Matrix4x4 sitStandMatrix        = WebVRMatrixUtil.NumbersToMatrix(GetFromSharedArray(4));
            if (!this.capabilities.hasPosition)
            {
                sitStandMatrix = Matrix4x4.Translate(new Vector3(0, this.DefaultHeight, 0));
            }

            OnHeadsetUpdate(
                leftProjectionMatrix,
                rightProjectionMatrix,
                leftViewMatrix,
                rightViewMatrix,
                sitStandMatrix);
        }
    }
Пример #8
0
    private void onControllerUpdate(string id,
                                    int index,
                                    string handValue,
                                    bool hasOrientation,
                                    bool hasPosition,
                                    Quaternion orientation,
                                    Vector3 position,
                                    Vector3 linearAcceleration,
                                    Vector3 linearVelocity,
                                    WebVRControllerButton[] buttonValues,
                                    float[] axesValues)
    {
        if (handFromString(handValue) == hand)
        {
            SetVisible(true);

            Quaternion sitStandRotation = WebVRMatrixUtil.GetRotationFromMatrix(this.sitStand);

            //////////////////////
            //Custom Rotations

            Vector4 customRot = new Vector4(clientData.rot.x, clientData.rot.y, clientData.rot.z, clientData.rot.w);

            if (customRot.magnitude != 0)
            {
                //NO EXACT MATCH? POINTS OF OCULUS REFERENCES NOT IN PAR WITH THIS ROTATION
                //player
                //mainplayer
                thisTransform.parent.rotation *= new Quaternion(customRot.x, customRot.y, customRot.z, customRot.w);
                clientData.rot = new Vector4();
            }


            Quaternion rotation = sitStandRotation * orientation;



            if (!hasPosition || this.simulate3dof)
            {
                position = applyArmModel(
                    this.sitStand.MultiplyPoint(this.headPosition),
                    rotation,
                    this.headRotation);
            }
            else
            {
                position = this.sitStand.MultiplyPoint(position);
            }

            thisTransform.localRotation = rotation;


            thisTransform.localPosition = position;

            thisTransform.position += clientData.pos;


            // hand network updates
            //var controllerCoords = new Coords();

            //controllerCoords.clientId = NetworkUpdateHandler.Instance.client_id;
            //controllerCoords.entityId = (NetworkUpdateHandler.Instance.client_id * 10) + (int)hand;
            //controllerCoords.entityType = (int)hand;
            //controllerCoords.rot = rotation;
            //controllerCoords.pos = position;

            //NetworkUpdateEvent.Invoke(controllerCoords);


            UpdateButtons(buttonValues);
            this.axes = axesValues;
        }
    }