Beispiel #1
0
        /// <summary>
        /// Unity engine object Update() hook
        /// </summary>
        private void Update()
        {
            if (!isClosing)
            {
                if (!IsStereo)
                {
                    LeftEye.transform.position = location;
                    LeftEye.transform.LookAt(lookAt, up);
                    this.LeftEye.Render();
                    StartCoroutine(SendFrame(false));
                }
                else if (cameraNeedUpdated)
                {
                    this.LeftEye.projectionMatrix  = stereoLeftProjectionMatrix;
                    this.RightEye.projectionMatrix = stereoRightProjectionMatrix;
                    this.LeftEye.Render();
                    this.RightEye.Render();
                    StartCoroutine(SendFrame(true));
                }
            }

            // if the eye config changes, reconfigure
            if (this.lastSetupVisibleEyes.HasValue &&
                this.lastSetupVisibleEyes.Value != this.IsStereo)
            {
                SetupActiveEyes();
            }

            // check if we're in the editor, and fail out if we aren't loading the plugin in editor
            if (Application.isEditor && !UseEditorNativePlugin)
            {
                return;
            }

            // if we got an offer, track that we're connected to them
            // in a way that won't trip our connection logic (we don't
            // want to accidently make them an offer, just an answer)
            if (offerPeer.HasValue && offerSucceeded)
            {
                previousPeer          = PeerList.Peers.First(p => p.Id == offerPeer.Value);
                PeerList.SelectedPeer = previousPeer;
            }

            // check if we need to connect to a peer, and if so, do it
            if ((previousPeer == null && PeerList.SelectedPeer != null) ||
                (previousPeer != null && PeerList.SelectedPeer != null && !previousPeer.Equals(PeerList.SelectedPeer)))
            {
                Plugin.ConnectToPeer(PeerList.SelectedPeer.Id);
                previousPeer = PeerList.SelectedPeer;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Unity engine object Update() hook
        /// </summary>
        private void Update()
        {
            if (!isClosing)
            {
                transform.position = location;
                transform.LookAt(lookAt, up);

                // apply stereo projection if needed
                if (this.IsStereo &&
                    !stereoLeftProjection.isIdentity &&
                    !stereoRightProjection.isIdentity)
                {
                    this.LeftEye.SetStereoProjectionMatrix(Camera.StereoscopicEye.Left, stereoLeftProjection * this.LeftEye.worldToCameraMatrix);
                    this.RightEye.SetStereoProjectionMatrix(Camera.StereoscopicEye.Right, stereoRightProjection * this.RightEye.worldToCameraMatrix);
                }
            }

            // if the eye config changes, reconfigure
            if (this.lastSetupVisibleEyes.HasValue &&
                this.lastSetupVisibleEyes.Value != this.IsStereo)
            {
                SetupActiveEyes();
            }

            // check if we're in the editor, and fail out if we aren't loading the plugin in editor
            if (Application.isEditor && !UseEditorNativePlugin)
            {
                return;
            }

            // encode the entire render texture at the end of the frame
            StartCoroutine(Plugin.EncodeAndTransmitFrame());

            // if we got an offer, track that we're connected to them
            // in a way that won't trip our connection logic (we don't
            // want to accidently make them an offer, just an answer)
            if (offerPeer.HasValue && offerSucceeded)
            {
                previousPeer          = PeerList.Peers.First(p => p.Id == offerPeer.Value);
                PeerList.SelectedPeer = previousPeer;
            }

            // check if we need to connect to a peer, and if so, do it
            if ((previousPeer == null && PeerList.SelectedPeer != null) ||
                (previousPeer != null && PeerList.SelectedPeer != null && !previousPeer.Equals(PeerList.SelectedPeer)))
            {
                Plugin.ConnectToPeer(PeerList.SelectedPeer.Id);
                previousPeer = PeerList.SelectedPeer;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Default ctor
 /// </summary>
 /// <param name="peer">the peer</param>
 public PeerDropdownOption(PeerListState.Peer peer)
 {
     this.Peer = peer;
     this.text = peer.Name;
 }
Beispiel #4
0
        /// <summary>
        /// Unity engine object Update() hook
        /// </summary>
        private void Update()
        {
            if (!isClosing)
            {
                foreach (var peerData in remotePeersData.Values)
                {
                    // Makes sure that the mono/stereo mode has been set.
                    if (peerData.IsStereo.HasValue)
                    {
                        // Lazily initializes the render textures.
                        if (peerData.LeftRenderTexture == null)
                        {
                            peerData.InitializeRenderTextures();
                        }

                        // Resets to the default transform.
                        SetupActiveEyes(peerData.IsStereo.Value);
                        LeftEye.transform.position    = leftEyeDefaultPosition;
                        LeftEye.transform.eulerAngles = leftEyeDefaultRotation;
                        LeftEye.ResetProjectionMatrix();

                        if (!peerData.IsStereo.Value)
                        {
                            // Enables fps limiter in non-stereo mode.
                            Application.targetFrameRate = 60;

                            LeftEye.targetTexture      = peerData.LeftRenderTexture;
                            LeftEye.transform.position = peerData.EyeVector;
                            LeftEye.transform.LookAt(peerData.LookAtVector, peerData.UpVector);
                            LeftEye.Render();
                        }
                        else if (peerData.IsNew)
                        {
                            // Sets render textures for both eyes.
                            LeftEye.targetTexture  = peerData.LeftRenderTexture;
                            RightEye.targetTexture = peerData.RightRenderTexture;

                            // Updates left and right projection matrices.
                            LeftEye.projectionMatrix  = peerData.stereoLeftProjectionMatrix;
                            RightEye.projectionMatrix = peerData.stereoRightProjectionMatrix;

                            // Updates camera transform's position and rotation.
                            // Converts from right-handed to left-handed coordinates.
                            peerData.stereoLeftViewMatrix  = Matrix4x4.Inverse(peerData.stereoLeftViewMatrix);
                            peerData.stereoRightViewMatrix = Matrix4x4.Inverse(peerData.stereoRightViewMatrix);

                            // Updates transform's position for both eyes.
                            this.LeftEye.transform.position = new Vector3(
                                peerData.stereoLeftViewMatrix.m03,
                                peerData.stereoLeftViewMatrix.m13,
                                -peerData.stereoLeftViewMatrix.m23);

                            this.RightEye.transform.position = new Vector3(
                                peerData.stereoRightViewMatrix.m03,
                                peerData.stereoRightViewMatrix.m13,
                                -peerData.stereoRightViewMatrix.m23);

                            // Updates transform's rotation for both eyes.
                            Quaternion leftQ = QuaternionFromMatrix(peerData.stereoLeftViewMatrix);
                            this.LeftEye.transform.rotation = new Quaternion(
                                -leftQ.x, -leftQ.y, leftQ.z, leftQ.w);

                            Quaternion rightQ = QuaternionFromMatrix(peerData.stereoRightViewMatrix);
                            this.RightEye.transform.rotation = new Quaternion(
                                -rightQ.x, -rightQ.y, rightQ.z, rightQ.w);

                            // Manually render to textures for both eyes.
                            this.LeftEye.Render();
                            this.RightEye.Render();
                        }
                    }
                    else
                    {
                        // Forces non-stereo mode initialization.
                        if (Environment.TickCount - peerData.startTick > StereoFlagWaitTime)
                        {
                            peerData.IsStereo     = false;
                            peerData.EyeVector    = DefaultEyeVector;
                            peerData.LookAtVector = DefaultLookAtVector;
                            peerData.UpVector     = DefaultUpVector;
                        }
                    }
                }

                SendFrame();
            }

            // check if we're in the editor, and fail out if we aren't loading the plugin in editor
            if (Application.isEditor && !UseEditorNativePlugin)
            {
                return;
            }

            // if we got an offer, track that we're connected to them
            // in a way that won't trip our connection logic (we don't
            // want to accidently make them an offer, just an answer)
            if (offerPeer.HasValue && offerSucceeded)
            {
                previousPeer          = PeerList.Peers.First(p => p.Id == offerPeer.Value);
                PeerList.SelectedPeer = previousPeer;
            }

            // check if we need to connect to a peer, and if so, do it
            if ((previousPeer == null && PeerList.SelectedPeer != null) ||
                (previousPeer != null && PeerList.SelectedPeer != null && !previousPeer.Equals(PeerList.SelectedPeer)))
            {
                Plugin.ConnectToPeer(PeerList.SelectedPeer.Id);
                previousPeer = PeerList.SelectedPeer;
            }
        }