Exemplo n.º 1
0
        protected override void GrabEnd()
        {
            if (m_grabbedObj != null)
            {
                m_grabbedObj.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;

                graph.movingNodes.Remove(m_grabbedObj.transform.GetSiblingIndex());

                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);
            }


            // Re-enable grab volumes to allow overlap events
            GrabVolumeEnable(true);
        }
Exemplo n.º 2
0
    public virtual Matrix4x4 ComputeTrackReferenceMatrix()
    {
        if (centerEyeAnchor == null)
        {
            Debug.LogError("centerEyeAnchor is required");
            return(Matrix4x4.identity);
        }

        // The ideal approach would be using UnityEngine.VR.VRNode.TrackingReference, then we would not have to depend on the OVRCameraRig. Unfortunately, it is not available in Unity 5.4.3

        OVRPose headPose = OVRPose.identity;

        Vector3    pos;
        Quaternion rot;

        if (OVRNodeStateProperties.GetNodeStatePropertyVector3(Node.Head, NodeStatePropertyType.Position, OVRPlugin.Node.Head, OVRPlugin.Step.Render, out pos))
        {
            headPose.position = pos;
        }
        if (OVRNodeStateProperties.GetNodeStatePropertyQuaternion(Node.Head, NodeStatePropertyType.Orientation, OVRPlugin.Node.Head, OVRPlugin.Step.Render, out rot))
        {
            headPose.orientation = rot;
        }

        OVRPose   invHeadPose   = headPose.Inverse();
        Matrix4x4 invHeadMatrix = Matrix4x4.TRS(invHeadPose.position, invHeadPose.orientation, Vector3.one);

        Matrix4x4 ret = centerEyeAnchor.localToWorldMatrix * invHeadMatrix;

        return(ret);
    }
Exemplo n.º 3
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);

            if (m_grabbedObj.GrabbableType == GrabbableType.Lever)
            {
                linearVelocity  = Vector3.zero;
                angularVelocity = Vector3.zero;
            }

            GrabbableRelease(linearVelocity, angularVelocity);
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 4
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_grabbedObj.grabbedRigidbody.MoveRotation(Quaternion.Euler(0,0,0));
            if (!m_grabbedObj.isGun)
            {
                m_grabbedObj.grabbedTransform.localRotation = Quaternion.Euler(0, 0, 0);
            }
            GrabbableRelease(linearVelocity, angularVelocity);
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 5
0
    private void GrabEnd()
    {
        OVRPose localPose = new OVRPose {
            position = OVRInput.GetLocalControllerPosition(m_OVRController), orientation = OVRInput.GetLocalControllerRotation(m_OVRController)
        };

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

        angularVelocity *= -1;

        m_grabbedObject.GrabEnd(this, linearVelocity, angularVelocity);

        // We also shoot out an event that tells our event system that something was let go
        switch (m_OVRController)
        {
        case (OVRInput.Controller.LTouch):
            CustomEvents.current.LeftGrabbedTurnedOff(m_grabbedObject);
            break;

        case (OVRInput.Controller.RTouch):
            CustomEvents.current.RightGrabbedTurnedOff(m_grabbedObject);
            break;
        }
        CustomEvents.current.GrabbedTurnedOff(this, OVRController, m_grabbedObject);

        m_grabbedObject = null;
    }
