当前位置: 首页>>代码示例>>C#>>正文


C# Pathfinding.Int2类代码示例

本文整理汇总了C#中Pathfinding.Int2的典型用法代码示例。如果您正苦于以下问题:C# Int2类的具体用法?C# Int2怎么用?C# Int2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Int2类属于Pathfinding命名空间,在下文中一共展示了Int2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Min

		public static Int2 Min (Int2 a, Int2 b) {
			return new Int2 (Math.Min (a.x,b.x), Math.Min (a.y,b.y));
		}
开发者ID:Marchys,项目名称:fanalet,代码行数:3,代码来源:Int3.cs

示例2: Left

		/** Returns if \a p lies on the left side of the line \a a - \a b. Also returns true if the points are colinear */
		public static bool Left (Int2 a, Int2 b, Int2 c) {
			return (long)(b.x - a.x) * (long)(c.y - a.y) - (long)(c.x - a.x) * (long)(b.y - a.y) <= 0;
		}
开发者ID:Marchys,项目名称:fanalet,代码行数:4,代码来源:AstarMath.cs

示例3: Intersects

		/** Returns if the line segment \a a2 - \a b2 intersects the line segment \a a - \a b.
		 * If only the endpoints coincide, the result is undefined (may be true or false).
		 */
		public static bool Intersects (Int2 a, Int2 b, Int2 a2, Int2 b2) {
			return Left (a,b,a2) != Left (a,b,b2) && Left (a2,b2,a) != Left (a2,b2,b);
		}
开发者ID:Marchys,项目名称:fanalet,代码行数:6,代码来源:AstarMath.cs

