void BuildPlates() { plates = new List <Plate>(); SphereTile toOrigin = new SphereTile(); //first get toPlate and toOrigin then make the plates for (int i = 0; i < tPlates.Count; i++) { List <SphereTile> toPlate = new List <SphereTile>(); foreach (SphereTile st in sTiles) { if (st.plate == i) { toPlate.Add(st); } } int x = 0; foreach (SphereTile st in toPlate) { if (st.plateOrigin) { toOrigin = st; x++; break; } if (x > 1) { Debug.Log("same plate origin: " + x); } } plates.Add(new Plate(toPlate, toOrigin, i)); //toPlate.Clear(); } //now get boundary by looking at neighbors //Debug.Log(plates.Count); foreach (Plate p in plates) { List <SphereTile> toBoundary = new List <SphereTile>(); foreach (SphereTile st in p.tiles) { foreach (SphereTile stn in st.neighborList) { //Debug.Log("parent " + st.plate + " neighbor " + stn.plate); if (stn.plate != st.plate) { //If a neighbor has a plate index other than the parent's, add it to the boundary toBoundary.Add(st); st.boundary = true; break; } } } //set boundary p.boundary = toBoundary; //toBoundary.Clear(); } //Boundaries are defined, next tile heights are set by Tectonics() }
public Plate(List<SphereTile> t, SphereTile ori) { origin = ori; float driftx, drifty, driftz; //drift axis components(randomized) tiles = new List<SphereTile>(t); //Random spin and drift //Define random axis and rotation about (drift) driftx = Random.Range(-1, 1); drifty = Random.Range(-1, 1); driftz = Random.Range(-1, 1); driftAxis = new Vector3(driftx, drifty, driftz); driftAngle = Random.Range(0.1f, 0.24f); drift = driftAxis * driftAngle; //Define random rotation about center axis (spin) spinAngle = Random.Range(0.1f, 0.24f); /* used to be for finding origin, now passed int i = 0; foreach (SphereTile st in tiles) { if (st.plateOrigin == true) { origin = st; i++; } if (i > 1) Debug.Log("There are " + i + " origins in plate " + index); } */ //set spin spin = origin.center * spinAngle; //oceanic? float rand = Random.Range(0, 1f); if (rand <= oceanProb) { oceanic = true; } //calculate movement //set drift for each tile foreach (SphereTile st in tiles) { //calculate movement of each tile given the plate movement st.drift = drift + spin + st.center; } }
public Plate(List <SphereTile> t, SphereTile ori, int ind) { index = ind; origin = ori; float driftx, drifty, driftz; //drift axis components(randomized) tiles = new List <SphereTile>(t); //Random spin and drift //Define random axis and rotation about (drift) driftx = Random.Range(-1, 1); drifty = Random.Range(-1, 1); driftz = Random.Range(-1, 1); driftAxis = new Vector3(driftx, drifty, driftz); driftAngle = Random.Range(0.1f, 0.24f); drift = driftAxis * driftAngle; //Define random rotation about center axis (spin) spinAngle = Random.Range(0.1f, 0.24f); //set spin spin = origin.center * spinAngle; float rand = Random.Range(0, 1.0f); if (rand < 0.5f) { oceanic = true; } //calculate movement //set drift for each tile foreach (SphereTile st in tiles) { //calculate movement of each tile given the plate movement st.drift = (drift + spin + st.center) / 3; } }
void SubdivideAndDuals() { List <Triangle> currentTris; List <Triangle> nextTris = new List <Triangle>(icosahedronTris); //Original icosahedron List <List <Triangle> > subdividedTris = new List <List <Triangle> >(); sTiles = new List <SphereTile>(); // Subdivide icosahedron for (int i = 0; i < subdivisions; i++) { currentTris = new List <Triangle>(nextTris); nextTris = new List <Triangle>(); //triforces = new List<Triforce>(); foreach (Triangle tri in currentTris) { //Bisect Vector3 v1 = (tri.v1 + tri.v2) / 2.0f; Vector3 v2 = (tri.v2 + tri.v3) / 2.0f; Vector3 v3 = (tri.v3 + tri.v1) / 2.0f; //Project onto sphere v1 *= (float)(1.902084 / v1.magnitude) * scale; //golden rectangle sphere radius 1.902084 v2 *= (float)(1.902084 / v2.magnitude) * scale; v3 *= (float)(1.902084 / v3.magnitude) * scale; //Add the four new triangles Triangle mid = new Triangle(v1, v2, v3, tri, TriforcePosition.Mid, subdivisions); nextTris.Add(mid); // Center of triforce Triangle top = new Triangle(tri.v1, v1, v3, tri, TriforcePosition.Top, subdivisions); nextTris.Add(top); Triangle right = new Triangle(v1, tri.v2, v2, tri, TriforcePosition.Right, subdivisions); nextTris.Add(right); Triangle left = new Triangle(v3, v2, tri.v3, tri, TriforcePosition.Left, subdivisions); nextTris.Add(left); tri.AssignChildren(mid, top, left, right); } //Set Neighbors foreach (Triangle tri in currentTris) { tri.childMid.AssignNeighbors(tri.childTop, tri.childRight, tri.childLeft); tri.childTop.AssignNeighbors(tri.NeighborOne(tri.childTop), tri.childMid, tri.NeighborTwo(tri.childTop)); tri.childRight.AssignNeighbors(tri.NeighborOne(tri.childRight), tri.NeighborTwo(tri.childRight), tri.childMid); tri.childLeft.AssignNeighbors(tri.childMid, tri.NeighborOne(tri.childLeft), tri.NeighborTwo(tri.childLeft)); } //Save our subdivided levels subdividedTris.Add(nextTris); } finalTris = new List <Triangle>(nextTris); //Create SphereTiles foreach (Triangle tri in finalTris) { //Tiles to assign SphereTile st1 = null, st2 = null, st3 = null; //Create empty SphereTiles, or, if we've already created a SphereTile at this point just reference it foreach (SphereTile st in sTiles) { if ((Vector3)st.center == (Vector3)tri.v1) { st1 = st; } if ((Vector3)st.center == (Vector3)tri.v2) { st2 = st; } if ((Vector3)st.center == (Vector3)tri.v3) { st3 = st; } } if (st1 == null) { st1 = new SphereTile(tri.v1, origin); sTiles.Add(st1); } if (st2 == null) { st2 = new SphereTile(tri.v2, origin); sTiles.Add(st2); } if (st3 == null) { st3 = new SphereTile(tri.v3, origin); sTiles.Add(st3); } //Add in the new neighbors from this triangle st1.neighborList.Add(st2); st1.neighborList.Add(st3); st2.neighborList.Add(st1); st2.neighborList.Add(st3); st3.neighborList.Add(st1); st3.neighborList.Add(st2); //Add this triangle as an inital triangle in each spheretile st1.subTriangles.Add(tri); st2.subTriangles.Add(tri); st3.subTriangles.Add(tri); } // --- Number sphere tiles --- int count = 0; //Build the SphereTiles! foreach (SphereTile st in sTiles) { st.index = count; count++; //st.scale *= scale; st.Build(); } }
void SubdivideAndDuals() { List<Triangle> currentTris; List<Triangle> nextTris = new List<Triangle>(icosahedronTris); //Original icosahedron List<List<Triangle>> subdividedTris = new List<List<Triangle>>(); sTiles = new List<SphereTile>(); // Subdivide icosahedron for (int i = 0; i < subdivisions; i++) { currentTris = new List<Triangle>(nextTris); nextTris = new List<Triangle>(); //triforces = new List<Triforce>(); foreach (Triangle tri in currentTris) { //Bisect Vector3 v1 = (tri.v1+tri.v2)/2.0f; Vector3 v2 = (tri.v2+tri.v3)/2.0f; Vector3 v3 = (tri.v3+tri.v1)/2.0f; //Project onto sphere v1 *= (float)(1.902084 / v1.magnitude) * scale; //golden rectangle sphere radius 1.902084 v2 *= (float)(1.902084 / v2.magnitude) * scale; v3 *= (float)(1.902084 / v3.magnitude) * scale; //Add the four new triangles Triangle mid = new Triangle(v1, v2, v3, tri, TriforcePosition.Mid, subdivisions); nextTris.Add(mid); // Center of triforce Triangle top = new Triangle(tri.v1, v1, v3, tri, TriforcePosition.Top, subdivisions); nextTris.Add(top); Triangle right = new Triangle(v1, tri.v2, v2, tri, TriforcePosition.Right, subdivisions); nextTris.Add(right); Triangle left = new Triangle(v3, v2, tri.v3, tri, TriforcePosition.Left, subdivisions); nextTris.Add(left); tri.AssignChildren(mid, top, left, right); } //Set Neighbors foreach (Triangle tri in currentTris) { tri.childMid.AssignNeighbors(tri.childTop, tri.childRight, tri.childLeft); tri.childTop.AssignNeighbors(tri.NeighborOne(tri.childTop), tri.childMid, tri.NeighborTwo(tri.childTop)); tri.childRight.AssignNeighbors(tri.NeighborOne(tri.childRight), tri.NeighborTwo(tri.childRight), tri.childMid); tri.childLeft.AssignNeighbors(tri.childMid, tri.NeighborOne(tri.childLeft), tri.NeighborTwo(tri.childLeft)); } //Save our subdivided levels subdividedTris.Add(nextTris); } //Create SphereTiles, give them neighbors foreach (Triangle tri in nextTris) { //Tiles to assign SphereTile st1 = null, st2 = null, st3 = null; //Create empty SphereTiles, or, if we've already created a SphereTile at this point just reference it foreach (SphereTile st in sTiles) { if ((Vector3)st.center == (Vector3)tri.v1) { st1 = st; } if ((Vector3)st.center == (Vector3)tri.v2) { st2 = st; } if ((Vector3)st.center == (Vector3)tri.v3) { st3 = st; } } if (st1 == null) { st1 = new SphereTile(tri.v1, origin); sTiles.Add(st1); } if (st2 == null) { st2 = new SphereTile(tri.v2, origin); sTiles.Add(st2); } if (st3 == null) { st3 = new SphereTile(tri.v3, origin); sTiles.Add(st3); } //Add in the new neighbors from this triangle st1.neighborList.Add(st2); st1.neighborList.Add(st3); st2.neighborList.Add(st1); st2.neighborList.Add(st3); st3.neighborList.Add(st1); st3.neighborList.Add(st2); //Add this triangle as an inital triangle in each spheretile st1.subTriangles.Add(tri); st2.subTriangles.Add(tri); st3.subTriangles.Add(tri); } //dualCenters = dualCenters.Distinct().ToList(); // --- Number sphere tiles --- int count = 0; //Build the SphereTiles! foreach(SphereTile st in sTiles) { st.index = count; count++; //st.scale *= scale; st.Build(); } }
void BuildPlates() { plates = new List<Plate>(); SphereTile toOrigin = new SphereTile(); //first get toPlate and toOrigin then make the plates for (int i = 0; i < tPlates.Count; i++) { List<SphereTile> toPlate = new List<SphereTile>(); foreach (SphereTile st in sTiles) { if (st.plate == i) { toPlate.Add(st); } } int x = 0; foreach (SphereTile st in toPlate) { if (st.plateOrigin) { toOrigin = st; x++; } if(x>1) { Debug.Log(x); } } plates.Add(new Plate(toPlate, toOrigin)); } //now get boundary by looking at neighbors List<SphereTile> toBoundary = new List<SphereTile>(); //Debug.Log(plates.Count); foreach (Plate p in plates) { foreach (SphereTile st in p.tiles) { foreach (SphereTile stn in st.neighborList) { //Debug.Log("parent " + st.plate + " neighbor " + stn.plate); if (stn.plate != st.plate) { //If a neighbor has a plate index other than the parent's, add it to the boundary toBoundary.Add(st); st.boundary = true; break; } } } //set boundary p.boundary = toBoundary; //Boundaries are done, now let's calculate heights based on them } }