public List <Vector3> ChimeraNodeToVector3(List <ChimeraNode> chVector) { List <Vector3> result = new List <Vector3>(); for (int i = 0; i < chVector.Count; i++) { ChimeraNode cNode = chVector[i]; Vector3 cPos = new Vector3() { x = cNode.x, y = cNode.y, z = 0f }; Vector3 newPos = Camera.main.ScreenToWorldPoint(cPos) * ChimeraWorld.rescaler; newPos.z = -5; result.Add(newPos); } return(result); }
private void RenderTile(Chimera.ChimeraNode node) { float cX = node.x; float cY = node.y; lineMaterial.SetPass(0); GL.Begin(GL.LINES); if (node.a == 0 && node.b == 0) { GL.Color(Color.red); } else { GL.Color(Color.green); } ///////////////// ChimeraPixelsToWorldPoint InternalPoint = (float x, float y, float z) => { Vector3 point = new Vector3(x, y, z); Vector3 transformPoint = Camera.main.ScreenToWorldPoint(point); transformPoint *= ChimeraWorld.rescaler; transformPoint.z = 0; return(transformPoint); }; GL.Vertex(InternalPoint(cX - wCell / 2, cY, 0)); GL.Vertex(InternalPoint(cX, cY - hCell / 2, 0)); GL.Vertex(InternalPoint(cX, cY - hCell / 2, 0)); GL.Vertex(InternalPoint(cX + wCell / 2, cY, 0)); GL.Vertex(InternalPoint(cX + wCell / 2, cY, 0)); GL.Vertex(InternalPoint(cX, cY + hCell / 2, 0)); GL.Vertex(InternalPoint(cX, cY + hCell / 2, 0)); GL.Vertex(InternalPoint(cX - wCell / 2, cY, 0)); GL.End(); }
void OnPostRender() { if (lineMaterial != null) { if (gridNodes == null) { gridNodes = ChimeraWorld.GetChimeraGrid; } foreach (KeyValuePair <int, Dictionary <int, Chimera.ChimeraNode> > pair in gridNodes) { foreach (KeyValuePair <int, Chimera.ChimeraNode> pair2 in pair.Value) { Chimera.ChimeraNode node = pair2.Value; RenderTile(node); } } Chimera.ChimeraEventDispather.Instance.DispatchEvent(Chimera.ChimeraEvent.DrawComplete); } }
public void DrawNode(Chimera.ChimeraNode node) { }
private void ComputationVertex() { int g = (Mathf.CeilToInt((rangeGrid.size.x / 2 + cPoint.x) / wCell)); int f = (Mathf.CeilToInt((rangeGrid.size.y / 2 + cPoint.y) / hCell)); topLeftNode = new ChimeraNode((int)(Screen.width / 2 - g * wCell), (int)(Screen.height / 2 - f * hCell) + hCell / 3); topLeftNode.a = g + f; topLeftNode.b = f - g; g = topLeftNode.a; f = topLeftNode.b; int wCount = Mathf.CeilToInt(wGrid / wCell); int hCount = Mathf.CeilToInt(hGrid / (hCell / 2)); int cx = topLeftNode.x; int cy = topLeftNode.y; int cg = g; int cf = f; for (int i = 0; i < hCount; i++) { for (int j = 0; j < wCount; j++) { cx = topLeftNode.x + j * wCell; cy = topLeftNode.y + i * hCell / 2; if (i % 2 != 0) { cx = cx - wCell / 2; } cg = g - j; cf = f + j; ChimeraNode vertex = new ChimeraNode(cx, cy); vertex.a = cg; vertex.b = cf; Debug.Log(cg + " " + cf); if (!gridNodes.ContainsKey(cg)) { gridNodes.Add(cg, new Dictionary <int, ChimeraNode>()); } if (gridNodes.ContainsKey(cg) && !gridNodes[cg].ContainsKey(cf)) { gridNodes[cg].Add(cf, vertex); } } if (i % 2 != 0) { g -= 1; } else { f -= 1; } } ChimeraEventDispather.Instance.DispatchEvent(ChimeraEvent.CalculateComplete); }
private List <Chimera.ChimeraNode> GetNeighbors(Chimera.ChimeraNode currentNode) { _neighbors.Clear(); int x = currentNode.x; int y = currentNode.y; _widthMax = (int)wGrid - wCell / 2; _heightMax = (int)hGrid - hCell / 2; _widthMin = wCell; _heightMin = (int)hCell / 2; ChimeraNode top = null, bottom = null, left = null, right = null; if (y > _heightMin) { top = GetNode(currentNode.a, currentNode.b - 1); _neighbors.Add(top); } if (y < _heightMax) { bottom = GetNode(currentNode.a, currentNode.b + 1); _neighbors.Add(bottom); } if (x > _widthMin) { left = GetNode(currentNode.a - 1, currentNode.b); _neighbors.Add(left); // try // { // if(!left.isWall) // { // if (y > _heightMin && !top.isWall) // { // _neighbors.Add(GetNode(currentNode.a - 1, currentNode.b - 1)); // } // if (y < _heightMax && !bottom.isWall) // { // _neighbors.Add(GetNode(currentNode.a - 1, currentNode.b + 1)); // } // } // } // catch // { // if (_neighbors[_neighbors.Count - 1] == null) // { // _neighbors.Remove(_neighbors[_neighbors.Count - 1]); // } // } } if (x < _widthMax) { right = GetNode(currentNode.a + 1, currentNode.b); _neighbors.Add(right); // try // { // if (!right.isWall) // { // if (y > _heightMin && !top.isWall) // { // _neighbors.Add (GetNode(currentNode.a + 1, currentNode.b - 1)); // } // if(y < _heightMax && !bottom.isWall) // { // _neighbors.Add(GetNode(currentNode.a + 1, currentNode.b + 1)); // } // } // } // catch // { // if (_neighbors[_neighbors.Count - 1] == null) // { // _neighbors.Remove(_neighbors[_neighbors.Count - 1]); // } // } } return(_neighbors); }