private void testApproximation() { Debug.Log("Testing Approximation class!"); MyTerrain t = new MyTerrain(); List <Vector3[]> cs = new List <Vector3[]>(); cs.Add(new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(100f, 0f, 0f), new Vector3(100f, 100f, 0f), new Vector3(0f, 100f, 0f) }); cs.Add(new Vector3[] { new Vector3(0f, 0f, 0f), new Vector3(100f, 0f, 0f), new Vector3(0f, 100f, 0f), new Vector3(0f, 0f, 0f) }); t.load(cs); for (int i = 0; i < cs.Count; i++) { Debug.Log("- " + "Contour number " + i); foreach (Vector3 v in t.getApproximatedContours(3)[i]) { Debug.Log("- " + v.ToString()); } } Debug.Log("Testing Approximation finished."); }
public int[] myParseOmap() { if (ptext == null) { return(null); } int[] ret = new int[4]; ret[0] = Int32.MaxValue; // min x ret[1] = Int32.MinValue; // max x ret[2] = Int32.MaxValue; // min y ret[3] = Int32.MinValue; // max y int ix = findFrom("default part", 0); // Position, where in all omap files begin changes Debug.Log("ix po default part: " + ix.ToString()); Debug.Log("znaky default part: " + ptext[ix] + ptext[ix - 1] + ptext[ix - 2] + ptext[ix - 3] + ptext[ix - 4] + ptext[ix - 5] + ptext[ix - 6]); List <Vector3[]> clist = new List <Vector3[]>(); // array of contours List <Vector3> contour = new List <Vector3>(); // temporary variable for contour int countObj = 0; int countCoords = 0; int symbol = -1; int x, y; while (ix < ptext.Length) { ix = findFrom("<objects ", ix); // index from "default part", gets index after "objects" if (ix == -1) { break; } ix = findFrom("count=\"", ix); // index from "<objects ", gets index after "count="" countObj = readInt(ix); // reads integer from actual index for (int i = 0; i < countObj; i++) // from previous parent objects parameter count we know number of object elements { ix = findFrom("<object ", ix); if (ix == -1) { break; } ix = findFrom("symbol=\"", ix); symbol = readInt(ix); ix = findFrom("<coords ", ix); ix = findFrom("count=\"", ix); // index from "<coords ", gets index after "count="" countCoords = readInt(ix); contour.Clear(); for (int j = 0; j < countCoords; j++) // from parent element parameter count we know number of coord elements { ix = findFrom("<coord ", ix); if (ix == -1) { break; } ix = findFrom("x=\"", ix); // x value x = readInt(ix); ix = findFrom("y=\"", ix); // y value y = readInt(ix); ret[0] = Mathf.Min(ret[0], x); // min x ret[2] = Mathf.Min(ret[2], y); // min y ret[1] = Mathf.Max(ret[1], x); // max x ret[3] = Mathf.Max(ret[3], y); // max y contour.Add(new Vector3((float)x, (float)y, 0)); // add x and y values to contour } ix = findFrom("</coords>", ix); // close element coords ix = findFrom("</object>", ix); // close element object clist.Add(contour.ToArray()); // add contour from last object's coords to array of contours } ix = findFrom("</objects>", ix); // close element objects } myTerr.load(clist); // add array of contours to terrain object Debug.Log("min x: " + ret[0].ToString() + " max x: " + ret[1].ToString() + " min y: " + ret[2].ToString() + " max y: " + ret[3].ToString()); return(ret); // return mins a maxs of x and y }