protected virtual void ApplyTrackData(TrackingEntity trackingEntity, TrackRecord trackRecord)
 {
     trackingEntity.AbsolutePosition             = new Vector3(trackRecord.currentPos.x - gridOffset.x, trackRecord.currentPos.y - gridOffset.y, trackRecord.currentPos.z - gridOffset.z);
     trackingEntity.NextExpectedAbsolutePosition = new Vector3(trackRecord.expectPos.x - gridOffset.x, trackRecord.expectPos.y - gridOffset.y, trackRecord.expectPos.z - gridOffset.z);
     trackingEntity.RelativePosition             = new Vector3(trackRecord.relPos.x, trackRecord.relPos.y, trackRecord.relPos.z);
     trackingEntity.Orientation = new Vector3(trackRecord.orientation.x, trackRecord.orientation.y, trackRecord.orientation.z);
     trackingEntity.Speed       = trackRecord.speed;
     trackingEntity.Echoes.Clear();
     trackRecord.echoes.AddRange(trackingEntity.Echoes);
 }
Example #2
0
 private void SaveTrackToDict(TrackRecord track, bool createIfNotYetExisting)
 {
     if (_trackDict.ContainsKey(track.trackID))
     {
         _trackDict[track.trackID] = track;
     }
     else
     {
         _trackDict.Add(track.trackID, track);
     }
 }
Example #3
0
        private void Update()
        {
            // Development only: Use this, if you changed the TracklinkSettings class and want to generate a new json file based on the new class layout.
            //if (Input.GetKeyUp(KeyCode.S))
            //{
            //	SaveSettings<TuioSettings>(_tuioSettings, _jsonConfigFileName);
            //}
            // End of Development only.

            //Lister for Tuio Data if enabled
            if (_eventProcessor != null)
            {
                _eventProcessor.Process();
            }

            // Iterate through all tracks, that got updated:
            foreach (int trackId in _updatedTrackIds)
            {
                TrackRecord track = GetTrackById(trackId);

                // Send events to subsribers:
                foreach (ITrackingReceiver receiver in _trackingReceiverList)
                {
                    // track is unknown yet AND is not about to die
                    if (track.state == TrackState.TRACK_ADDED)
                    {
                        receiver.OnTrackNew(track);
                    }
                    // standard track update
                    else if (track.state == TrackState.TRACK_UPDATE)
                    {
                        receiver.OnTrackUpdate(track);
                    }
                    // track is known and this is his funeral
                    else if (track.state == TrackState.TRACK_REMOVED)
                    {
                        receiver.OnTrackLost(track);
                    }
                }

                // After sending, if it is a removed track message, remove it from the dict:
                if (track.state == TrackState.TRACK_REMOVED)
                {
                    if (_trackDict.ContainsKey(track.trackID))
                    {
                        _trackDict.Remove(track.trackID);
                    }
                }
            }

            // Clear the Updated tracks list afterwards:
            _updatedTrackIds.Clear();
        }
 protected void RemoveAllTrackRecords()
 {
     foreach (KeyValuePair <int, TrackRecord> entry in _trackDict)
     {
         TrackRecord track = entry.Value;
         foreach (ITrackingReceiver receiver in _trackingReceiverList)
         {
             track.state = TrackState.TRACK_REMOVED;
             receiver.OnTrackLost(track);
         }
     }
 }
        public virtual void TrackAdded(TrackRecord trackRecord)
        {
            Vector2    position      = _trackingReceiveHandler.TrackingSettings.GetScreenPositionFromRelativePosition(trackRecord.relPos.x, trackRecord.relPos.y);
            GameObject trackInstance = GameObject.Instantiate(TrackingEntityPrefab, new Vector3(position.x, -1.7f, position.y), Quaternion.identity) as GameObject;

            trackInstance.transform.SetParent(trackSpawnParent);
            trackInstance.name = string.Format("PharusTrack_{0}", trackRecord.trackID);

            TrackingEntity trackingEntity = trackInstance.GetComponent <TrackingEntity>();

            trackingEntity.TrackID = trackRecord.trackID;

            ApplyTrackData(trackingEntity, trackRecord);

            _trackingEntityDict.Add(trackingEntity.TrackID, trackingEntity);
        }
Example #6
0
        private void OnUpdateEchoInformation(TUIO.TuioObject tuioObject, TrackState state)
        {
            TrackRecord track = GetTrackById(tuioObject.SymbolID);             // Symbol ID is the ID of the track, to which the echo belongs.

            if (state == TrackState.TRACK_ADDED)
            {
                track.echoes.Add(new Vector2(tuioObject.Position.X, tuioObject.Position.Y));
            }
            else if (state == TrackState.TRACK_REMOVED)
            {
                // Actually I can find the one specific, by saving and comparing Session IDs or by comparing the positions, but this is not necessary in this case.
                // Pharus sends Tuio Remove messages for all echos. Then it sends add messages for all echos. If one is removed, all are being removed.
                track.echoes.Clear();
            }

            SaveTrackToDict(track, createIfNotYetExisting: false);
        }
        public virtual void TrackUpdated(TrackRecord trackRecord)
        {
            TrackingEntity trackingEntity = null;

            if (_trackingEntityDict.TryGetValue(trackRecord.trackID, out trackingEntity))
            {
                ApplyTrackData(trackingEntity, trackRecord);

                trackingEntity.SetPosition(_trackingReceiveHandler.TrackingSettings.GetScreenPositionFromRelativePosition(trackRecord.relPos.x, trackRecord.relPos.y));
            }
            else
            {
                if (addUnknownTrackOnUpdate)
                {
                    TrackAdded(trackRecord);
                }
            }
        }