Exemplo n.º 6
0
    protected void GrabEnd()
    {
        if (m_grabbedObj != null)
        {
            if (m_grabbedObj.gameObject.tag == "Dummy")
            {
                DMS.DS_AttemptGrabEnd(m_grabbedObj.gameObject);
            }
            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);
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 7
0
    protected void GrabEnd()
    {
        /**///ボールを離したとき
        ballcatch = false;
        /**/

        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 * speed, angularVelocity * curve);//ボールを離した後に進む直線方向の速度を加速させている。
            /**/
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
    void UpdateDefaultExternalCamera()
    {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || OVR_ANDROID_MRC
        // always build a 1080p external camera
        const int   cameraPixelWidth  = 1920;
        const int   cameraPixelHeight = 1080;
        const float cameraAspect      = (float)cameraPixelWidth / cameraPixelHeight;


        string cameraName = "UnityExternalCamera";
        OVRPlugin.CameraIntrinsics cameraIntrinsics = new OVRPlugin.CameraIntrinsics();
        OVRPlugin.CameraExtrinsics cameraExtrinsics = new OVRPlugin.CameraExtrinsics();

        // intrinsics

        cameraIntrinsics.IsValid = OVRPlugin.Bool.True;
        cameraIntrinsics.LastChangedTimeSeconds = Time.time;

        float          vFov = defaultExternalCamera.fieldOfView * Mathf.Deg2Rad;
        float          hFov = Mathf.Atan(Mathf.Tan(vFov * 0.5f) * cameraAspect) * 2.0f;
        OVRPlugin.Fovf fov  = new OVRPlugin.Fovf();
        fov.UpTan   = fov.DownTan = Mathf.Tan(vFov * 0.5f);
        fov.LeftTan = fov.RightTan = Mathf.Tan(hFov * 0.5f);

        cameraIntrinsics.FOVPort = fov;
        cameraIntrinsics.VirtualNearPlaneDistanceMeters = defaultExternalCamera.nearClipPlane;
        cameraIntrinsics.VirtualFarPlaneDistanceMeters  = defaultExternalCamera.farClipPlane;
        cameraIntrinsics.ImageSensorPixelResolution.w   = cameraPixelWidth;
        cameraIntrinsics.ImageSensorPixelResolution.h   = cameraPixelHeight;

        // extrinsics

        cameraExtrinsics.IsValid = OVRPlugin.Bool.True;
        cameraExtrinsics.LastChangedTimeSeconds = Time.time;
        cameraExtrinsics.CameraStatusData       = OVRPlugin.CameraStatus.CameraStatus_Calibrated;
        cameraExtrinsics.AttachedToNode         = OVRPlugin.Node.None;

        Camera       mainCamera = Camera.main;
        OVRCameraRig cameraRig  = mainCamera.GetComponentInParent <OVRCameraRig>();
        if (cameraRig)
        {
            Transform trackingSpace     = cameraRig.trackingSpace;
            OVRPose   trackingSpacePose = trackingSpace.ToOVRPose(false);
            OVRPose   cameraPose        = defaultExternalCamera.transform.ToOVRPose(false);
            OVRPose   relativePose      = trackingSpacePose.Inverse() * cameraPose;
            cameraExtrinsics.RelativePose = relativePose.ToPosef();
        }
        else
        {
            cameraExtrinsics.RelativePose = OVRPlugin.Posef.identity;
        }

        if (!OVRPlugin.SetDefaultExternalCamera(cameraName, ref cameraIntrinsics, ref cameraExtrinsics))
        {
            Debug.LogError("SetDefaultExternalCamera() failed");
        }
#endif
    }
Exemplo n.º 9
0
    protected void GrabEnd()
    {
        if (m_grabbedObj != null)
        {
            //Drop the food away from mouth ------------------------
            GameObject grabbed = m_grabbedObj.gameObject;
            if (grabbed.CompareTag("Shrimp"))
            {
                InputManager.GetComponent <InputManager>().ShrimpGrabbed = false;
                InputManager.GetComponent <InputManager>().ResetShrimp();
                GrabbableRelease(Vector3.zero, Vector3.zero);
                GrabVolumeEnable(true);
                return;
            }
            else if (grabbed.CompareTag("Watermelon"))
            {
                InputManager.GetComponent <InputManager>().WatermelonGrabbed = false;
                InputManager.GetComponent <InputManager>().ResetWatermelon();
                GrabbableRelease(Vector3.zero, Vector3.zero);
                GrabVolumeEnable(true);
                return;
            }
            else if (grabbed.CompareTag("Large"))
            {
                AudioManager.GetComponent <AudioManagement>().Play("Throw");
            }

            //-----------------------------------------------------


            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);

            float scale = Player.transform.localScale.y;

            if (GameplayManager.GetComponent <GameplayManager>().SceneNumber == 2)
            {
                GrabbableRelease(Vector3.zero, Vector3.zero);
            }
            else
            {
                GrabbableRelease(linearVelocity * scale, angularVelocity * scale);
            }
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 10
0
    private void GrabEnd()
    {
        OVRPose localPose = new OVRPose {
            position = OVRInput.GetLocalControllerPosition(m_OVRController), orientation = OVRInput.GetLocalControllerRotation(m_OVRController)
        };

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

        angularVelocity *= -1;

        m_grabbedObject.GrabEnd(this, linearVelocity, angularVelocity);
        m_grabbedObject = null;
    }
Exemplo n.º 11
0
    public void VelocityCounter()
    {
        OVRPose localPose = new OVRPose {
            position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
        };                                                                                                                                                                 //What is controller pos/rot
        OVRPose offsetPose = new OVRPose {
            position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation
        };                                  //What is original pos/rot

        localPose = localPose * offsetPose; //Multiply both vectors & quaternion's
        OVRPose trackingSpace = transform.ToOVRPose() * localPose.Inverse();

        //All that these lines do is take the velocity of the hand (which happens to the velocity of our ball) and
        //Removes the local velocity and instead puts it into global space.  Works like a charm Mr. Hidinger!

        velocityBuffer.PushFront(trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_controller));
        angularBuffer.PushFront(trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_controller));
        //Take the velocity from the controller and orient it correctly for the ball being thrown
    }
