Pathfinding.TriangleMeshNode.ClosestPointOnNodeXZ C# (CSharp) Method

ClosestPointOnNodeXZ() public method

public ClosestPointOnNodeXZ ( Vector3 _p ) : Vector3
_p UnityEngine.Vector3
return UnityEngine.Vector3
		public override Vector3 ClosestPointOnNodeXZ (Vector3 _p) {
			INavmeshHolder g = GetNavmeshHolder(GraphIndex);
			Int3 tp1 = g.GetVertex(v0);
			Int3 tp2 = g.GetVertex(v1);
			Int3 tp3 = g.GetVertex(v2);
			
			Int3 p = (Int3)_p;
			int oy = p.y;
			
			// Assumes the triangle vertices are laid out in (counter?)clockwise order
			
			tp1.y = 0;
			tp2.y = 0;
			tp3.y = 0;
			p.y = 0;
			
			if ((long)(tp2.x - tp1.x) * (long)(p.z - tp1.z) - (long)(p.x - tp1.x) * (long)(tp2.z - tp1.z) > 0) {
				float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp1, tp2, p));
				return new Vector3(tp1.x + (tp2.x-tp1.x)*f, oy, tp1.z + (tp2.z-tp1.z)*f)*Int3.PrecisionFactor;
			} else if ((long)(tp3.x - tp2.x) * (long)(p.z - tp2.z) - (long)(p.x - tp2.x) * (long)(tp3.z - tp2.z) > 0) {
				float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp2, tp3, p));
				return new Vector3(tp2.x + (tp3.x-tp2.x)*f, oy, tp2.z + (tp3.z-tp2.z)*f)*Int3.PrecisionFactor;
			} else if ((long)(tp1.x - tp3.x) * (long)(p.z - tp3.z) - (long)(p.x - tp3.x) * (long)(tp1.z - tp3.z) > 0) {
				float f = Mathf.Clamp01 (AstarMath.NearestPointFactor (tp3, tp1, p));
				return new Vector3(tp3.x + (tp1.x-tp3.x)*f, oy, tp3.z + (tp1.z-tp3.z)*f)*Int3.PrecisionFactor;
			} else {
				return _p;
			}
			
			/*
			 * Equivalent to the above, but the above uses manual inlining
			if (!Polygon.Left (tp1, tp2, p)) {
				float f = Mathf.Clamp01 (Mathfx.NearestPointFactor (tp1, tp2, p));
				return new Vector3(tp1.x + (tp2.x-tp1.x)*f, oy, tp1.z + (tp2.z-tp1.z)*f)*Int3.PrecisionFactor;
			} else if (!Polygon.Left (tp2, tp3, p)) {
				float f = Mathf.Clamp01 (Mathfx.NearestPointFactor (tp2, tp3, p));
				return new Vector3(tp2.x + (tp3.x-tp2.x)*f, oy, tp2.z + (tp3.z-tp2.z)*f)*Int3.PrecisionFactor;
			} else if (!Polygon.Left (tp3, tp1, p)) {
				float f = Mathf.Clamp01 (Mathfx.NearestPointFactor (tp3, tp1, p));
				return new Vector3(tp3.x + (tp1.x-tp3.x)*f, oy, tp3.z + (tp1.z-tp3.z)*f)*Int3.PrecisionFactor;
			} else {
				return _p;
			}*/

			/* Almost equivalent to the above, but this is slower
			Vector3 tp1 = (Vector3)g.GetVertex(v0);
			Vector3 tp2 = (Vector3)g.GetVertex(v1);
			Vector3 tp3 = (Vector3)g.GetVertex(v2);
			tp1.y = 0;
			tp2.y = 0;
			tp3.y = 0;
			_p.y = 0;
			return Pathfinding.Polygon.ClosestPointOnTriangle (tp1,tp2,tp3,_p);*/
		}
		

Usage Example

Ejemplo n.º 1
0
 // Token: 0x060025F4 RID: 9716 RVA: 0x001A3488 File Offset: 0x001A1688
 private void SearchBoxClosestXZ(int boxi, Vector3 p, ref float closestSqrDist, NNConstraint constraint, ref NNInfoInternal nnInfo)
 {
     BBTree.BBTreeBox bbtreeBox = this.tree[boxi];
     if (bbtreeBox.IsLeaf)
     {
         TriangleMeshNode[] array = this.nodeLookup;
         for (int i = 0; i < 4; i++)
         {
             if (array[bbtreeBox.nodeOffset + i] == null)
             {
                 return;
             }
             TriangleMeshNode triangleMeshNode = array[bbtreeBox.nodeOffset + i];
             if (constraint == null || constraint.Suitable(triangleMeshNode))
             {
                 Vector3 vector = triangleMeshNode.ClosestPointOnNodeXZ(p);
                 float   num    = (vector.x - p.x) * (vector.x - p.x) + (vector.z - p.z) * (vector.z - p.z);
                 if (nnInfo.constrainedNode == null || num < closestSqrDist - 1E-06f || (num <= closestSqrDist + 1E-06f && Mathf.Abs(vector.y - p.y) < Mathf.Abs(nnInfo.constClampedPosition.y - p.y)))
                 {
                     nnInfo.constrainedNode      = triangleMeshNode;
                     nnInfo.constClampedPosition = vector;
                     closestSqrDist = num;
                 }
             }
         }
     }
     else
     {
         int   left  = bbtreeBox.left;
         int   right = bbtreeBox.right;
         float num2;
         float num3;
         this.GetOrderedChildren(ref left, ref right, out num2, out num3, p);
         if (num2 <= closestSqrDist)
         {
             this.SearchBoxClosestXZ(left, p, ref closestSqrDist, constraint, ref nnInfo);
         }
         if (num3 <= closestSqrDist)
         {
             this.SearchBoxClosestXZ(right, p, ref closestSqrDist, constraint, ref nnInfo);
         }
     }
 }
All Usage Examples Of Pathfinding.TriangleMeshNode::ClosestPointOnNodeXZ