Inheritance: global::System.IDisposable
Exemplo n.º 1
0
        void OnTimeOffset(HoloToolkit.Sharing.NetworkInMessage msg)
        {
#if !UNITY_EDITOR
            float eventTime = Time.time;
            msg.ReadInt64();

            int timeOffset = msg.ReadInt32();
            if (timeOffset > 0)
            {
                timeOffset *= -1;
            }

            colorFrameReceivedTimeS = eventTime;
            prevTimeOffsetNS        = timeOffset;

            Vector3    pos;
            Quaternion rot;

            if (GetHeadTransform(WorldManager.GetNativeISpatialCoordinateSystemPtr(),
                                 (int)timeOffset,
                                 out rot.x, out rot.y, out rot.z, out rot.w,
                                 out pos.x, out pos.y, out pos.z))
            {
                // Transform the head position and rotation from world space into local space
                Vector3    HeadPos = this.transform.InverseTransformPoint(pos);
                Quaternion HeadRot = Quaternion.Inverse(this.transform.rotation) * rot;
                SpectatorView.SV_CustomMessages.Instance.SendHeadTransform(HeadPos, HeadRot);
            }
#endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// When a remote system has a transform for us, we'll get it here.
        /// </summary>
        /// <param name="msg"></param>
        void OnSceneTransform(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            msg.ReadInt64();

            transform.localPosition = SpectatorView.SV_CustomMessages.Instance.ReadVector3(msg);
            transform.localRotation = SpectatorView.SV_CustomMessages.Instance.ReadQuaternion(msg);
            transform.localScale    = SpectatorView.SV_CustomMessages.Instance.ReadVector3(msg);
        }
Exemplo n.º 3
0
        void OnColorDuration(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            msg.ReadInt64();

            long duration = msg.ReadInt64();

            colorFrameDurationNS = duration * 100;
        }
Exemplo n.º 4
0
        void OnNetworkTimeSet(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            msg.ReadInt64();

            long time = msg.ReadInt64();

            NetworkTime = time;
        }
Exemplo n.º 5
0
        void OnMessageReceived(NetworkConnection connection, NetworkInMessage msg)
        {
            byte            messageType    = msg.ReadByte();
            MessageCallback messageHandler = MessageHandlers[(TestMessageID)messageType];

            if (messageHandler != null)
            {
                messageHandler(msg);
            }
        }
Exemplo n.º 6
0
        private void ProcessAnchorComplete(NetworkInMessage msg)
        {
            Debug.Log("start");
            long userID = msg.ReadInt64();

            if (SharingStage.Instance.ClientRole == ClientRole.Secondary)
            {
                Debug.Log("Called process anchorcomplete");
                ImportExportAnchorManager.Instance.anchor_ready = true;
            }
        }
    /// <summary>
    /// Process user hit.
    /// </summary>
    /// <param name="msg"></param>
    void ProcessRemoteProjectile(NetworkInMessage msg)
    {
        // Parse the message
        long userID = msg.ReadInt64();
        Vector3 remoteProjectilePosition = CustomMessages.Instance.ReadVector3(msg);

        Vector3 remoteProjectileDirection = CustomMessages.Instance.ReadVector3(msg);

        Transform anchor = ImportExportAnchorManager.Instance.gameObject.transform;
        ShootProjectile(anchor.TransformPoint(remoteProjectilePosition), anchor.TransformDirection(remoteProjectileDirection), userID);
    }
Exemplo n.º 8
0
        private void ProcessAnchorRequest(NetworkInMessage msg)
        {
            long userID = msg.ReadInt64();

            if (SharingStage.Instance.ClientRole == ClientRole.Primary)
            {
                if (ImportExportAnchorManager.Instance.AnchorEstablished)
                {
                    CustomMessages.Instance.SendAnchorComplete();
                }
            }
        }
Exemplo n.º 9
0
        public bool ReadBoolean(NetworkInMessage msg)
        {
            float val = msg.ReadFloat();

            if (val == 1.0f)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Called when a remote user sends a head transform.
        /// </summary>
        /// <param name="msg"></param>
        void UpdateHeadTransform(NetworkInMessage msg)
        {
            // Parse the message
            long userID = msg.ReadInt64();

            Vector3 headPos = CustomMessages.Instance.ReadVector3(msg);

            Quaternion headRot = CustomMessages.Instance.ReadQuaternion(msg);

            RemoteHeadInfo headInfo = GetRemoteHeadInfo(userID);

            headInfo.HeadObject.transform.localPosition = headPos;
            headInfo.HeadObject.transform.localRotation = headRot;
        }
Exemplo n.º 11
0
        void OnSpatialMapping(HoloToolkit.Sharing.NetworkInMessage msg)
        {
#if UNITY_EDITOR
            if (SpatialMappingManager.Instance == null)
            {
                return;
            }

            SpectatorView.RemoteSpatialMappingSource rsms = SpatialMappingManager.Instance.GetComponent <SpectatorView.RemoteSpatialMappingSource>();
            if (rsms == null)
            {
                return;
            }

            msg.ReadInt64();

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector3> normals   = new List <Vector3>();
            List <int>     triangles = new List <int>();

            int vertexCount   = msg.ReadInt32();
            int normalCount   = msg.ReadInt32();
            int triangleCount = msg.ReadInt32();

            for (int i = 0; i < vertexCount; i++)
            {
                Vector3 vertex = SpectatorView.SV_CustomMessages.Instance.ReadVector3(msg);
                vertices.Add(vertex);
            }

            for (int i = 0; i < normalCount; i++)
            {
                Vector3 normal = SpectatorView.SV_CustomMessages.Instance.ReadVector3(msg);
                normals.Add(normal);
            }

            for (int i = 0; i < triangleCount; i++)
            {
                int index = msg.ReadInt32();
                triangles.Add(index);
            }

            SpatialMappingManager.Instance.transform.parent        = transform;
            SpatialMappingManager.Instance.transform.localPosition = Vector3.zero;
            SpatialMappingManager.Instance.transform.localRotation = Quaternion.identity;

            rsms.AddSurface(vertices, normals, triangles);
#endif
        }
Exemplo n.º 12
0
        void OnUpdateSpectatorViewIP(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            msg.ReadInt64();
            string _SpectatorViewIP = SV_CustomMessages.Instance.ReadIP(msg);

            if (SpectatorViewManager.Instance == null || SpectatorView.HolographicCameraManager.Instance == null)
            {
                return;
            }

            if (_SpectatorViewIP != SpectatorViewManager.Instance.SpectatorViewIP)
            {
                Debug.Log("Updating spectator view ip to: " + SpectatorViewManager.Instance.SpectatorViewIP);
                SpectatorViewManager.Instance.SpectatorViewIP = _SpectatorViewIP;
                SpectatorView.HolographicCameraManager.Instance.HolographicCameraIP = SpectatorViewManager.Instance.SpectatorViewIP;
            }
        }
Exemplo n.º 13
0
        void OnNetworkRoundTripTime(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            long userID = msg.ReadInt64();

            long time = msg.ReadInt64();

#if !UNITY_EDITOR
            SpectatorView.SV_CustomMessages.Instance.SendNetworkRoundTripTime(time);
#else
            if (HolographicCameraManager.Instance != null &&
                HolographicCameraManager.Instance.tppcUser != null &&
                HolographicCameraManager.Instance.tppcUser.IsValid() &&
                userID == HolographicCameraManager.Instance.tppcUser.GetID())
            {
                NetworkTime = GetCurrentUnityTime() - time;

                SetNetworkLatency(NetworkTime);
                SpectatorView.SV_CustomMessages.Instance.SendTPPCNetworkTime(NetworkTime);
            }
#endif
        }
Exemplo n.º 14
0
        void OnEditorUser(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            msg.ReadInt64();

            long ipSize = msg.ReadInt64();

            byte[] ipData = new byte[(uint)ipSize];
            msg.ReadArray(ipData, (uint)ipSize);
            string editorIP = System.Text.Encoding.ASCII.GetString(ipData).Trim();

            long editorUserID = msg.ReadInt64();

            if (HolographicCameraManager.Instance.LocalComputerIP.Trim() == String.Empty ||
                HolographicCameraManager.Instance.LocalComputerIP.Trim() == editorIP)
            {
                User user = SharingStage.Instance.SessionUsersTracker.GetUserById((int)editorUserID);
                if (user != null)
                {
                    HolographicCameraManager.Instance.editorUser = user;
                }
            }
        }
Exemplo n.º 15
0
 public int ReadInt(NetworkInMessage msg)
 {
     return(msg.ReadInt32());     // This is a x86 system and therefore should read 32 bits.
 }
        /// <summary>
        /// Now that we've gotten a message, examine it and dissect the audio data.
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="message"></param>
        public void OnMessageReceived(NetworkConnection connection, NetworkInMessage message)
        {
            // Unused byte headerSize
            message.ReadByte();

            Int32 pack = message.ReadInt32();

            // Unused int version
            versionExtractor.GetBitsValue(pack);
            int audioStreamCount = audioStreamCountExtractor.GetBitsValue(pack);
            int channelCount     = channelCountExtractor.GetBitsValue(pack);
            int sampleRate       = sampleRateExtractor.GetBitsValue(pack);
            int sampleType       = sampleTypeExtractor.GetBitsValue(pack);
            int bytesPerSample   = sizeof(float);

            if (sampleType == 1)
            {
                bytesPerSample = sizeof(Int16);
            }

            int sampleCount = sampleCountExtractor.GetBitsValue(pack);
            int codecType   = codecTypeExtractor.GetBitsValue(pack);

            // Unused int sequenceNumber
            sequenceNumberExtractor.GetBitsValue(pack);

            if (sampleRate == 0)
            {
                // Unused int extendedSampleRate
                message.ReadInt32();
            }

            try
            {
                audioDataMutex.WaitOne();

                prominentSpeakerCount = 0;

                for (int i = 0; i < audioStreamCount; i++)
                {
                    float   averageAmplitude = message.ReadFloat();
                    UInt32  hrtfSourceID     = (UInt32)message.ReadInt32();
                    Vector3 hrtfPosition     = new Vector3();
                    Vector3 hrtfDirection    = new Vector3();
                    if (hrtfSourceID != 0)
                    {
                        hrtfPosition.x = message.ReadFloat();
                        hrtfPosition.y = message.ReadFloat();
                        hrtfPosition.z = message.ReadFloat();

                        hrtfDirection.x = message.ReadFloat();
                        hrtfDirection.y = message.ReadFloat();
                        hrtfDirection.z = message.ReadFloat();

                        Vector3 cameraPosRelativeToGlobalAnchor       = Vector3.zero;
                        Vector3 cameraDirectionRelativeToGlobalAnchor = Vector3.zero;

                        if (GlobalAnchorTransform != null)
                        {
                            cameraPosRelativeToGlobalAnchor = MathUtils.TransformPointFromTo(
                                null,
                                GlobalAnchorTransform,
                                Camera.main.transform.position);
                            cameraDirectionRelativeToGlobalAnchor = MathUtils.TransformDirectionFromTo(
                                null,
                                GlobalAnchorTransform,
                                Camera.main.transform.position);
                        }

                        cameraPosRelativeToGlobalAnchor.Normalize();
                        cameraDirectionRelativeToGlobalAnchor.Normalize();

                        Vector3 soundVector = hrtfPosition - cameraPosRelativeToGlobalAnchor;
                        soundVector.Normalize();

                        // x is forward
                        float fltx = (kDropOffMaximum / DropOffMaximumMetres) * Vector3.Dot(soundVector, cameraDirectionRelativeToGlobalAnchor);
                        // y is right
                        Vector3 myRight = Quaternion.Euler(0, 90, 0) * cameraDirectionRelativeToGlobalAnchor;
                        float   flty    = -(kPanMaximum / PanMaximumMetres) * Vector3.Dot(soundVector, myRight);
                        // z is up
                        Vector3 myUp = Quaternion.Euler(90, 0, 0) * cameraDirectionRelativeToGlobalAnchor;
                        float   fltz = (kPanMaximum / PanMaximumMetres) * Vector3.Dot(soundVector, myUp);

                        // Hacky distance check so we don't get too close to source.
                        Vector3 flt = new Vector3(fltx, flty, fltz);
                        if (flt.magnitude < (MinimumDistance * kDropOffMaximum))
                        {
                            flt  = flt.normalized * MinimumDistance * kDropOffMaximum;
                            fltx = flt.x;
                            flty = flt.y;
                            fltz = flt.z;
                        }

                        AddProminentSpeaker(hrtfSourceID, averageAmplitude, fltx, flty, fltz);
                    }

                    for (int j = 0; j < channelCount; j++)
                    {
                        // if uncompressed, size = sampleCount
                        Int16 size = (Int16)sampleCount;
                        if (codecType != 0)
                        {
                            // if compressed, size is first 2 bytes, sampleCount should be number of bytes after decompression
                            size = message.ReadInt16();
                        }

                        // make this array big enough to hold all of the uncompressed data only if the
                        // buffer is not the right size, minimize new operations
                        int totalBytes = size * bytesPerSample;
                        if (networkPacketBufferBytes.Length != totalBytes)
                        {
                            networkPacketBufferBytes = new byte[totalBytes];
                        }
                        message.ReadArray(networkPacketBufferBytes, (uint)(totalBytes));

                        if (codecType != 0)
                        {
                            // in place decompression please - should fill out the data buffer
                            // ...
                        }

                        if (hrtfSourceID > 0)
                        {
                            // hrtf processing here
                        }

                        circularBuffer.Write(networkPacketBufferBytes, 0, networkPacketBufferBytes.Length);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
            }
            finally
            {
                audioDataMutex.ReleaseMutex();
            }
        }
Exemplo n.º 17
0
 public Quaternion ReadQuaternion(NetworkInMessage msg)
 {
     return(new Quaternion(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat()));
 }
Exemplo n.º 18
0
 public Vector3 ReadVector3(NetworkInMessage msg)
 {
     return(new Vector3(msg.ReadFloat(), msg.ReadFloat(), msg.ReadFloat()));
 }
Exemplo n.º 19
0
 private void SecondPlayerReadyCheck(NetworkInMessage msg)
 {
     secondPlayerReady = true;
 }
 public override void OnMessageReceived(NetworkConnection connection, NetworkInMessage message)
 {
     Profile.BeginRange("OnMessageReceived");
     this.MessageReceivedCallback?.Invoke(connection, message);
     Profile.EndRange();
 }
Exemplo n.º 21
0
        void OnSpatialMappingRequest(HoloToolkit.Sharing.NetworkInMessage msg)
        {
            msg.ReadInt64();

            HolographicCameraManager.Instance.requestSpatialMappingData = true;
        }