ClosestPointOnTriangle() public static method

public static ClosestPointOnTriangle ( Vector3 triangle, Vector3 point ) : Vector3
triangle Vector3
point Vector3
return Vector3
Ejemplo n.º 1
0
        public override Vector3 ClosestPointOnNode(Vector3 p)
        {
            Int3 a, b, c;

            GetVertices(out a, out b, out c);
            return(Polygon.ClosestPointOnTriangle((Vector3)a, (Vector3)b, (Vector3)c, p));
        }
Ejemplo n.º 2
0
        // Token: 0x060025F5 RID: 9717 RVA: 0x001A6794 File Offset: 0x001A4994
        public override Vector3 ClosestPointOnNode(Vector3 p)
        {
            Int3 ob;
            Int3 ob2;
            Int3 ob3;

            this.GetVertices(out ob, out ob2, out ob3);
            return(Polygon.ClosestPointOnTriangle((Vector3)ob, (Vector3)ob2, (Vector3)ob3, p));
        }
Ejemplo n.º 3
0
        public override Vector3 ClosestPointOnNodeXZ(Vector3 p)
        {
            INavmeshHolder navmeshHolder = TriangleMeshNode.GetNavmeshHolder(base.GraphIndex);
            Int3           vertex        = navmeshHolder.GetVertex(this.v0);
            Int3           vertex2       = navmeshHolder.GetVertex(this.v1);
            Int3           vertex3       = navmeshHolder.GetVertex(this.v2);
            Vector2        vector        = Polygon.ClosestPointOnTriangle(new Vector2((float)vertex.x * 0.001f, (float)vertex.z * 0.001f), new Vector2((float)vertex2.x * 0.001f, (float)vertex2.z * 0.001f), new Vector2((float)vertex3.x * 0.001f, (float)vertex3.z * 0.001f), new Vector2(p.x, p.z));

            return(new Vector3(vector.x, p.y, vector.y));
        }
Ejemplo n.º 4
0
        public override Vector3 ClosestPointOnNodeXZ(Vector3 p)
        {
            // Get all 3 vertices for this node
            Int3 tp1, tp2, tp3;

            GetVertices(out tp1, out tp2, out tp3);

            Vector2 closest = Polygon.ClosestPointOnTriangle(
                new Vector2(tp1.x * Int3.PrecisionFactor, tp1.z * Int3.PrecisionFactor),
                new Vector2(tp2.x * Int3.PrecisionFactor, tp2.z * Int3.PrecisionFactor),
                new Vector2(tp3.x * Int3.PrecisionFactor, tp3.z * Int3.PrecisionFactor),
                new Vector2(p.x, p.z)
                );

            return(new Vector3(closest.x, p.y, closest.y));
        }
Ejemplo n.º 5
0
        public override Vector3 ClosestPointOnNodeXZ(Vector3 p)
        {
            // Get the object holding the vertex data for this node
            // This is usually a graph or a recast graph tile
            INavmeshHolder g = GetNavmeshHolder(GraphIndex);

            // Get all 3 vertices for this node
            Int3 tp1 = g.GetVertex(v0);
            Int3 tp2 = g.GetVertex(v1);
            Int3 tp3 = g.GetVertex(v2);

            Vector2 closest = Polygon.ClosestPointOnTriangle(
                new Vector2(tp1.x * Int3.PrecisionFactor, tp1.z * Int3.PrecisionFactor),
                new Vector2(tp2.x * Int3.PrecisionFactor, tp2.z * Int3.PrecisionFactor),
                new Vector2(tp3.x * Int3.PrecisionFactor, tp3.z * Int3.PrecisionFactor),
                new Vector2(p.x, p.z)
                );

            return(new Vector3(closest.x, p.y, closest.y));
        }
Ejemplo n.º 6
0
        public override Vector3d ClosestPointOnNodeXZ(Vector3d p)
        {
            // Get the object holding the vertex data for this node
            // This is usually a graph or a recast graph tile
            INavmeshHolder g = GetNavmeshHolder(GraphIndex);

            // Get all 3 vertices for this node
            Int3 tp1 = g.GetVertex(v0);
            Int3 tp2 = g.GetVertex(v1);
            Int3 tp3 = g.GetVertex(v2);

            Vector2d closest = Polygon.ClosestPointOnTriangle(
                new Vector2d(((long)tp1.x) * FixedMath.One / 1000, ((long)tp1.z) * FixedMath.One / 1000),
                new Vector2d(((long)tp2.x) * FixedMath.One / 1000, ((long)tp2.z) * FixedMath.One / 1000),
                new Vector2d(((long)tp3.x) * FixedMath.One / 1000, ((long)tp3.z) * FixedMath.One / 1000),
                new Vector2d(p.x, p.z)
                );

            return(new Vector3d(closest.x, 0, closest.y));
        }
Ejemplo n.º 7
0
 /** Returns the closest point of the node */
 public static Vector3 ClosestPointOnNode(TriangleMeshNode node, Int3[] vertices, Vector3 pos)
 {
     return(Polygon.ClosestPointOnTriangle((Vector3)vertices[node.v0], (Vector3)vertices[node.v1], (Vector3)vertices[node.v2], pos));
 }
