Exemplo n.º 1
0
    void Update()
    {
        // Check if the system is currently streaming
        if (rtClient.GetStreamingStatus())
        {
            // Get the data of the tracked object based on the name supplied
            SixDOFBody trackedObj = rtClient.GetBody(objectName);

            // If this object has a position value, that means it's tracked!
            if (!float.IsNaN(trackedObj.Position.sqrMagnitude))
            {
                // Apply the position and rotation to the object
                transform.position = trackedObj.Position;
                transform.rotation = trackedObj.Rotation;
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (updateTimer > 0)
        {
            updateTimer -= Time.deltaTime;
        }

        if (rtClient.GetStreamingStatus())
        {
            SixDOFBody trackedObj = rtClient.GetBody(objectName);

            if (!float.IsNaN(trackedObj.Position.sqrMagnitude))
            {
                transform.position = trackedObj.Position;
                transform.rotation = trackedObj.Rotation;
            }
        }
    }
Exemplo n.º 3
0
        /// <summary>
        /// ...
        /// </summary>
        void LateUpdate()
        {
            if (eyeAnchor == null)
            {
                return;
            }

            // Get streamed rigid body definition of rift
            if (useRiftRigidBody && RTClient.GetInstance().GetStreamingStatus())
            {
                SixDOFBody rift = RTClient.GetInstance().GetBody(bodyName);
                if (rift != null && !rift.Rotation.Convert().IsNaN())
                {
                    sixDOFBodyRotation = new Quaternion(rift.Rotation.x, rift.Rotation.y, rift.Rotation.z, rift.Rotation.w);

                    // Reorientate the camera rig to match the 6 DOF coordinate system
                    if (
                        useInternalTracking &&
                        needsCameraRigReorientation &&
                        sixDOFBodyRotation != Quaternion.identity
                        )
                    {
                        Debug.Log("Calibrating Oculus Rift Pose...");
                        Debug.Log("Rift rotation " + rift.Rotation.eulerAngles);
                        Debug.Log("Anchor rotation " + eyeAnchor.localEulerAngles);

                        // Align the camera rig coordinate system to the QTM coordinate system by a rotation over the y-axis
                        //offsetAngle = (360 - eyeAnchor.eulerAngles.y) + sixDOFBodyRotation.eulerAngles.y;
                        //offsetAngle = eyeAnchor.localEulerAngles.y + sixDOFBodyRotation.eulerAngles.y + 180; // 180 cause of the rigid body axes
                        offsetAngle = 180 + sixDOFBodyRotation.eulerAngles.y - eyeAnchor.localEulerAngles.y;

                        // Enable avatar mesh
                        foreach (SkinnedMeshRenderer renderer in renderers)
                        {
                            renderer.enabled = true;
                        }

                        // OVR global coordinate system is calibrated
                        needsCameraRigReorientation = false;
                    }

                    // Show mirrored avatar when camera rig is orientated
                    if (showMirror)
                    {
                        mirroredCharacterJoints.root.gameObject.SetActive(true);
                    }

                    //RTClient.GetInstance().SetStatusMessage("OCULUS_RIFT", "", true);
                }
                else
                {
                    //RTClient.GetInstance().SetStatusMessage("OCULUS_RIFT", "", false);
                }
            }
            else if (!useRiftRigidBody && showMirror)
            {
                mirroredCharacterJoints.root.gameObject.SetActive(true);
            }

            // Get avatars head
            Transform head   = characterJoints.head;
            Vector3   lookAt = eyeAnchor.forward * 10.0f;

            // Set head orientation to rift orientation and position the camera rig in front of the head
            if (useInternalTracking)
            {
                head.rotation = eyeAnchor.rotation;
                cameraRig.transform.eulerAngles = new Vector3(0, this.transform.eulerAngles.y + offsetAngle, 0);
                //cameraRig.transform.position = head.position + head.rotation * cameraOffset;
                //cameraRig.transform.localPosition = head.position + cameraRig.transform.rotation * cameraOffset;
                //cameraRig.transform.localPosition = head.position + eyeAnchor.rotation * cameraOffset;
                // Need to substract the position of the eye anchor
                cameraRig.transform.localPosition =
                    head.position
                    - cameraRig.transform.rotation * eyeAnchor.localPosition
                    + eyeAnchor.rotation * cameraOffset;
            }
            else
            {
                head.localRotation = sixDOFBodyRotation;
            }

            // Draw debug ray in look direction
            Debug.DrawRay(eyeAnchor.position, lookAt, Color.green);

            // Set pose of the mirrored avatar
            if (showMirror)
            {
                setMirroredAvatarPose();
            }
        }