Exemplo n.º 12
0
    protected void GrabEnd()
    {
        Debug.Log("GrabEnd Grabber");
        if (m_grabbedObj != null)
        {
            myGrabMoveCount = 0;

            if (m_grabbedObj.tag == "Hold")
            {
                FuncMoveStation();
//?				myGrabPos0 = Vector3.zero;
            }

            if (m_grabbedObj.tag == "Cap")
            {
                FuncOpenCap();
            }

            OVRPose localPose = new OVRPose {
                position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
            };
            OVRPose offsetPose = new OVRPose {
                position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation
            };
            Debug.Log("localPose.position= " + localPose.position.ToString("F4"));
            Debug.Log("localPose.orientation= " + localPose.orientation.ToString("F4"));
            Debug.Log("offsetPose.position= " + offsetPose.position.ToString("F4"));
            Debug.Log("offsetPose.orientation= " + offsetPose.orientation.ToString("F4"));

            localPose = localPose * offsetPose;
            // 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);
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 13
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();
            OVRPose localVelocity = new OVRPose()
            {
                position = OVRInput.GetLocalControllerVelocity(m_controller), orientation = OVRInput.GetLocalControllerAngularVelocity(m_controller)
            };
            Vector3 linearVelocity = trackingSpace.orientation * localVelocity.position;
            //Vector3 angularVelocity = (trackingSpace.orientation * localVelocity.orientation).eulerAngles * Mathf.Deg2Rad;

            /*
             *          if (angularVelocity.x > Mathf.PI)
             *                  angularVelocity.x -= 2f * Mathf.PI;
             *          if (angularVelocity.y > Mathf.PI)
             *                  angularVelocity.y -= 2f * Mathf.PI;
             *          if (angularVelocity.z > Mathf.PI)
             *                  angularVelocity.z -= 2f * Mathf.PI;
             */
            float      angleInDegrees;
            Vector3    rotationAxis;
            Quaternion rotationAsQuat = trackingSpace.orientation * localVelocity.orientation;
            rotationAsQuat.ToAngleAxis(out angleInDegrees, out rotationAxis);

            Vector3 angularDisplacement = rotationAxis * angleInDegrees * Mathf.Deg2Rad;

            GrabbableRelease(linearVelocity, angularDisplacement);
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 14
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);


            if (m_grabbedObj.isFixed)
            {
                OVRCameraRig rig = transform.parent.parent.GetComponent <OVRCameraRig>();

                rig.UpdatedAnchors        -= updateWheel;
                OvrAvatar.lockedHand       = null;
                OvrAvatar.lockedController = null;
                m_hand.parent            = localAvatar;
                m_controllerPoint.parent = localAvatar;
                rig.UpdatedAnchors      += updateAnchor;

                //enable recovering
                m_grabbedObj.GetComponent <wheelAuto>().setRecovering = true;
                GrabbableRelease(Vector3.zero, Vector3.zero);
            }
            else
            {
                GrabbableRelease(linearVelocity, angularVelocity);
            }
        }

        // Re-enable grab volumes to allow overlap events
        GrabVolumeEnable(true);
    }