Ejemplo n.º 8
0
 public Vector3 ClosestPoint(Vector3 p, Int3[] vertices)
 {
     return(Polygon.ClosestPointOnTriangle((Vector3)vertices[v1], (Vector3)vertices[v2], (Vector3)vertices[v3], p));
 }
Ejemplo n.º 9
0
        public override Vector3 ClosestPointOnNode(Vector3 p)
        {
            INavmeshHolder navmeshHolder = GetNavmeshHolder(base.DataGroupIndex, base.GraphIndex);

            return(Polygon.ClosestPointOnTriangle((Vector3)navmeshHolder.GetVertex(this.v0), (Vector3)navmeshHolder.GetVertex(this.v1), (Vector3)navmeshHolder.GetVertex(this.v2), p));
        }
Ejemplo n.º 10
0
 public static Vector3 ClosestPointOnTriangle(Vector3[] triangle, Vector3 point)
 {
     return(Polygon.ClosestPointOnTriangle(triangle[0], triangle[1], triangle[2], point));
 }
 /** Returns the closest point of the node */
 public static Vector3 ClosestPointOnNode(MeshNode node, Int3[] vertices, Vector3 pos)
 {
     return(Polygon.ClosestPointOnTriangle((Vector3)vertices[node[0]], (Vector3)vertices[node[1]], (Vector3)vertices[node[2]], pos));
 }
        /** This performs a linear search through all polygons returning the closest one.
         * This will fill the NNInfo with .node for the closest node not necessarily complying with the NNConstraint, and .constrainedNode with the closest node
         * complying with the NNConstraint.
         * \see GetNearestForce(Node[],Int3[],Vector3,NNConstraint,bool)
         */
        public static NNInfo GetNearestForceBoth(Node[] nodes, Int3[] vertices, Vector3 position, NNConstraint constraint, bool accurateNearestNode)
        {
            Int3 pos = (Int3)position;

            float minDist = -1;
            Node  minNode = null;

            float minConstDist = -1;
            Node  minConstNode = null;

            float maxDistSqr = constraint.constrainDistance ? AstarPath.active.maxNearestNodeDistanceSqr : float.PositiveInfinity;

            if (nodes == null || nodes.Length == 0)
            {
                return(new NNInfo());
            }

            for (int i = 0; i < nodes.Length; i++)
            {
                MeshNode node = nodes[i] as MeshNode;

                if (accurateNearestNode)
                {
                    Vector3 closest = Polygon.ClosestPointOnTriangle((Vector3)vertices[node.v1], (Vector3)vertices[node.v2], (Vector3)vertices[node.v3], position);
                    float   dist    = ((Vector3)pos - closest).sqrMagnitude;

                    if (minNode == null || dist < minDist)
                    {
                        minDist = dist;
                        minNode = node;
                    }

                    if (dist < maxDistSqr && constraint.Suitable(node))
                    {
                        if (minConstNode == null || dist < minConstDist)
                        {
                            minConstDist = dist;
                            minConstNode = node;
                        }
                    }
                }
                else
                {
                    if (!Polygon.IsClockwise(vertices[node.v1], vertices[node.v2], pos) || !Polygon.IsClockwise(vertices[node.v2], vertices[node.v3], pos) || !Polygon.IsClockwise(vertices[node.v3], vertices[node.v1], pos))
                    {
                        float dist = (node.position - pos).sqrMagnitude;
                        if (minNode == null || dist < minDist)
                        {
                            minDist = dist;
                            minNode = node;
                        }

                        if (dist < maxDistSqr && constraint.Suitable(node))
                        {
                            if (minConstNode == null || dist < minConstDist)
                            {
                                minConstDist = dist;
                                minConstNode = node;
                            }
                        }
                    }
                    else
                    {
                        int dist = Mathfx.Abs(node.position.y - pos.y);

                        if (minNode == null || dist < minDist)
                        {
                            minDist = dist;
                            minNode = node;
                        }

                        if (dist < maxDistSqr && constraint.Suitable(node))
                        {
                            if (minConstNode == null || dist < minConstDist)
                            {
                                minConstDist = dist;
                                minConstNode = node;
                            }
                        }
                    }
                }
            }

            NNInfo nninfo = new NNInfo(minNode);

            //Find the point closest to the nearest triangle

            if (nninfo.node != null)
            {
                MeshNode node = nninfo.node as MeshNode;                //minNode2 as MeshNode;

                Vector3 clP = Polygon.ClosestPointOnTriangle((Vector3)vertices[node.v1], (Vector3)vertices[node.v2], (Vector3)vertices[node.v3], position);

                nninfo.clampedPosition = clP;
            }

            nninfo.constrainedNode = minConstNode;
            if (nninfo.constrainedNode != null)
            {
                MeshNode node = nninfo.constrainedNode as MeshNode;                //minNode2 as MeshNode;

                Vector3 clP = Polygon.ClosestPointOnTriangle((Vector3)vertices[node.v1], (Vector3)vertices[node.v2], (Vector3)vertices[node.v3], position);

                nninfo.constClampedPosition = clP;
            }

            return(nninfo);
        }
Ejemplo n.º 13
0
        public override Vector3 ClosestPointOnNode(Vector3 p)
        {
            var g = GetNavmeshHolder(GraphIndex);

            return(Polygon.ClosestPointOnTriangle((Vector3)g.GetVertex(v0), (Vector3)g.GetVertex(v1), (Vector3)g.GetVertex(v2), p));
        }