Ejemplo n.º 1
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);
            return(Polygon.ClosestPointOnTriangleXZ((Vector3)tp1, (Vector3)tp2, (Vector3)tp3, p));
        }
Ejemplo n.º 2
0
        // Token: 0x060025F7 RID: 9719 RVA: 0x001A68C8 File Offset: 0x001A4AC8
        public override Vector3 ClosestPointOnNodeXZ(Vector3 p)
        {
            Int3 ob;
            Int3 ob2;
            Int3 ob3;

            this.GetVertices(out ob, out ob2, out ob3);
            return(Polygon.ClosestPointOnTriangleXZ((Vector3)ob, (Vector3)ob2, (Vector3)ob3, p));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Closest point on the node when seen from above.
        /// This method is mostly for internal use as the <see cref="Pathfinding.NavmeshBase.Linecast"/> methods use it.
        ///
        /// - The returned point is the closest one on the node to p when seen from above (relative to the graph).
        ///   This is important mostly for sloped surfaces.
        /// - The returned point is an Int3 point in graph space.
        /// - It is guaranteed to be inside the node, so if you call <see cref="ContainsPointInGraphSpace"/> with the return value from this method the result is guaranteed to be true.
        ///
        /// This method is slower than e.g <see cref="ClosestPointOnNode"/> or <see cref="ClosestPointOnNodeXZ"/>.
        /// However they do not have the same guarantees as this method has.
        /// </summary>
        internal Int3 ClosestPointOnNodeXZInGraphSpace(Vector3 p)
        {
            // Get the vertices that make up the triangle
            Int3 a, b, c;

            GetVerticesInGraphSpace(out a, out b, out c);

            // Convert p to graph space
            p = GetNavmeshHolder(GraphIndex).transform.InverseTransform(p);

            // Find the closest point on the triangle to p when looking at the triangle from above (relative to the graph)
            var closest = Polygon.ClosestPointOnTriangleXZ((Vector3)a, (Vector3)b, (Vector3)c, p);

            // Make sure the point is actually inside the node
            var i3closest = (Int3)closest;

            if (ContainsPointInGraphSpace(i3closest))
            {
                // Common case
                return(i3closest);
            }
            else
            {
                // Annoying...
                // The closest point when converted from floating point coordinates to integer coordinates
                // is not actually inside the node. It needs to be inside the node for some methods
                // (like for example Linecast) to work properly.

                // Try the 8 integer coordinates around the closest point
                // and check if any one of them are completely inside the node.
                // This will most likely succeed as it should be very close.
                for (var dx = -1; dx <= 1; dx++)
                {
                    for (var dz = -1; dz <= 1; dz++)
                    {
                        if (dx != 0 || dz != 0)
                        {
                            var candidate = new Int3(i3closest.x + dx, i3closest.y, i3closest.z + dz);
                            if (ContainsPointInGraphSpace(candidate))
                            {
                                return(candidate);
                            }
                        }
                    }
                }

                // Happens veery rarely.
                // Pick the closest vertex of the triangle.
                // The vertex is guaranteed to be inside the triangle.
                var da = (a - i3closest).sqrMagnitudeLong;
                var db = (b - i3closest).sqrMagnitudeLong;
                var dc = (c - i3closest).sqrMagnitudeLong;
                return(da < db ? da < dc ? a : c : db < dc ? b : c);
            }
        }
Ejemplo n.º 4
0
        // Token: 0x060025F6 RID: 9718 RVA: 0x001A67C8 File Offset: 0x001A49C8
        internal Int3 ClosestPointOnNodeXZInGraphSpace(Vector3 p)
        {
            Int3 @int;
            Int3 int2;
            Int3 int3;

            this.GetVerticesInGraphSpace(out @int, out int2, out int3);
            p = TriangleMeshNode.GetNavmeshHolder(base.GraphIndex).transform.InverseTransform(p);
            Int3 int4 = (Int3)Polygon.ClosestPointOnTriangleXZ((Vector3)@int, (Vector3)int2, (Vector3)int3, p);

            if (this.ContainsPointInGraphSpace(int4))
            {
                return(int4);
            }
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (i != 0 || j != 0)
                    {
                        Int3 int5 = new Int3(int4.x + i, int4.y, int4.z + j);
                        if (this.ContainsPointInGraphSpace(int5))
                        {
                            return(int5);
                        }
                    }
                }
            }
            long sqrMagnitudeLong  = (@int - int4).sqrMagnitudeLong;
            long sqrMagnitudeLong2 = (int2 - int4).sqrMagnitudeLong;
            long sqrMagnitudeLong3 = (int3 - int4).sqrMagnitudeLong;

            if (sqrMagnitudeLong >= sqrMagnitudeLong2)
            {
                if (sqrMagnitudeLong2 >= sqrMagnitudeLong3)
                {
                    return(int3);
                }
                return(int2);
            }
            else
            {
                if (sqrMagnitudeLong >= sqrMagnitudeLong3)
                {
                    return(int3);
                }
                return(@int);
            }
        }