Exemplo n.º 15
0
        protected void GrabEnd()
        {
            if (_grabbedObj != null)
            {
                OVRPose localPose = new OVRPose {
                    position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller)
                };
                OVRPose offsetPose = new OVRPose {
                    position = _anchorOffsetPosition, orientation = _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);
            }

            GrabVolumeEnable(true);
        }
Exemplo n.º 16
0
 protected void GrabEnd()
 {
     if (this.m_grabbedObj != null)
     {
         OVRPose lhs = new OVRPose
         {
             position    = OVRInput.GetLocalControllerPosition(this.m_controller),
             orientation = OVRInput.GetLocalControllerRotation(this.m_controller)
         };
         OVRPose rhs = new OVRPose
         {
             position    = this.m_anchorOffsetPosition,
             orientation = this.m_anchorOffsetRotation
         };
         lhs *= rhs;
         OVRPose ovrpose         = base.transform.ToOVRPose(false) * lhs.Inverse();
         Vector3 linearVelocity  = ovrpose.orientation * OVRInput.GetLocalControllerVelocity(this.m_controller);
         Vector3 angularVelocity = ovrpose.orientation * OVRInput.GetLocalControllerAngularVelocity(this.m_controller);
         this.GrabbableRelease(linearVelocity, angularVelocity);
     }
     this.GrabVolumeEnable(true);
 }
Exemplo n.º 17
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();
            OVRPose localVelocity = new OVRPose()
            {
                position = OVRInput.GetLocalControllerVelocity(m_controller), orientation = OVRInput.GetLocalControllerAngularVelocity(m_controller)
            };
            Vector3 linearVelocity  = trackingSpace.orientation * localVelocity.position;
            Vector3 angularVelocity = (trackingSpace.orientation * localVelocity.orientation).eulerAngles * Mathf.Deg2Rad;

            if (angularVelocity.x > Mathf.PI)
            {
                angularVelocity.x -= 2f * Mathf.PI;
            }
            if (angularVelocity.y > Mathf.PI)
            {
                angularVelocity.y -= 2f * Mathf.PI;
            }
            if (angularVelocity.z > Mathf.PI)
            {
                angularVelocity.z -= 2f * Mathf.PI;
            }

            GrabbableRelease(linearVelocity, angularVelocity);
        }

        // Re-enable grab volumes to allow overlap events
        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;
    }
Exemplo n.º 19
0
    /// <summary>
    /// Converts the given pose from tracking-space to world-space.
    /// </summary>
    public static OVRPose ToWorldSpacePose(OVRPose trackingSpacePose)
    {
        OVRPose headPose = OVRPose.identity;

        Vector3    pos;
        Quaternion rot;

        if (OVRNodeStateProperties.GetNodeStatePropertyVector3(Node.Head, NodeStatePropertyType.Position, OVRPlugin.Node.Head, OVRPlugin.Step.Render, out pos))
        {
            headPose.position = pos;
        }
        if (OVRNodeStateProperties.GetNodeStatePropertyQuaternion(Node.Head, NodeStatePropertyType.Orientation, OVRPlugin.Node.Head, OVRPlugin.Step.Render, out rot))
        {
            headPose.orientation = rot;
        }

        // Transform from tracking-Space to head-Space
        OVRPose poseInHeadSpace = headPose.Inverse() * trackingSpacePose;

        // Transform from head space to world space
        OVRPose ret = Camera.main.transform.ToOVRPose() * poseInHeadSpace;

        return(ret);
    }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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);
    }
