public virtual void UpdatePlayerPosition(PharusTransmission.TrackRecord trackRecord) { foreach (ATrackingEntity aPlayer in _playerList) { if (aPlayer.TrackID == trackRecord.trackID) { aPlayer.AbsolutePosition = new Vector2(trackRecord.currentPos.x, trackRecord.currentPos.y); aPlayer.NextExpectedAbsolutePosition = new Vector2(trackRecord.expectPos.x, trackRecord.expectPos.y); aPlayer.RelativePosition = new Vector2(trackRecord.relPos.x, trackRecord.relPos.y); aPlayer.Orientation = new Vector2(trackRecord.orientation.x, trackRecord.orientation.y); aPlayer.Speed = trackRecord.speed; // use AddToVector2List() instead of ToVector2List() as it is more performant aPlayer.Echoes.Clear(); trackRecord.echoes.AddToVector2List(aPlayer.Echoes); aPlayer.SetPosition(UnityPharusManager.GetScreenPositionFromRelativePosition(trackRecord.relPos)); aPlayer.SetPosition(TrackingAdapter.GetScreenPositionFromRelativePosition(trackRecord.relPos.x, trackRecord.relPos.y)); return; } } if (_addUnknownPlayerOnUpdate) { AddPlayer(trackRecord); } }
public void AddPlayer(PharusTransmission.TrackRecord trackRecord) { // Vector2 position = UnityPharusManager.GetScreenPositionFromRelativePosition(trackRecord.relPos); Vector2 position = TrackingAdapter.GetScreenPositionFromRelativePosition(trackRecord.relPos.x, trackRecord.relPos.y); ATrackingEntity aPlayer = (GameObject.Instantiate(_playerPrefabArray[idx], new Vector3(position.x, position.y, 0), Quaternion.identity) as GameObject).GetComponent <ATrackingEntity>(); aPlayer.TrackID = trackRecord.trackID; aPlayer.AbsolutePosition = new Vector2(trackRecord.currentPos.x, trackRecord.currentPos.y); aPlayer.NextExpectedAbsolutePosition = new Vector2(trackRecord.expectPos.x, trackRecord.expectPos.y); aPlayer.RelativePosition = new Vector2(trackRecord.relPos.x, trackRecord.relPos.y); aPlayer.Orientation = new Vector2(trackRecord.orientation.x, trackRecord.orientation.y); aPlayer.Speed = trackRecord.speed; aPlayer.Echoes.Clear(); trackRecord.echoes.AddToVector2List(aPlayer.Echoes); aPlayer.gameObject.name = string.Format("PharusPlayer_{0}", aPlayer.TrackID); _playerList.Add(aPlayer); _playerList.Add(aPlayer); if (idx < _playerPrefabArray.Length - 1) { idx++; } else { idx = 0; } }
public virtual void AddPlayer(TUIO.TuioContainer theTuioContainer) { // Vector2 position = UnityTuioManager.GetScreenPositionFromRelativePosition (theTuioContainer.Position); Vector2 position = TrackingAdapter.GetScreenPositionFromRelativePosition(theTuioContainer.Position.X, theTuioContainer.Position.Y); ATrackingEntity aPlayer = (GameObject.Instantiate(_playerPrefab, new Vector3(position.x, position.y, 0), Quaternion.identity) as GameObject).GetComponent <ATrackingEntity>(); aPlayer.TrackID = theTuioContainer.SessionID; aPlayer.RelativePosition = new Vector2(theTuioContainer.Position.X, theTuioContainer.Position.Y); aPlayer.gameObject.name = string.Format("TuioPlayer_{0}", aPlayer.TrackID); _playerList.Add(aPlayer); }
public virtual void UpdatePlayerPosition(TUIO.TuioContainer theTuioContainer) { foreach (ATrackingEntity player in _playerList) { if (player.TrackID.Equals(theTuioContainer.SessionID)) { // Vector2 position = UnityTuioManager.GetScreenPositionFromRelativePosition (theTuioContainer.Position); Vector2 position = TrackingAdapter.GetScreenPositionFromRelativePosition(theTuioContainer.Position.X, theTuioContainer.Position.Y); player.SetPosition(position); player.RelativePosition = new Vector2(theTuioContainer.Position.X, theTuioContainer.Position.Y); return; } } if (_addUnknownPlayerOnUpdate) { AddPlayer(theTuioContainer); } }
private IEnumerator InitInstance() { m_initialized = true; Application.runInBackground = true; if (m_pharusSettings.CheckServerReconnectIntervall > 0) { StartCoroutine(CheckServerAlive(m_pharusSettings.CheckServerReconnectIntervall)); } if (m_persistent) { GameObject.DontDestroyOnLoad(this.gameObject); } // start: load config file yield return(StartCoroutine(LoadConfigXML())); // Debug.Log ("UnityPharusManager config loaded, continue InitInstance"); if (m_unityPharusXMLConfig != null) { string configTrackLinkEnabled = null; string configProtocol = null; string configTCPIP = null; string configTCPPort = null; string configUDPMulticastIP = null; string configUDPPort = null; string targetResolutionX = null; string targetResolutionY = null; string stageX = null; string stageY = null; for (int i = 0; i < m_unityPharusXMLConfig.ConfigNodes.Length; i++) { switch (m_unityPharusXMLConfig.ConfigNodes[i].Name) { case "enabled": configTrackLinkEnabled = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "protocol": configProtocol = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "tcp-ip": configTCPIP = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "tcp-port": configTCPPort = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "udp-multicast-ip": configUDPMulticastIP = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "udp-port": configUDPPort = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "targetResolutionX": targetResolutionX = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "targetResolutionY": targetResolutionY = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "stageX": stageX = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; case "stageY": stageY = m_unityPharusXMLConfig.ConfigNodes[i].Value; break; default: break; } } bool configTracklinkBool; if (configTrackLinkEnabled != null && Boolean.TryParse(configTrackLinkEnabled, out configTracklinkBool)) { m_pharusSettings.TracklinkEnabled = configTracklinkBool; Debug.Log(string.Format("XML config: TrackLink enabled: {0}", m_pharusSettings.TracklinkEnabled)); } else { Debug.Log(string.Format("XML config: invalid TrackLink enabled config. Using settings from prefab instead: TrackLink enabled: {0}", m_pharusSettings.TracklinkEnabled)); } if (configProtocol != null) { configProtocol = configProtocol.ToUpper(); switch (configProtocol) { case "UDP": int configUDPPortInt; if (configUDPMulticastIP != null && configUDPPort != null && int.TryParse(configUDPPort, out configUDPPortInt)) { m_pharusSettings.Protocol = PharusSettings.EProtocolType.UDP; m_pharusSettings.UDP_Multicast_IP_Address = configUDPMulticastIP; m_pharusSettings.UDP_Port = configUDPPortInt; Debug.Log(string.Format("XML config: using UDP: {0}:{1}", configUDPMulticastIP, configUDPPort)); } else { Debug.LogWarning("XML config: invalid UDP config data"); } break; case "TCP": int configTCPPortInt; if (configTCPIP != null && configTCPPort != null && int.TryParse(configTCPPort, out configTCPPortInt)) { m_pharusSettings.Protocol = PharusSettings.EProtocolType.TCP; m_pharusSettings.TCP_IP_Address = configTCPIP; m_pharusSettings.TCP_Port = configTCPPortInt; Debug.Log(string.Format("XML config: using TCP: {0}:{1}", configTCPIP, configTCPPort)); } else { Debug.LogWarning("XML config: invalid TCP config data"); } break; default: Debug.LogWarning("XML config: invalid protocol specification"); break; } } else { Debug.LogWarning("XML config: invalid protocol specification"); } int configResolutionIntX; int configResolutionIntY; if (targetResolutionX != null && int.TryParse(targetResolutionX, out configResolutionIntX) && targetResolutionY != null && int.TryParse(targetResolutionY, out configResolutionIntY)) { m_pharusSettings.TargetScreenWidth = configResolutionIntX; m_pharusSettings.TargetScreenHeight = configResolutionIntY; Debug.Log(string.Format("XML config: new target resolution: {0}x{1}", m_pharusSettings.TargetScreenWidth, m_pharusSettings.TargetScreenHeight)); } else { Debug.LogWarning(string.Format("XML config: invalid resolution config, using resolution specified in PharusManager prefab instead: {0}x{1}", m_pharusSettings.TargetScreenWidth, m_pharusSettings.TargetScreenHeight)); } float configStageFloatX; float configStageFloatY; if (stageX != null && float.TryParse(stageX, out configStageFloatX) && stageY != null && float.TryParse(stageY, out configStageFloatY)) { m_pharusSettings.StageX = configStageFloatX; m_pharusSettings.StageY = configStageFloatY; Debug.Log(string.Format("XML config: new stage size: {0}x{1}", m_pharusSettings.StageX, m_pharusSettings.StageY)); } else { Debug.LogWarning(string.Format("XML config: invalid stage size config, using stage size specified in PharusManager prefab instead: {0}x{1}", m_pharusSettings.StageX, m_pharusSettings.StageY)); } } else { Debug.Log(string.Format("no config xml file found in resources: using default pharus settings ({0})", m_pharusSettings.Protocol.ToString())); } // end: load config file if (!m_pharusSettings.TracklinkEnabled) { Debug.Log("Disable and Destroy UnityPharusManager"); this.enabled = false; Destroy(this); yield break; } if (m_pharusSettings.Protocol == PharusSettings.EProtocolType.TCP) { m_listener = UnityPharusListener.NewUnityPharusListenerTCP(m_pharusSettings.TCP_IP_Address, m_pharusSettings.TCP_Port); } else if (m_pharusSettings.Protocol == PharusSettings.EProtocolType.UDP) { m_listener = UnityPharusListener.NewUnityPharusListenerUDP(m_pharusSettings.UDP_Multicast_IP_Address, m_pharusSettings.UDP_Port); } else { Debug.LogError("Invalid pharus settings!"); yield break; } m_eventProcessor = new UnityPharusEventProcessor(m_listener); if (OnTrackingInitialized != null) { OnTrackingInitialized(this, new EventArgs()); } Screen.SetResolution(m_pharusSettings.TargetScreenWidth, m_pharusSettings.TargetScreenHeight, true); TrackingAdapter.InjectTrackingManager(m_instance); UpdateDebugGUI(); }
public TrackingController() { TrackingAdapter = new TrackingAdapter(); }
private IEnumerator InitInstance() { m_initialized = true; Application.runInBackground = true; if (m_persistent) { GameObject.DontDestroyOnLoad(this.gameObject); } // start: load config file yield return(StartCoroutine(LoadConfigXML())); // Debug.Log ("UnityTuioManager config loaded, continue InitInstance"); if (m_unityTuioXMLConfig != null) { string configTrackingEnabled = null; string configUDPPort = null; string targetResolutionX = null; string targetResolutionY = null; string stageX = null; string stageY = null; for (int i = 0; i < m_unityTuioXMLConfig.ConfigNodes.Length; i++) { switch (m_unityTuioXMLConfig.ConfigNodes[i].Name) { case "enabled": configTrackingEnabled = m_unityTuioXMLConfig.ConfigNodes[i].Value; break; case "udp-port": configUDPPort = m_unityTuioXMLConfig.ConfigNodes[i].Value; break; case "targetResolutionX": targetResolutionX = m_unityTuioXMLConfig.ConfigNodes[i].Value; break; case "targetResolutionY": targetResolutionY = m_unityTuioXMLConfig.ConfigNodes[i].Value; break; case "stageX": stageX = m_unityTuioXMLConfig.ConfigNodes[i].Value; break; case "stageY": stageY = m_unityTuioXMLConfig.ConfigNodes[i].Value; break; default: break; } } bool configTrackingEnabledBool; if (configTrackingEnabled != null && Boolean.TryParse(configTrackingEnabled, out configTrackingEnabledBool)) { m_tuioSettings.TrackingEnabled = configTrackingEnabledBool; //Debug.Log(string.Format("XML config: TUIO tracking enabled: {0}", m_tuioSettings.TrackingEnabled)); } else { //Debug.Log(string.Format("XML config: invalid TUIO enabled config. Using settings from prefab instead: TUIO tracking enabled: {0}", m_tuioSettings.TrackingEnabled)); } int configUDPPortInt; if (configUDPPort != null && int.TryParse(configUDPPort, out configUDPPortInt)) { m_tuioSettings.UDP_Port = configUDPPortInt; //Debug.Log(string.Format("XML config: TUIO using UDP Port: {0}", configUDPPort)); } else { //Debug.LogWarning("XML config: invalid TUIO Port config"); } int configResolutionIntX; int configResolutionIntY; if (targetResolutionX != null && int.TryParse(targetResolutionX, out configResolutionIntX) && targetResolutionY != null && int.TryParse(targetResolutionY, out configResolutionIntY)) { m_tuioSettings.TargetFloorWidth = configResolutionIntX; m_tuioSettings.TargetFloorHeight = configResolutionIntY; //Debug.Log(string.Format("XML config: new target resolution: {0}x{1}", m_tuioSettings.TargetFloorWidth, m_tuioSettings.TargetFloorHeight)); } else { //Debug.LogWarning(string.Format("XML config: invalid resolution config, using resolution specified in TuioManager prefab instead: {0}x{1}", m_tuioSettings.TargetFloorWidth, m_tuioSettings.TargetFloorHeight)); } float configStageFloatX; float configStageFloatY; if (stageX != null && float.TryParse(stageX, out configStageFloatX) && stageY != null && float.TryParse(stageY, out configStageFloatY)) { m_tuioSettings.StageX = configStageFloatX; m_tuioSettings.StageY = configStageFloatY; //Debug.Log(string.Format("XML config: new stage size: {0}x{1}", m_tuioSettings.StageX, m_tuioSettings.StageY)); } else { //Debug.LogWarning(string.Format("XML config: invalid stage size config, using stage size specified in TuioManager prefab instead: {0}x{1}", m_tuioSettings.StageX, m_tuioSettings.StageY)); } } else { Debug.Log("no config xml file found in resources: using default TUIO settings"); } // end: load config file if (!m_tuioSettings.TrackingEnabled) { Debug.Log("Disable and Destroy UnityTuioManager"); this.enabled = false; Destroy(this); yield break; } m_listener = new UnityTuioListener(m_tuioSettings.UDP_Port); m_eventProcessor = new UnityTuioEventProcessor(m_listener); if (OnTrackingInitialized != null) { OnTrackingInitialized(this, new EventArgs()); } TrackingAdapter.InjectTrackingManager(m_instance); UpdateDebugGUI(); }
/// <summary> /// Initializes new instance of the <see cref="DockableBase"/> class. /// </summary> protected DockableBase() { _trackingAdapter = new TrackingAdapter(); }
public TrackingController() { TrackingAdapter = new TrackingAdapter(); }