/* * Here we need to update the scale and positions of important vertices in our line */ void updateLine() { int count = transform.childCount; //Debug.Log("Updated Line"); for (int i = 0; i < count; i++) { //GameObject bird = spawn_bird.spawned_individuals[i]; GameObject child = transform.GetChild(i).transform.gameObject; IndividualBehavior id = reader.gp.individualBehaviors[i]; int trackCount = id.Individualtracks.Count;//number of datapoints for each individual string[] locations = spawn_bird._LocationStrings[i]; float[] heights = spawn_bird._HeightArray[i]; Vector3[] vP = new Vector3[trackCount]; child.GetComponent <LineRenderer>().positionCount = trackCount; child.GetComponent <LineRenderer>().widthMultiplier = process.lineScale; for (int j = 0; j < trackCount; j++) { string loc = locations[j]; float height = heights[j]; var location = Conversions.StringToLatLon(loc); var localPosition = _map.GeoToWorldPosition(location, true); Vector3 point = new Vector3(localPosition.x, localPosition.y + height, localPosition.z); vP[j] = point; } //bird.transform.position = new Vector3(vP[0].x, vP[0].y, vP[0].z); child.GetComponent <LineRenderer>().SetPositions(vP); } }
/* * After reading the data we want to understand: * 1.when does the first individual come, * 2.when does the last individual finish * so that we can calculate the timeline amount in percentage */ void GetMinMaxTime() { IndividualBehavior firstId = reader.gp.individualBehaviors[0]; int firstlen = firstId.Individualtracks.Count; string fFirst = firstId.Individualtracks[0].timestamp; string fLast = firstId.Individualtracks[firstlen - 1].timestamp; curMin = fFirst; curMax = fLast; /*minIndex=0; * maxIndex=0;*/ for (int i = 1; i < indiviudal_num; i++) { IndividualBehavior id = reader.gp.individualBehaviors[i]; int len = id.Individualtracks.Count; string localFirst = id.Individualtracks[0].timestamp; string localLast = id.Individualtracks[len - 1].timestamp; if (!compareTime(localFirst, curMin)) { //local is ealier curMin = localFirst; //minIndex = i; } if (!compareTime(curMax, localLast)) { //local is later curMax = localLast; //maxIndex = i; } } }
void initialize() { //get the name of the object(correspond to the index of spawned_individuals) string objectName = transform.name; index = int.Parse(objectName); //this bird should be animated bird = spawned_individuals[index]; //get the linerenderer from this obj UpdateLineRenderer(); birdpos = positions[0]; nextpos = positions[1]; bird.transform.position = new Vector3(birdpos.x, birdpos.y, birdpos.z); t = 0; /* check * if (num == lineRenderer.positionCount) { * Debug.Log(positions[0]); * } */ //code below is to initialize a list information for each individual idb = reader.gp.individualBehaviors[index]; Individual first = idb.Individualtracks[0]; Individual second = idb.Individualtracks[1]; overallSpeed = spawn.speed; //Debug.Log("OverallSpeed " + overallSpeed); string time1 = first.timestamp; string time2 = second.timestamp; DateTime t1; DateTime.TryParse(time1, out t1); DateTime t2; DateTime.TryParse(time2, out t2); TimeSpan TimeDiff = t2 - t1; double timeDiffSec = TimeDiff.TotalSeconds; //timeDiffSecDou = Convert.ToInt64(timeDiffSec); multipler = overallSpeed / timeDiffSec; }
/* * Initialize, we want to draw different lines for different individuals */ void drawline() { for (int i = 0; i < indiviudal_num; i++) { //random bright color Color color = new Color( Random.Range(0.3f, 3f), Random.Range(0.3f, 3f), Random.Range(0.3f, 3f) ); string childID = i.ToString(); GameObject child = new GameObject(childID); child.AddComponent <birdMovement>(); child.transform.parent = this.transform; LineRenderer lineRenderer = child.AddComponent <LineRenderer>(); //Color color = ; colors[i] = color; lineRenderer.widthMultiplier = 30f; lineRenderer.material = new Material(Shader.Find("Standard")); lineRenderer.material.SetColor("_Color", color); IndividualBehavior id = reader.gp.individualBehaviors[i]; int trackCount = id.Individualtracks.Count;//number of datapoints for each individual string[] locations = spawn_bird._LocationStrings[i]; float[] heights = spawn_bird._HeightArray[i]; Vector3[] vP = new Vector3[trackCount]; lineRenderer.positionCount = trackCount; child.GetComponent <birdMovement>().firstTimestamp = id.Individualtracks[0].timestamp; for (int j = 0; j < trackCount; j++) { string loc = locations[j]; float height = heights[j]; var location = Conversions.StringToLatLon(loc); var localPosition = _map.GeoToWorldPosition(location, true); Vector3 point = new Vector3(localPosition.x, localPosition.y + height, localPosition.z); vP[j] = point; } //Debug.Log(vP.Length); lineRenderer.SetPositions(vP); } }
void ReadCSVFile() { //from Resources folder load data TextAsset Individual_data = Resources.Load <TextAsset>(id_name); string[] data = Individual_data.text.Split(new char[] { '\n' });//split for each line //initialize a list of tracks IndividualBehavior individualBehaviors = new IndividualBehavior(); //for the whole dateset for (int i = 1; i <= data.Length - 1; i++)//when there is no header i=0 { string[] row = data[i].Split(new char[] { ',' }); //Debug.Log(row.Length); //int a = row.Length; string cur_id = row[0]; // check if last id is equal this id if (last_id != null && cur_id != last_id) { if (row.Length == 5) { //store the last individualBehavior gp.individualBehaviors.Add(individualBehaviors); //create a new InidividualBehavior to store the data individualBehaviors = new IndividualBehavior(); //store to individual typ Individual individual = new Individual(); individual.id = cur_id; individual.timestamp = row[1]; //Debug.Log(individual.timestamp); individual.lng = row[2]; individual.lat = row[3]; float.TryParse(row[4], out individual.height); //Debug.Log(individual.height); //individual.height = individual.height - 1000; if (individual.height < 0) { individual.height = 0; Debug.LogError("there are height lower equal 0s"); } individualBehaviors.Individualtracks.Add(individual); } } else { if (row.Length == 5) { //that include 2 possiblities: last id= null(initial) or the id doesn't change //We just store the id into individualBehaviors //store to individual typ Individual individual = new Individual(); individual.id = cur_id; individual.timestamp = row[1]; //Debug.Log(individual.timestamp); individual.lng = row[2]; individual.lat = row[3]; float.TryParse(row[4], out individual.height); //individual.height = individual.height - 1000; if (individual.height < 0) { individual.height = 0; Debug.LogError("there are height lower equal 0s");//warn the user } //get the last individualBehaviors to store data individualBehaviors.Individualtracks.Add(individual); //Debug.Log(individualBehaviors.Individualtracks.Count + " < " + individual.height); } } //update id last_id = cur_id; if (i == data.Length - 1) { gp.individualBehaviors.Add(individualBehaviors); } } /*if (gp.individualBehaviors[2].Individualtracks != null) * { * for (int i = 0; i < gp.individualBehaviors[2].Individualtracks.Count; i++) * { * Debug.Log(gp.individualBehaviors[2].Individualtracks[i].height); * } * } * if (gp.individualBehaviors[2].Individualtracks == null) * { * Debug.Log("null"); * }*/ }