Exemplo n.º 22
0
    public void GrabEnd()
    {
        EVRA_Grabber otherGrabberRef = m_OtherGrabVolume;

        RemoveOtherGrabVolume();

        if (!m_grabbed)
        {
            return;               // If no objects currently grabbed, end quickly
        }
        // There are two situations:
        // 1) the grabbed object has only one hand grabbing it (aka this one)
        // 2) the grabbed object has two hands grabbing it

        // 1) We need to call `GrabEnd()` with the appropriate linear and angular velocity
        // 2) We need to switch parenting over to the other hand via `SwitchHand()`. To tell if there is another grab volume grabbing the object, we just check if m_OtherGrabVolume is not null

        if (otherGrabberRef)
        {
            // If we have an other grabber ref, then that means that multiple objects are holding the current item.
            // Now, technically, it can be either the initial holder of the item or the rotation ref.
            // If it's the initial holder, then we let go AND transfer possession to the other grab volume
            // If it's just the rotation ref, then we just need to decouple the other grab volume - we don't need to let go of it.
            if (m_grabbed.GrabbableRef.currentGrabber == this)
            {
                //otherGrabberRef.transform.localRotation = Quaternion.Euler(0f,0f,0f);
                m_grabbed.GrabbableRef.SwitchHand(otherGrabberRef);
                //m_grabbed.GrabbableRef.GrabEnd();
            }
            otherGrabberRef.RemoveOtherGrabVolume();
            //if (m_grabbed.GrabbableRef.currentGrabber.grabbed != m_grabbed) m_grabbed.GrabbableRef.currentGrabber.RemoveOtherGrabVolume();
        }
        else
        {
            OVRPose localPose = new OVRPose {
                position = OVRInput.GetLocalControllerPosition(m_CustomGrabber.OVRController), orientation = OVRInput.GetLocalControllerRotation(m_CustomGrabber.OVRController)
            };
            OVRPose trackingSpace   = transform.ToOVRPose() * localPose.Inverse();
            Vector3 linearVelocity  = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_CustomGrabber.OVRController);
            Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_CustomGrabber.OVRController);
            angularVelocity *= -1;
            m_grabbed.GrabbableRef.GrabEnd(linearVelocity, angularVelocity);
            //m_grabbed.GrabbableRef.currentGrabber.RemoveOtherGrabVolume();
        }

        /*
         * if (m_grabbed.GrabbableRef.currentGrabber && m_grabbed.GrabbableRef.currentGrabber.OtherGrabVolume) {
         *  if (m_grabbed.GrabbableRef.currentGrabber.grabbed && m_grabbed.GrabbableRef.currentGrabber.grabbed != m_grabbed) m_grabbed.GrabbableRef.currentGrabber.RemoveOtherGrabVolume();
         * }
         * if (m_grabbed.GrabbableRef.currentGrabber == this) {
         *  OVRPose localPose = new OVRPose { position = OVRInput.GetLocalControllerPosition(m_CustomGrabber.OVRController), orientation = OVRInput.GetLocalControllerRotation(m_CustomGrabber.OVRController) };
         *  OVRPose trackingSpace = transform.ToOVRPose() * localPose.Inverse();
         *  Vector3 linearVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_CustomGrabber.OVRController);
         *  Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_CustomGrabber.OVRController);
         *  angularVelocity *= -1;
         *  m_grabbed.GrabbableRef.GrabEnd(linearVelocity,angularVelocity);
         * }
         */
        transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
        m_grabbed = null;
    }
