//public List<int> mazeList = new List<int>(); public void MakeMaze(int _y, int _x) { m_iRowDimensions = _y; m_iColDimensions = _x; m_iMaze = new int[m_iRowDimensions * m_iColDimensions]; //row is Y, col is X int[Y,X] [i,j] [row,col] vec2 pot = new vec2(); mf.yt.triggerDistanceOffset += 3; mf.turn.BuildTurnLines(); for (int i = 0; i < mf.self.m_iRowDimensions; i++) { for (int j = 0; j < mf.self.m_iColDimensions; j++) { pot.easting = (j * 2) + (int)mf.minFieldX; pot.northing = (i * 2) + (int)mf.minFieldY; if (!mf.turn.PointInsideWorkArea(pot)) { m_iMaze[(i * m_iColDimensions) + j] = 1; } else { m_iMaze[(i * m_iColDimensions) + j] = 0; } } } mf.yt.triggerDistanceOffset -= 3; mf.turn.BuildTurnLines(); Maze = new CMazePath(m_iRowDimensions, m_iColDimensions, m_iMaze); }
public List <vec3> SearchForPath(vec3 start, vec3 stop) { CMazePath maze = new CMazePath(mazeRowYDim, mazeColXDim, mazeArr); List <vec3> mazeList = maze.Search((int)((start.northing - mf.minFieldY) / mf.mazeGrid.mazeScale), (int)((start.easting - mf.minFieldX) / mf.mazeGrid.mazeScale), (int)((stop.northing - mf.minFieldY) / mf.mazeGrid.mazeScale), (int)((stop.easting - mf.minFieldX) / mf.mazeGrid.mazeScale)); if (mazeList == null) { return(mazeList); } //we find our way back, we want to go forward, so reverse the list mazeList.Reverse(); int cnt = mazeList.Count; if (cnt < 3) { mazeList.Clear(); return(mazeList); } //the temp array vec3[] arr2 = new vec3[cnt]; mazeList.CopyTo(arr2); mazeList.Clear(); for (int h = 0; h < cnt; h++) { arr2[h].easting = (arr2[h].easting * mazeScale) + mf.minFieldX; arr2[h].northing = (arr2[h].northing * mazeScale) + mf.minFieldY; mazeList.Add(arr2[h]); } //fill in the gaps for (int i = 0; i < cnt; i++) { int j = i + 1; if (j == cnt) { j = i; } double distance = glm.Distance(mazeList[i], mazeList[j]); if (distance > 2) { vec3 pointB = new vec3((mazeList[i].easting + mazeList[j].easting) / 2.0, (mazeList[i].northing + mazeList[j].northing) / 2.0, 0); mazeList.Insert(j, pointB); cnt = mazeList.Count; i--; //go back to original point again } } cnt = mazeList.Count; //the temp array vec3[] arr = new vec3[cnt]; //how many samples int smPts = mazeScale; //read the points before and after the setpoint for (int s = 0; s < smPts; s++) { arr[s].easting = mazeList[s].easting; arr[s].northing = mazeList[s].northing; arr[s].heading = mazeList[s].heading; } for (int s = cnt - smPts; s < cnt; s++) { arr[s].easting = mazeList[s].easting; arr[s].northing = mazeList[s].northing; arr[s].heading = mazeList[s].heading; } //average them - center weighted average for (int i = smPts; i < cnt - smPts; i++) { for (int j = -smPts; j < smPts; j++) { arr[i].easting += mazeList[j + i].easting; arr[i].northing += mazeList[j + i].northing; } arr[i].easting /= (smPts * 2); arr[i].northing /= (smPts * 2); arr[i].heading = mazeList[i].heading; } //clear the list and reload with calc headings - first and last droppped mazeList.Clear(); for (int i = mazeScale; i < cnt - mazeScale; i++) { vec3 pt3 = arr[i]; pt3.heading = Math.Atan2(arr[i + 1].easting - arr[i].easting, arr[i + 1].northing - arr[i].northing); if (pt3.heading < 0) { pt3.heading += glm.twoPI; } mazeList.Add(pt3); } return(mazeList); }