public Sensor(string sensorID, GameObject sensorGameObject) { bodies = new Dictionary<string, SensorBody> (); _active = true; SensorID = sensorID; lastBodiesMessage = null; _sensorGameObject = sensorGameObject; SensorGameObject.name = sensorID; center1 = new Vector3 (); center2 = new Vector3 (); up1 = new Vector3 (); up2 = new Vector3 (); _floorValues = new List<Vector3> (); _bestFitPlanePoints = new List<Vector3> (); _material = _chooseMaterial (); CommonUtils.changeGameObjectMaterial (_sensorGameObject, _material); GameObject cloudobj = new GameObject ("PointCloud"); cloudobj.transform.parent = sensorGameObject.transform; cloudobj.transform.localPosition = Vector3.zero; cloudobj.transform.localRotation = Quaternion.identity; cloudobj.transform.localScale = new Vector3 (-1, 1, 1); cloudobj.AddComponent<PointCloudSimple> (); lastCloud = cloudobj.GetComponent<PointCloudSimple> (); }
public void newFrameFromSensor(string bodies) { try { BodiesMessage b = new BodiesMessage(bodies); trackerGameObject.GetComponent<Tracker>().setNewFrame(b); } catch (BodiesMessageException e) { Debug.Log(e.Message); } }
void Update() { while (_stringsToParse.Count > 0) { try { byte[] toProcess = _stringsToParse.First(); if(toProcess != null) { // TMA: THe first char distinguishes between a BodyMessage and a CloudMessage if (Convert.ToChar(toProcess[0]) == 'B') { try { string stringToParse = Encoding.ASCII.GetString(toProcess); string[] splitmsg = stringToParse.Split(MessageSeparators.L0); BodiesMessage b = new BodiesMessage(splitmsg[1]); gameObject.GetComponent<Tracker>().setNewFrame(b); } catch (BodiesMessageException e) { Debug.Log(e.Message); } } else if(Convert.ToChar(toProcess[0]) == 'C') { string stringToParse = Encoding.ASCII.GetString(toProcess); string[] splitmsg = stringToParse.Split(MessageSeparators.L0); CloudMessage c = new CloudMessage(splitmsg[1], toProcess); gameObject.GetComponent<Tracker>().setNewCloud(c); } } _stringsToParse.RemoveAt(0); } catch (Exception exc) { _stringsToParse.RemoveAt(0); } } }
internal void setNewFrame(BodiesMessage bodies) { if (!Sensors.ContainsKey (bodies.KinectId)) { Vector3 position = new Vector3 (Mathf.Ceil (Sensors.Count / 2.0f) * (Sensors.Count % 2 == 0 ? -1.0f : 1.0f), 1, 0); Sensors [bodies.KinectId] = new Sensor (bodies.KinectId, (GameObject)Instantiate (Resources.Load ("Prefabs/KinectSensorPrefab"), position, Quaternion.identity)); } Sensors [bodies.KinectId].lastBodiesMessage = bodies; }