Exemplo n.º 23
0
        void Update()
        {
            if (!calibratedCameraPose.HasValue)
            {
                if (!OVRPlugin.Media.GetInitialized())
                {
                    return;
                }

                OVRPlugin.CameraIntrinsics cameraIntrinsics;
                OVRPlugin.CameraExtrinsics cameraExtrinsics;

                if (OVRPlugin.GetMixedRealityCameraInfo(0, out cameraExtrinsics, out cameraIntrinsics))
                {
                    calibratedCameraPose = cameraExtrinsics.RelativePose.ToOVRPose();
                }
                else
                {
                    return;
                }
            }

            OVRPose cameraStagePoseInUnits = calibratedCameraPose.Value;

            // Converting position from meters to decimeters (unit used by Open Brush)
            cameraStagePoseInUnits.position *= App.METERS_TO_UNITS;

            // Workaround to fix the OVRExtensions.ToWorldSpacePose() and
            // OVRComposition.ComputeCameraWorldSpacePose() calls when computing
            // the Mixed Reality foreground and background camera positions.
            OVRPose headPose = OVRPose.identity;

            Vector3    pos;
            Quaternion rot;

            if (OVRNodeStateProperties.GetNodeStatePropertyVector3(Node.Head,
                                                                   NodeStatePropertyType.Position, OVRPlugin.Node.Head, OVRPlugin.Step.Render, out pos))
            {
                headPose.position = pos;
            }

            if (OVRNodeStateProperties.GetNodeStatePropertyQuaternion(Node.Head,
                                                                      NodeStatePropertyType.Orientation, OVRPlugin.Node.Head, OVRPlugin.Step.Render, out rot))
            {
                headPose.orientation = rot;
            }

            OVRPose headPoseInUnits = OVRPose.identity;

            headPoseInUnits.position    = headPose.position * App.METERS_TO_UNITS;
            headPoseInUnits.orientation = headPose.orientation;

            OVRPose stageToLocalPose = OVRPlugin.GetTrackingTransformRelativePose(
                OVRPlugin.TrackingOrigin.Stage).ToOVRPose();

            OVRPose stageToLocalPoseInUnits = OVRPose.identity;

            stageToLocalPoseInUnits.position    = stageToLocalPose.position * App.METERS_TO_UNITS;
            stageToLocalPoseInUnits.orientation = stageToLocalPose.orientation;

            OVRPose cameraWorldPoseInUnits = headPoseInUnits.Inverse() * stageToLocalPoseInUnits *
                                             cameraStagePoseInUnits;
            OVRPose cameraStagePoseFix = stageToLocalPose.Inverse() * headPose * cameraWorldPoseInUnits;

            // Override the MRC camera's stage pose
            OVRPlugin.OverrideExternalCameraStaticPose(0, true, cameraStagePoseFix.ToPosef());
        }
    public override void Update(GameObject gameObject, Camera mainCamera)
    {
        RefreshCameraObjects(gameObject, mainCamera);

        OVRPlugin.SetHandNodePoseStateLatency(0.0);             // the HandNodePoseStateLatency doesn't apply to the external composition. Always enforce it to 0.0

        // For third-person camera to use for calculating camera position with different anchors
        OVRPose stageToLocalPose = OVRPlugin.GetTrackingTransformRelativePose(OVRPlugin.TrackingOrigin.Stage).ToOVRPose();
        OVRPose localToStagePose = stageToLocalPose.Inverse();
        OVRPose head             = localToStagePose * OVRPlugin.GetNodePose(OVRPlugin.Node.Head, OVRPlugin.Step.Render).ToOVRPose();
        OVRPose leftC            = localToStagePose * OVRPlugin.GetNodePose(OVRPlugin.Node.HandLeft, OVRPlugin.Step.Render).ToOVRPose();
        OVRPose rightC           = localToStagePose * OVRPlugin.GetNodePose(OVRPlugin.Node.HandRight, OVRPlugin.Step.Render).ToOVRPose();

        OVRPlugin.Media.SetMrcHeadsetControllerPose(head.ToPosef(), leftC.ToPosef(), rightC.ToPosef());

#if OVR_ANDROID_MRC
        RefreshAudioFilter();

        int drawTextureIndex = (frameIndex / 2) % 2;
        int castTextureIndex = 1 - drawTextureIndex;

        backgroundCamera.enabled = (frameIndex % 2) == 0;
        foregroundCamera.enabled = (frameIndex % 2) == 1;

        if (frameIndex % 2 == 0)
        {
            if (lastMrcEncodeFrameSyncId != -1)
            {
                OVRPlugin.Media.SyncMrcFrame(lastMrcEncodeFrameSyncId);
                lastMrcEncodeFrameSyncId = -1;
            }
            lastMrcEncodeFrameSyncId = CastMrcFrame(castTextureIndex);
            SetCameraTargetTexture(drawTextureIndex);
        }

        ++frameIndex;
#endif

        backgroundCamera.clearFlags      = mainCamera.clearFlags;
        backgroundCamera.backgroundColor = mainCamera.backgroundColor;
        backgroundCamera.cullingMask     = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        backgroundCamera.nearClipPlane   = mainCamera.nearClipPlane;
        backgroundCamera.farClipPlane    = mainCamera.farClipPlane;

        foregroundCamera.cullingMask   = mainCamera.cullingMask & (~OVRManager.instance.extraHiddenLayers);
        foregroundCamera.nearClipPlane = mainCamera.nearClipPlane;
        foregroundCamera.farClipPlane  = mainCamera.farClipPlane;

        if (OVRMixedReality.useFakeExternalCamera || OVRPlugin.GetExternalCameraCount() == 0)
        {
            OVRPose worldSpacePose    = new OVRPose();
            OVRPose trackingSpacePose = new OVRPose();
            trackingSpacePose.position = OVRManager.instance.trackingOriginType == OVRManager.TrackingOrigin.EyeLevel ?
                                         OVRMixedReality.fakeCameraEyeLevelPosition :
                                         OVRMixedReality.fakeCameraFloorLevelPosition;
            trackingSpacePose.orientation = OVRMixedReality.fakeCameraRotation;
            worldSpacePose = OVRExtensions.ToWorldSpacePose(trackingSpacePose);

            backgroundCamera.fieldOfView = OVRMixedReality.fakeCameraFov;
            backgroundCamera.aspect      = OVRMixedReality.fakeCameraAspect;
            foregroundCamera.fieldOfView = OVRMixedReality.fakeCameraFov;
            foregroundCamera.aspect      = OVRMixedReality.fakeCameraAspect;

            if (cameraInTrackingSpace)
            {
                backgroundCamera.transform.FromOVRPose(trackingSpacePose, true);
                foregroundCamera.transform.FromOVRPose(trackingSpacePose, true);
            }
            else
            {
                backgroundCamera.transform.FromOVRPose(worldSpacePose);
                foregroundCamera.transform.FromOVRPose(worldSpacePose);
            }
        }
        else
        {
            OVRPlugin.CameraExtrinsics extrinsics;
            OVRPlugin.CameraIntrinsics intrinsics;

            // So far, only support 1 camera for MR and always use camera index 0
            if (OVRPlugin.GetMixedRealityCameraInfo(0, out extrinsics, out intrinsics))
            {
                float fovY   = Mathf.Atan(intrinsics.FOVPort.UpTan) * Mathf.Rad2Deg * 2;
                float aspect = intrinsics.FOVPort.LeftTan / intrinsics.FOVPort.UpTan;
                backgroundCamera.fieldOfView = fovY;
                backgroundCamera.aspect      = aspect;
                foregroundCamera.fieldOfView = fovY;
                foregroundCamera.aspect      = intrinsics.FOVPort.LeftTan / intrinsics.FOVPort.UpTan;

                if (cameraInTrackingSpace)
                {
                    OVRPose trackingSpacePose = ComputeCameraTrackingSpacePose(extrinsics);
                    backgroundCamera.transform.FromOVRPose(trackingSpacePose, true);
                    foregroundCamera.transform.FromOVRPose(trackingSpacePose, true);
                }
                else
                {
                    OVRPose worldSpacePose = ComputeCameraWorldSpacePose(extrinsics);
                    backgroundCamera.transform.FromOVRPose(worldSpacePose);
                    foregroundCamera.transform.FromOVRPose(worldSpacePose);
                }
#if OVR_ANDROID_MRC
                cameraPoseTimeArray[drawTextureIndex] = extrinsics.LastChangedTimeSeconds;
#endif
            }
            else
            {
                Debug.LogError("Failed to get external camera information");
                return;
            }
        }

        Vector3 headToExternalCameraVec = mainCamera.transform.position - foregroundCamera.transform.position;
        float   clipDistance            = Vector3.Dot(headToExternalCameraVec, foregroundCamera.transform.forward);
        foregroundCamera.farClipPlane = Mathf.Max(foregroundCamera.nearClipPlane + 0.001f, clipDistance);
    }
    // Update is called once per frame
    void Update()
    {
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || OVR_ANDROID_MRC
        if (!inited)
        {
            Initialize();
            return;
        }

        if (!defaultExternalCamera)
        {
            return;
        }

#if OVR_ANDROID_MRC
        if (!OVRPlugin.Media.GetInitialized())
        {
            return;
        }
#else
        if (!OVRPlugin.IsMixedRealityInitialized())
        {
            return;
        }
#endif

        if (OVRInput.GetDown(OVRInput.Button.One))
        {
            if (currentMode == CameraMode.ThirdPerson)
            {
                currentMode = CameraMode.Normal;
            }
            else
            {
                currentMode = currentMode + 1;
            }

            Debug.LogFormat("Camera mode change to {0}", currentMode);
        }

        if (currentMode == CameraMode.Normal)
        {
            UpdateDefaultExternalCamera();
            OVRPlugin.OverrideExternalCameraFov(0, false, new OVRPlugin.Fovf());
            OVRPlugin.OverrideExternalCameraStaticPose(0, false, OVRPlugin.Posef.identity);
        }
        else if (currentMode == CameraMode.OverrideFov)
        {
            OVRPlugin.Fovf fov    = defaultFov;
            OVRPlugin.Fovf newFov = new OVRPlugin.Fovf();
            newFov.LeftTan  = fov.LeftTan * 2.0f;
            newFov.RightTan = fov.RightTan * 2.0f;
            newFov.UpTan    = fov.UpTan * 2.0f;
            newFov.DownTan  = fov.DownTan * 2.0f;

            OVRPlugin.OverrideExternalCameraFov(0, true, newFov);
            OVRPlugin.OverrideExternalCameraStaticPose(0, false, OVRPlugin.Posef.identity);

            if (!OVRPlugin.GetUseOverriddenExternalCameraFov(0))
            {
                Debug.LogWarning("FOV not overridden");
            }
        }
        else if (currentMode == CameraMode.ThirdPerson)
        {
            Camera camera = GetComponent <Camera>();
            if (camera == null)
            {
                return;
            }

            float          vFov = camera.fieldOfView * Mathf.Deg2Rad;
            float          hFov = Mathf.Atan(Mathf.Tan(vFov * 0.5f) * camera.aspect) * 2.0f;
            OVRPlugin.Fovf fov  = new OVRPlugin.Fovf();
            fov.UpTan   = fov.DownTan = Mathf.Tan(vFov * 0.5f);
            fov.LeftTan = fov.RightTan = Mathf.Tan(hFov * 0.5f);
            OVRPlugin.OverrideExternalCameraFov(0, true, fov);

            Camera       mainCamera = Camera.main;
            OVRCameraRig cameraRig  = mainCamera.GetComponentInParent <OVRCameraRig>();
            if (cameraRig)
            {
                Transform       trackingSpace     = cameraRig.trackingSpace;
                OVRPose         trackingSpacePose = trackingSpace.ToOVRPose(false);
                OVRPose         cameraPose        = transform.ToOVRPose(false);
                OVRPose         relativePose      = trackingSpacePose.Inverse() * cameraPose;
                OVRPlugin.Posef relativePosef     = relativePose.ToPosef();
                OVRPlugin.OverrideExternalCameraStaticPose(0, true, relativePosef);
            }
            else
            {
                OVRPlugin.OverrideExternalCameraStaticPose(0, false, OVRPlugin.Posef.identity);
            }

            if (!OVRPlugin.GetUseOverriddenExternalCameraFov(0))
            {
                Debug.LogWarning("FOV not overridden");
            }

            if (!OVRPlugin.GetUseOverriddenExternalCameraStaticPose(0))
            {
                Debug.LogWarning("StaticPose not overridden");
            }
        }
#endif
    }