Example #8
0
        private TrackRecord GetTrackById(int trackId)
        {
            bool unknownTrack = !_trackDict.ContainsKey(trackId);

            TrackRecord track;

            if (unknownTrack)
            {
                track         = new TrackRecord();
                track.trackID = trackId;
                track.echoes  = new List <Vector2>();
                _trackDict.Add(track.trackID, track);
            }
            else
            {
                track = _trackDict[trackId];
            }

            return(track);
        }
Example #9
0
        private void OnReceivedTrackInformation(TUIO.TuioCursor tuioCursor, TrackState state)
        {
            TrackRecord track = GetTrackById(tuioCursor.CursorID);

            track.state = state;
            Vector2 absPos = TrackingSettings.GetScreenPositionFromRelativePosition(tuioCursor.Position.X, tuioCursor.Position.Y);

            track.currentPos.x = absPos.x;
            track.currentPos.y = absPos.y;
            track.expectPos.x  = tuioCursor.Position.X + (tuioCursor.XSpeed * Time.deltaTime);
            track.expectPos.y  = tuioCursor.Position.Y + (tuioCursor.YSpeed * Time.deltaTime);
            Vector2 orientation = (new Vector2(tuioCursor.XSpeed, tuioCursor.YSpeed)).normalized;

            track.orientation.x = orientation.x;
            track.orientation.y = orientation.y;
            track.speed         = tuioCursor.XSpeed + tuioCursor.YSpeed;
            track.relPos.x      = tuioCursor.Position.X;
            track.relPos.y      = tuioCursor.Position.Y;

            SaveTrackToDict(track, createIfNotYetExisting: true);

            _updatedTrackIds.Add(track.trackID);
        }
Example #10
0
        private void OnReceivedMessage(byte[] messageBytes, System.Net.IPAddress senderIP)
        {
            int messageBytesLength = messageBytes.Length;

            if (messageBytes != null && messageBytesLength > 0)
            {
                int i = 0;
                while (i < messageBytesLength)
                {
                    if (Convert.ToChar(messageBytes[i++]) != 'T')
                    {
                        Console.WriteLine("TransmissionClient: Unexpected header byte, skipping packet.");
                        i = messageBytesLength;
                        continue;
                    }

                    // get the tracks's id
                    int tid;
                    tid = BytePackHelper.UnpackInt(messageBytes, ref i);

                    // is this track known? if so, update, else add:
                    bool unknownTrack = !_trackDict.ContainsKey(tid);

                    TrackRecord track;
                    if (unknownTrack)
                    {
                        track         = new TrackRecord();
                        track.echoes  = new List <Vector3>();
                        track.trackID = tid;
                        _trackDict.Add(track.trackID, track);
                    }
                    else
                    {
                        track = _trackDict[tid];
                    }

                    track.state         = (TrackState)BytePackHelper.UnpackInt(messageBytes, ref i);
                    track.currentPos.x  = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.currentPos.z  = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.currentPos.y  = -1.7f;
                    track.expectPos.x   = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.expectPos.y   = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.orientation.x = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.orientation.y = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.speed         = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.relPos.x      = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.relPos.y      = BytePackHelper.UnpackFloat(messageBytes, ref i);
                    track.echoes.Clear();
                    while (Convert.ToChar(messageBytes[i]) == 'E') // peek if echo(es) available
                    {
                        ++i;                                       // yep, then skip 'E'
                        Vector2 echo = new Vector2();
                        echo.x = BytePackHelper.UnpackFloat(messageBytes, ref i);
                        echo.y = BytePackHelper.UnpackFloat(messageBytes, ref i);
                        track.echoes.Add(echo);
                        ++i;                         // 'e'
                    }

                    if (Convert.ToChar(messageBytes[i++]) != 't')
                    {
                        Console.WriteLine("TransmissionClient: Unexpected tailing byte, skipping packet.");
                        i = messageBytesLength;
                        continue;
                    }

                    //notify callbacks
                    foreach (ITrackingReceiver receiver in _trackingReceiverList)
                    {
                        // track is unknown yet AND is not about to die
                        if (unknownTrack && track.state != TrackState.TRACK_REMOVED)
                        {
                            receiver.OnTrackNew(track);
                        }
                        // standard track update
                        else if (!unknownTrack && track.state != TrackState.TRACK_REMOVED)
                        {
                            receiver.OnTrackUpdate(track);
                        }
                        // track is known and this is his funeral
                        else if (!unknownTrack && track.state == TrackState.TRACK_REMOVED)
                        {
                            receiver.OnTrackLost(track);
                        }
                    }

                    // remove track from dictionary
                    if (track.state == TrackState.TRACK_REMOVED)
                    {
                        _trackDict.Remove(track.trackID);
                    }
                }
            }
        }
 public void OnTrackLost(TrackRecord track)
 {
     TrackRemoved(track.trackID);
 }
 public void OnTrackUpdate(TrackRecord track)
 {
     TrackUpdated(track);
 }
 public void OnTrackNew(TrackRecord track)
 {
     TrackAdded(track);
 }