public void GetPortals() { Portals.Clear(); for (int i = 0; i < TriPath.Count - 1; i++) { Pair <Vector3, Vector3> portal = new Pair <Vector3, Vector3>(); if (TriPath[i].U == TriPath[i + 1].U || TriPath[i].U == TriPath[i + 1].V || TriPath[i].U == TriPath[i + 1].W) { portal = new Pair <Vector3, Vector3>(TriPath[i].U.A, TriPath[i].U.B); } else if (TriPath[i].V == TriPath[i + 1].U || TriPath[i].V == TriPath[i + 1].V || TriPath[i].V == TriPath[i + 1].W) { portal = new Pair <Vector3, Vector3>(TriPath[i].V.A, TriPath[i].V.B); } else { portal = new Pair <Vector3, Vector3>(TriPath[i].W.A, TriPath[i].W.B); } if (Op2D.Cross(portal.first - TriPath[i].Center, portal.second - TriPath[i].Center) < 0) { Vector3 tmp = portal.first; portal.first = portal.second; portal.second = tmp; } Portals.Add(portal); } Portals.Add(new Pair <Vector3, Vector3>(EndPt, EndPt)); }
public List <Vector3> Funnel() { List <Vector3> path = new List <Vector3>(); Vector3 right, left, current; int rightId, leftId; right = left = current = StartPt; rightId = leftId = 0; for (int i = 0; i < Portals.Count; i++) { if (left == current || Op2D.Cross(left - current, Portals[i].first - current) >= 0) { if (Op2D.Cross(right - current, Portals[i].first - current) > 0) { path.Add(right); current = left = right; i = leftId = rightId; continue; } else { left = Portals[i].first; leftId = i; } } if (right == current || Op2D.Cross(right - current, Portals[i].second - current) <= 0) { if (Op2D.Cross(left - current, Portals[i].second - current) < 0) { path.Add(left); current = right = left; i = rightId = leftId; continue; } else { right = Portals[i].second; rightId = i; } } } path.Add(EndPt); Engine.Singleton.SceneManager.DestroyManualObject("line"); // destroy the SceneNode (or keep it to add other manual objects) Engine.Singleton.SceneManager.DestroySceneNode("line_node"); ManualObject manOb = Engine.Singleton.SceneManager.CreateManualObject("line"); manOb.Begin("line_material", RenderOperation.OperationTypes.OT_LINE_LIST); for (int i = 1; i < path.Count; i++) { Vector3 adam = path[i - 1]; adam.y = 0.4f; manOb.Position(adam); Vector3 adam1 = path[i]; adam1.y = 0.4f; manOb.Position(adam1); } manOb.End(); SceneNode moNode = Engine.Singleton.SceneManager.RootSceneNode.CreateChildSceneNode("line_node"); moNode.SetPosition(0, 0, 0); moNode.AttachObject(manOb); return(path); }