示例4: Max

		public static Int2 Max (Int2 a, Int2 b) {
			return new Int2(System.Math.Max(a.x, b.x), System.Math.Max(a.y, b.y));
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:3,代码来源:Int3.cs

示例5: NearestPointFactor

		/** Factor of the nearest point on the segment.
		 * Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line.
		 * The closest point can be got by (end-start)*factor + start;
		 */
		public static float NearestPointFactor (Int2 lineStart, Int2 lineEnd, Int2 point)
	    {
	    	var lineDirection = lineEnd-lineStart;
	    	double magn = lineDirection.sqrMagnitudeLong;
	        
	        double closestPoint = Int2.DotLong(point-lineStart,lineDirection); //Vector3.Dot(lineDirection,lineDirection);
	        if (magn != 0) closestPoint /= magn;

			return (float)closestPoint;
	        //return closestPoint / magn;
	    }
开发者ID:Marchys,项目名称:fanalet,代码行数:15,代码来源:AstarMath.cs

示例6: NodeBounds

		/** Calculates the bounding box in XZ space of all nodes between \a from (inclusive) and \a to (exclusive) */
		static IntRect NodeBounds (MeshNode[] nodes, int from, int to) {
			if (to - from <= 0) throw new ArgumentException();

			var first = nodes[from].GetVertex(0);
			var min = new Int2(first.x,first.z);
			Int2 max = min;

			for (int j = from; j < to; j++) {
				var node = nodes[j];
				var nverts = node.GetVertexCount();
				for (int i = 0; i < nverts; i++) {
					var p = node.GetVertex(i);
					min.x = Math.Min (min.x, p.x);
					min.y = Math.Min (min.y, p.z);

					max.x = Math.Max (max.x, p.x);
					max.y = Math.Max (max.y, p.z);
				}
			}

			return new IntRect (min.x, min.y, max.x, max.y);
		}
开发者ID:smclallen,项目名称:Galactic_Parcel_Service,代码行数:23,代码来源:BBTree.cs

示例7: DotLong

		/** Dot product of the two coordinates */
		public static long DotLong (Int2 a, Int2 b) {
			return (long)a.x*(long)b.x + (long)a.y*(long)b.y;
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:4,代码来源:Int3.cs

示例8: IsClockwiseMargin

		public static bool IsClockwiseMargin (Int2 a, Int2 b, Int2 c) {
			return VectorMath.IsClockwiseOrColinear(a, b, c);
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:3,代码来源:AstarMath.cs

示例9: Intersects

		public static bool Intersects (Int2 start1, Int2 end1, Int2 start2, Int2 end2) {
			return VectorMath.SegmentsIntersect(start1, end1, start2, end2);
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:3,代码来源:AstarMath.cs

示例10: ClosestPointOnLineFactor

		/** Factor of the nearest point on the segment.
		 * Returned value is in the range [0,1] if the point lies on the segment otherwise it just lies on the line.
		 * The closest point can be calculated using (end-start)*factor + start;
		 */
		public static float ClosestPointOnLineFactor (Int2 lineStart, Int2 lineEnd, Int2 point) {
			var lineDirection = lineEnd - lineStart;
			double magn = lineDirection.sqrMagnitudeLong;

			double closestPoint = Int2.DotLong(point - lineStart, lineDirection);

			if (magn != 0) closestPoint /= magn;

			return (float)closestPoint;
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:14,代码来源:AstarMath.cs

示例11: Left

		public static bool Left (Int2 a, Int2 b, Int2 p) {
			return VectorMath.RightOrColinear(a, b, p);
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:3,代码来源:AstarMath.cs

示例12: ContainsPoint

		/** Returns if the triangle \a ABC contains the point \a p.
		 * The triangle vertices are assumed to be laid out in clockwise order.
		 */
		public static bool ContainsPoint (Int2 a, Int2 b, Int2 c, Int2 p) {
			return VectorMath.IsClockwiseOrColinear(a, b, p) && VectorMath.IsClockwiseOrColinear(b, c, p) && VectorMath.IsClockwiseOrColinear(c, a, p);
		}
开发者ID:Xylord,项目名称:Project-Feels,代码行数:6,代码来源:AstarMath.cs

示例13: Linecast

		/** Returns if there is an obstacle between \a \a and \a \b on the graph.
		 * \param [in] _a Point to linecast from
		 * \param [in] _b Point to linecast to
		 * \param [out] hit Contains info on what was hit, see GraphHitInfo
		 * \param [in] hint \deprecated
		 * \param trace If a list is passed, then it will be filled with all nodes the linecast traverses
		 *
		 * This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions.
		 *
		 * It uses a method similar to Bresenham's line algorithm but it has been
		 * extended to allow the start and end points to lie on non-integer coordinates
		 * (which makes the math a bit trickier).
		 *
		 * \see https://en.wikipedia.org/wiki/Bresenham's_line_algorithm
		 *
		 * \version In 3.6.8 this method was rewritten to improve accuracy and performance.
		 * Previously it used a sampling approach which could cut corners of obstacles slightly
		 * and was pretty inefficient.
		 *
		 * \astarpro
		 */
		public bool Linecast (Vector3 _a, Vector3 _b, GraphNode hint, out GraphHitInfo hit, List<GraphNode> trace) {
			hit = new GraphHitInfo ();

			hit.origin = _a;

			Vector3 aInGraphSpace = inverseMatrix.MultiplyPoint3x4(_a);
			Vector3 bInGraphSpace = inverseMatrix.MultiplyPoint3x4(_b);

			// Clip the line so that the start and end points are on the graph
			if (!ClipLineSegmentToBounds (aInGraphSpace, bInGraphSpace, out aInGraphSpace, out bInGraphSpace)) {
				// Line does not intersect the graph
				// So there are no obstacles we can hit
				return false;
			}

			// Find the closest nodes to the start and end on the part of the segment which is on the graph
			var n1 = GetNearest (matrix.MultiplyPoint3x4(aInGraphSpace),NNConstraint.None).node as GridNodeBase;
			var n2 = GetNearest (matrix.MultiplyPoint3x4(bInGraphSpace),NNConstraint.None).node as GridNodeBase;

			if (!n1.Walkable) {
				hit.node = n1;
				// Hit point is the point where the segment intersects with the graph boundary
				// or just _a if it starts inside the graph
				hit.point = matrix.MultiplyPoint3x4(aInGraphSpace);
				hit.tangentOrigin = hit.point;
				return true;
			}

			// Throw away components we don't care about (y)
			var a = new Vector2(aInGraphSpace.x,aInGraphSpace.z);
			var b = new Vector2(bInGraphSpace.x,bInGraphSpace.z);

			// Subtract 0.5 because nodes have an offset of 0.5 (first node is at (0.5,0.5) not at (0,0))
			// And it's just more convenient to remove that term here
			a -= Vector2.one*0.5f;
			b -= Vector2.one*0.5f;

			// Couldn't find a valid node
			// This shouldn't really happen unless there are NO nodes in the graph
			if (n1 == null || n2 == null) {
				hit.node = null;
				hit.point = _a;
				return true;
			}

			var dir = b-a;

			// Primary direction that we will move in
			// (e.g up and right or down and left)
			var sign = new Int2((int)Mathf.Sign(dir.x), (int)Mathf.Sign(dir.y));

			// How much further we move away from (or towards) the line when walking along #sign
			// This isn't an actual distance. It is a signed distance so it can be negative (other side of the line)
			// Also it includes an additional factor, but the same factor is used everywhere
			// and we only check for if the signed distance is greater or equal to zero so it is ok
			var primaryDirectionError = CrossMagnitude(dir, new Vector2(sign.x,sign.y))*0.5f;

			/*         Z
			 *         |
			 *         |
			 *
			 *         2
			 *         |
			 * --  3 - X - 1  ----- X
			 *         |
			 *         0
			 *
			 *         |
			 *         |
			 */

			// This is the direction which moves further to the right of the segment (when looking from the start)
			int directionToReduceError;
			// This is the direction which moves further to the left of the segment (when looking from the start)
			int directionToIncreaseError;

			if (dir.y >= 0) {
				if (dir.x >= 0) {
					// First quadrant
//.........这里部分代码省略.........
开发者ID:mBeierl,项目名称:GGJ16,代码行数:101,代码来源:GridGenerator.cs

示例14: NearestPointFactor

 public static float NearestPointFactor(Int2 lineStart, Int2 lineEnd, Int2 point)
 {
     Int2 b = lineEnd - lineStart;
     double num = (double)b.sqrMagnitudeLong;
     double num2 = (double)Int2.DotLong(point - lineStart, b);
     if (num != 0.0)
     {
         num2 /= num;
     }
     return (float)num2;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:11,代码来源:AstarMath.cs

示例15: NodeBounds

 private static IntRect NodeBounds(MeshNode[] nodes, int from, int to)
 {
     if (to - from <= 0)
     {
         throw new ArgumentException();
     }
     Int3 vertex = nodes[from].GetVertex(0);
     Int2 @int = new Int2(vertex.x, vertex.z);
     Int2 int2 = @int;
     for (int i = from; i < to; i++)
     {
         MeshNode meshNode = nodes[i];
         for (int j = 1; j < meshNode.GetVertexCount(); j++)
         {
             Int3 vertex2 = meshNode.GetVertex(j);
             @int.x = Math.Min(@int.x, vertex2.x);
             @int.y = Math.Min(@int.y, vertex2.z);
             int2.x = Math.Max(int2.x, vertex2.x);
             int2.y = Math.Max(int2.y, vertex2.z);
         }
     }
     return new IntRect(@int.x, @int.y, int2.x, int2.y);
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:23,代码来源:BBTree.cs


注:本文中的Pathfinding.Int2类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。