///// <summary> ///// Object.Equals override. ///// Tells if two nodes are equal by comparing positions. ///// </summary> ///// <exception cref="ArgumentException">A Node cannot be compared with another type.</exception> ///// <param name="O">The node to compare with.</param> ///// <returns>'true' if both nodes are equal.</returns> //public override bool Equals(object O) //{ // if (O is MeshableObject) // { // return _GlobalPos == ((MeshableObject)O).GlobalPosition(); // } // //if (O is Vector3d) // //{ // // return Create((Vector3d)O).Equals(this); // //} // throw new ArgumentException("Type " + O.GetType() + " cannot be compared with type " + GetType() + " !"); //} /// <summary> /// Returns a copy of this node. /// </summary> /// <returns>The reference of the new object.</returns> public object Clone() { SimWaypointImpl N = new SimWaypointImpl(_LocalPos, _GlobalPos, CIndex, Plane, PathStore); N._Passable = _Passable; return(N); }
public static SimWaypoint CreateLocal(Vector3 from, CollisionPlane CP) { SimPathStore PathStore = CP.PathStore; float POINTS_PER_METER = PathStore.POINTS_PER_METER; int PX = PathStore.ARRAY_X(from.X); int PY = PathStore.ARRAY_Y(from.Y); SimWaypoint WP; CollisionIndex CI = CollisionIndex.CreateCollisionIndex(from, PathStore); lock (CI) { WP = CI.FindWayPoint(from.Z); if (WP != null) { return(WP); } from.X = PX / POINTS_PER_METER; from.Y = PY / POINTS_PER_METER; Vector3d GlobalPos = PathStore.LocalToGlobal(from); if (GlobalPos.X < 256 || GlobalPos.Y < 256) { CollisionPlane.Debug("bad global " + GlobalPos); } WP = new SimWaypointImpl(from, GlobalPos, CI, CP, PathStore); WP.IsPassable = true; } // wp._IncomingArcs = new ArrayList(); // wp._OutgoingArcs = new ArrayList(); // PathStore.EnsureKnown(wp); return(WP); }
/// <summary> /// Determines the bounding box of the entire graph. /// </summary> /// <exception cref="InvalidOperationException">Impossible to determine the bounding box for this graph.</exception> /// <param name="MinPoint">The point of minimal coordinates for the box.</param> /// <param name="MaxPoint">The point of maximal coordinates for the box.</param> public void BoundingBox(out double[] MinPoint, out double[] MaxPoint) { try { SimWaypointImpl.BoundingBox(Nodes, out MinPoint, out MaxPoint); } catch (ArgumentException e) { throw new InvalidOperationException("Impossible to determine the bounding box for this graph.\n", e); } }
public SimWaypoint GetWayPoint(float z) { CollisionPlane CP = CollisionPlaneAt(z); SimWaypoint v; if (!WaypointsHash.TryGetValue(CP, out v)) { v = SimWaypointImpl.CreateLocal(_LocalPos.X, _LocalPos.Y, z, PathStore); v.Plane = CP; } return(v); }
private SimWaypoint CreateXYZ(int x, int y) { int ix = IndexX(x); int iy = IndexY(y); if (saved[ix, iy] == null) { saved[ix, iy] = SimWaypointImpl.CreateGlobal(x, y, SimZ); } SimWaypoint wp = saved[ix, iy]; AddNode(wp); return(wp); }
/// <summary> /// /// </summary> /// <param name="v3"></param> /// <returns></returns> public SimWaypoint CreateClosestWaypoint(Vector3d v3) { double Dist; SimWaypoint Closest = ClosestNode(v3.X, v3.Y, v3.Z, out Dist, false); SimWaypoint V3Waypoint = SimWaypointImpl.CreateGlobal(v3); if (Closest != V3Waypoint) { IList <SimWaypoint> more = ClosestNodes(V3Waypoint, Dist, Dist * 2, false); AddNode(V3Waypoint); Intern2Arc(Closest, V3Waypoint, 1f); foreach (SimWaypoint P in more) { Intern2Arc(P, V3Waypoint, 1f); } } return(V3Waypoint); }
public virtual SimWaypoint GetPointAt(double p, SimPathStore PathStore) { double len = Length; if (p <= 0.0f) { return(StartNode); } if (p >= len) { return(EndNode); } Vector3d dir = EndNode.GlobalPosition - StartNode.GlobalPosition; double X = (dir.X / len) * p; double Y = (dir.Y / len) * p; double Z = (dir.Z / len) * p; return(SimWaypointImpl.CreateGlobal(new Vector3d(X, Y, Z))); }
/// <summary> /// /// </summary> /// <param name="v3"></param> /// <param name="radius"></param> /// <param name="numPoints"></param> /// <param name="Weight"></param> /// <returns></returns> public SimWaypoint CreateClosestWaypointBox(Vector3d v3, double radius, int numPoints, double Weight) { SimWaypoint node = SimWaypointImpl.CreateGlobal(v3); double radiansStep = Math.PI * 2 / numPoints; SimWaypoint Last = node; Dictionary <SimWaypoint, List <SimWaypoint> > newWaypoints = new Dictionary <SimWaypoint, List <SimWaypoint> >(); for (int Step = 0; Step < numPoints; Step++) { double ThisAngle = Step * radiansStep; Vector3d vectNew = (new Vector3d((double)Math.Cos(ThisAngle), (double)Math.Sin(ThisAngle), 0) * radius) + v3; SimWaypoint nodeNew = SimWaypointImpl.CreateGlobal(v3); List <SimWaypoint> closeNodes = new List <SimWaypoint>(); newWaypoints[nodeNew] = closeNodes; double Dist; closeNodes.Add(node); closeNodes.Add(Last); closeNodes.Add(ClosestNode(vectNew.X, vectNew.Y, vectNew.Z, out Dist, false)); Last = nodeNew; } foreach (SimWaypoint P in newWaypoints.Keys) { AddNode(P); foreach (SimWaypoint V in newWaypoints[P]) { if (V == null) { continue; } AddNode(V); if (P != V) { Intern2Arc(P, V, Weight); } } } return(node); }
/// <summary> /// Creates a node, adds to the graph and returns its reference. /// </summary> /// <param name="x">X coordinate.</param> /// <param name="y">Y coordinate.</param> /// <param name="z">Z coordinate.</param> /// <returns>The reference of the new node / null if the node is already in the graph.</returns> public SimWaypoint AddNode(double x, double y, double z) { SimWaypoint NewNode = SimWaypointImpl.CreateGlobal(x, y, z); return(AddNode(NewNode) ? NewNode : null); }
public static SimWaypoint CreateLocal(Vector3 from, CollisionPlane CP) { SimPathStore PathStore = CP.PathStore; float POINTS_PER_METER = PathStore.POINTS_PER_METER; int PX = PathStore.ARRAY_X(from.X); int PY = PathStore.ARRAY_Y(from.Y); SimWaypoint WP; CollisionIndex CI = CollisionIndex.CreateCollisionIndex(from, PathStore); lock (CI) { WP = CI.FindWayPoint(from.Z); if (WP != null) return WP; from.X = PX / POINTS_PER_METER; from.Y = PY / POINTS_PER_METER; Vector3d GlobalPos = PathStore.LocalToGlobal(from); if (GlobalPos.X < 256 || GlobalPos.Y < 256) { CollisionPlane.Debug("bad global " + GlobalPos); } WP = new SimWaypointImpl(from, GlobalPos, CI, CP, PathStore); WP.IsPassable = true; } // wp._IncomingArcs = new ArrayList(); // wp._OutgoingArcs = new ArrayList(); // PathStore.EnsureKnown(wp); return WP; }
///// <summary> ///// Object.Equals override. ///// Tells if two nodes are equal by comparing positions. ///// </summary> ///// <exception cref="ArgumentException">A Node cannot be compared with another type.</exception> ///// <param name="O">The node to compare with.</param> ///// <returns>'true' if both nodes are equal.</returns> //public override bool Equals(object O) //{ // if (O is MeshableObject) // { // return _GlobalPos == ((MeshableObject)O).GlobalPosition(); // } // //if (O is Vector3d) // //{ // // return Create((Vector3d)O).Equals(this); // //} // throw new ArgumentException("Type " + O.GetType() + " cannot be compared with type " + GetType() + " !"); //} /// <summary> /// Returns a copy of this node. /// </summary> /// <returns>The reference of the new object.</returns> public object Clone() { SimWaypointImpl N = new SimWaypointImpl(_LocalPos, _GlobalPos, CIndex, Plane, PathStore); N._Passable = _Passable; return N; }