public LcLink LinkTo(string lptname, Vector3 v, string lname = "") { var lp0 = anchorpt; if (lp0 == null) { throw new UnityException("Anchorpt null"); } lptname = gm.addprefix(lptname); v = gm.modv(v); var lp1 = GetNewNode(lptname, v); if (lname == "") { lname = lp0.name + ":" + lptname; } else { lname = gm.addprefix(lname); } if (linkdict.ContainsKey(lname)) { throw new UnityException("LinkTo: Duplicate Link name:" + lname); } linknamelist.Add(lname); var lnk = new LcLink(this, lname, lp0, lp1); linkdict.Add(lname, lnk); //lklistlist.Add(lnk); anchorpt = lp1; return(lnk); }
public Weg(LcLink link, LcNode tonode, LcNode frnode) { this.link = link; this.toNode = tonode; this.frNode = frnode; this.distance = Vector3.Distance(frnode.pt, tonode.pt); }
//private static int newnamenumber = 0; //public static string genuniquename() //{ // var newname = "uniqlinkname-" + newnamenumber; // newnamenumber++; // return newname; //} public LcLink(LinkCloud lc, string name, LcNode node1, LcNode node2) { this.lc = lc; this.name = name; this.node1 = node1; this.node2 = node2; len = Vector3.Distance(node1.pt, node2.pt); linkLink(); }
public LcLink LinkTo(string newanchor, string lptname, Vector3 v, string lname = "") { if (!isnodename(newanchor)) { throw new UnityException("LinkTo: Unknown anchor:" + newanchor); } anchorpt = nodedict[newanchor]; return(LinkTo(lptname, v, lname)); }
public LcNode GetNewNode(string name, Vector3 v) { if (nodedict.ContainsKey(name)) { return(nodedict[name]); } // otherwise we need to make it nodenamelist.Add(name); var node = new LcNode(this, name, v); nodedict.Add(name, node); return(node); }
Path reconstructPath(LcNode spt, LcNode ept) { var cflist = new LinkedList <LcNode>(); cflist.AddLast(ept); var curpt = ept; int nloop = 0; while (curpt != spt) { nloop = nloop + 1; if (nloop > (4 * nodenamelist.Count)) { GraphUtil.Log("Iter count exceeded 1 in reconstructPath"); return(null); } cflist.AddLast(curpt); curpt = curpt.cameFrom; } cflist.AddLast(curpt); nloop = 0; var path = new Path(spt); var cur = cflist.Last; while (cur != null) { nloop = nloop + 1; if (nloop > (4 * nodenamelist.Count)) { GraphUtil.Log("Iter count exceeded 2 in reconstructPath"); return(null); } var next = cur.Previous; if (next != null) { var nxpt = next.Value.pt; foreach (var w in cur.Value.wegtos) { if (nxpt == w.toNode.pt) { path.AddWaypt(w); continue; } } } cur = next; } path.Finish(); return(path); }
public LcLink AddLink(string lname, LcNode lp1, LcNode lp2) { lname = gm.addprefix(lname); if (linkdict.ContainsKey(lname)) { throw new UnityException("AddLink: Duplicate Link name:" + lname); } linknamelist.Add(lname); var lnk = new LcLink(this, lname, lp1, lp2); linkdict.Add(lname, lnk); //lklistlist.Add(lnk); return(lnk); }
public LcNode AddNode(string name, Vector3 v) { name = gm.addprefix(name); if (nodedict.ContainsKey(name)) { throw new UnityException("Duplicate Point name"); } v = gm.modv(v); nodenamelist.Add(name); var lpt = new LcNode(this, name, v); nodedict.Add(name, lpt); anchorpt = lpt; return(lpt); }
LcNode findminfscore(HashSet <LcNode> openset) { var minf = 99e30f; LcNode minlpt = null; foreach (var lpt in openset) { if (lpt.fScore < minf) { minf = lpt.fScore; minlpt = lpt; } } return(minlpt); }
public LcNode FindClosestNode(Vector3 pt) { float mindist = 9e30f; LcNode minnode = null; foreach (var nname in nodenamelist) { var node = GetNode(nname); var dist = Vector3.Distance(pt, node.pt); if (dist < mindist) { mindist = dist; minnode = node; } } return(minnode); }
public LcNode FindClosestNodeToNodeGo(LcNode targetnode) { float mindist = 9e30f; LcNode minnode = null; var gopt = targetnode.go.transform.position; foreach (var nname in nodenamelist) { if (nname != targetnode.name) { var node = GetNode(nname); var dist = Vector3.Distance(gopt, node.pt); if (dist < mindist) { mindist = dist; minnode = node; } } } return(minnode); }
public LcLink(GraphCtrl grc, string name, LcNode node1, LcNode node2, LinkUse usetype = LinkUse.legacy, string comment = "") { this.grc = grc; this.usetype = usetype; this.name = name; this.node1 = node1; this.node2 = node2; this.node1spec = ""; this.node2spec = ""; this.comment = ""; var regid = grc.regman.curNodeRegion.regid; if (node1.regid == node2.regid) { regid = node1.regid; } this.regid = regid; this.regionStepIdx = grc.regman.curNodeRegion.GetCurStepIdx(); len = Vector3.Distance(node1.pt, node2.pt); LinkLink(); }
public void CreateSpherePoints(int nlng = 10, int nlat = 10, float rad = 5.0f, float heit = 0) { grc.gm.initmods(); grc.gm.mod_name_pfx = getmodelprefix("sph-", forcecount: true); var optar = new LcNode[nlng, nlat]; for (int i = 0; i < nlat; i++) { float alat = Mathf.PI * (90 - (i * 180f / (nlat - 1))) / 180; float y = rad * Mathf.Sin(alat) + heit; float crad = rad * Mathf.Cos(alat); for (int j = 0; j < nlng; j++) { float alng = Mathf.PI * (j * 360f / nlng) / 180; float z = crad * Mathf.Sin(alng); float x = crad * Mathf.Cos(alng); var pt = new Vector3(x, y, z); var pname = "pt." + i.ToString() + "." + j.ToString(); LcNode npt = grc.AddNode(pname, pt); optar[i, j] = npt; } } for (int i = 0; i < nlat; i++) { for (int j = 0; j < nlng; j++) { var jto = (j + 1) % nlng; var lname = "lk.h." + i + "." + j; grc.AddLink(lname, optar[i, j], optar[i, jto]); if (i > 0) { var lname1 = "lk.v." + i + "." + j; grc.AddLink(lname1, optar[i - 1, j], optar[i, j]); } } } }
public void AstarInit() { cameFrom = null; gScore = 9e30f; fScore = 9e30f; }
public float heuristic_cost_estimate(LcNode topt) { var f = Vector3.Distance(pt, topt.pt); return(f); }
public Path(LcNode start) { this.start = start; startpt = start.pt; }
public void Finish() { end = waypts[waypts.Count - 1].toNode; endpt = end.pt; }