コード例 #1
0
    public static bool ValidateTarget(VInt3 loc, VInt3 target, out VInt3 newTarget, out int nodeIndex)
    {
        newTarget = target;
        nodeIndex = -1;
        if (!AstarPath.active)
        {
            return(false);
        }
        AstarData        astarData           = AstarPath.active.astarData;
        TriangleMeshNode locatedByRasterizer = astarData.GetLocatedByRasterizer(target);

        if (locatedByRasterizer != null)
        {
            return(true);
        }
        int num = -1;
        TriangleMeshNode triangleMeshNode = astarData.IntersectByRasterizer(target, loc, out num);

        if (triangleMeshNode == null)
        {
            return(false);
        }
        VInt3[] staticVerts = PathfindingUtility._staticVerts;
        triangleMeshNode.GetPoints(out staticVerts[0], out staticVerts[1], out staticVerts[2]);
        bool  flag = false;
        VInt3 vInt = Polygon.IntersectionPoint(ref target, ref loc, ref staticVerts[num], ref staticVerts[(num + 1) % 3], out flag);

        if (!flag)
        {
            return(false);
        }
        if (!PathfindingUtility.MakePointInTriangle(ref vInt, triangleMeshNode, -4, 4, -4, 4, VInt3.zero))
        {
            return(false);
        }
        newTarget = vInt;
        return(true);
    }
コード例 #2
0
    public static VInt3 FindValidTarget(ActorRoot actor, VInt3 start, VInt3 end, out bool bResult)
    {
        int actorCamp = (int)actor.TheActorMeta.ActorCamp;
        TriangleMeshNode triangleMeshNode = null;

        bResult = false;
        if (!AstarPath.active)
        {
            return(end);
        }
        AstarData data = AstarPath.active.GetData(actorCamp);

        if (data == null)
        {
            return(end);
        }
        int num;
        int num2;

        data.rasterizer.GetCellPosClamped(out num, out num2, start);
        int num3;
        int num4;

        data.rasterizer.GetCellPosClamped(out num3, out num4, end);
        bool flag  = num < num3;
        bool flag2 = num2 < num4;
        int  num5  = flag ? (num3 - num) : (num - num3);
        int  num6  = flag2 ? (num4 - num2) : (num2 - num4);

        for (int i = 0; i <= num5; i++)
        {
            for (int j = 0; j <= num6; j++)
            {
                int           num7 = num + i * (flag ? 1 : -1);
                int           num8 = num2 + j * (flag2 ? 1 : -1);
                List <object> objs = data.rasterizer.GetObjs(num7, num8);
                if (objs != null)
                {
                    int count = objs.get_Count();
                    if (count != 0)
                    {
                        VInt3 vInt;
                        if (count > 2)
                        {
                            if (data.rasterizer.IntersectionSegment(num7, num8, start, end) && data.CheckSegmentIntersects(start, end, num7, num8, out vInt, out triangleMeshNode))
                            {
                                if (triangleMeshNode != null)
                                {
                                    VInt3 offset = vInt;
                                    bResult = PathfindingUtility.MakePointInTriangle(ref vInt, triangleMeshNode, -4, 4, -4, 4, offset);
                                }
                                return(vInt);
                            }
                        }
                        else if (data.CheckSegmentIntersects(start, end, num7, num8, out vInt, out triangleMeshNode))
                        {
                            if (triangleMeshNode != null)
                            {
                                VInt3 offset2 = vInt;
                                bResult = PathfindingUtility.MakePointInTriangle(ref vInt, triangleMeshNode, -4, 4, -4, 4, offset2);
                            }
                            return(vInt);
                        }
                    }
                }
            }
        }
        return(end);
    }
コード例 #3
0
    private static void MoveAlongEdge(TriangleMeshNode node, int edge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result, bool checkAnotherEdge = true)
    {
        DebugHelper.Assert(edge >= 0 && edge <= 2);
        VInt3 vertex  = node.GetVertex(edge);
        VInt3 vertex2 = node.GetVertex((edge + 1) % 3);
        VInt3 vInt    = destLoc - srcLoc;

        vInt.y = 0;
        VInt3 vInt2 = vertex2 - vertex;

        vInt2.y = 0;
        vInt2.NormalizeTo(1000);
        int num;

        if (state != null)
        {
            num = vInt.magnitude2D * 1000;
            VInt3 vInt3 = state.enabled ? state.firstAdjDir : vInt;
            if (VInt3.Dot(ref vInt2, ref vInt3) < 0)
            {
                num   = -num;
                vInt3 = -vInt2;
            }
            else
            {
                vInt3 = vInt2;
            }
            if (!state.enabled)
            {
                state.enabled     = true;
                state.firstAdjDir = VInt3.Lerp(vInt, vInt3, 1, 3);
                state.firstDir    = state.curDir;
                state.adjDir      = vInt3;
            }
            else if (VInt3.Dot(ref state.adjDir, ref vInt3) >= 0)
            {
                state.adjDir = vInt3;
            }
            else
            {
                num = 0;
            }
            state.applied = true;
        }
        else
        {
            num = vInt2.x * vInt.x + vInt2.z * vInt.z;
        }
        bool  flag;
        VInt3 rhs = Polygon.IntersectionPoint(ref vertex, ref vertex2, ref srcLoc, ref destLoc, out flag);

        if (!flag)
        {
            if (!Polygon.IsColinear(vertex, vertex2, srcLoc) || !Polygon.IsColinear(vertex, vertex2, destLoc))
            {
                result = srcLoc;
                return;
            }
            if (num >= 0)
            {
                int num2 = vInt2.x * (vertex2.x - vertex.x) + vInt2.z * (vertex2.z - vertex.z);
                int num3 = vInt2.x * (destLoc.x - vertex.x) + vInt2.z * (destLoc.z - vertex.z);
                rhs = ((num2 > num3) ? destLoc : vertex2);
                DebugHelper.Assert(num2 >= 0 && num3 >= 0);
            }
            else
            {
                int num4 = -vInt2.x * (vertex.x - vertex2.x) - vInt2.z * (vertex.z - vertex2.z);
                int num5 = -vInt2.x * (destLoc.x - vertex2.x) - vInt2.z * (destLoc.z - vertex2.z);
                rhs = ((Mathf.Abs(num4) > Mathf.Abs(num5)) ? destLoc : vertex);
                DebugHelper.Assert(num4 >= 0 && num5 >= 0);
            }
        }
        int num6 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 1000000L);
        int num7 = IntMath.Sqrt(vertex2.XZSqrMagnitude(rhs) * 1000000L);

        if (num >= num6 && num <= num7)
        {
            result = IntMath.Divide(vInt2, (long)num, 1000000L) + rhs;
            if (!node.ContainsPoint(result))
            {
                Vector3 vector = (Vector3)(vertex2 - vertex);
                vector.y = 0f;
                vector.Normalize();
                VInt3 lhs = vertex2 - vertex;
                lhs.y = 0;
                lhs  *= 10000;
                long    num8    = (long)lhs.magnitude;
                VFactor vFactor = default(VFactor);
                vFactor.nom = (long)num;
                vFactor.den = num8 * 1000L;
                int num9;
                int num10;
                PathfindingUtility.getMinMax(out num9, out num10, (long)lhs.x, ref vFactor);
                int num11;
                int num12;
                PathfindingUtility.getMinMax(out num11, out num12, (long)lhs.z, ref vFactor);
                if (!PathfindingUtility.MakePointInTriangle(ref result, node, num9, num10, num11, num12, srcLoc) && !PathfindingUtility.MakePointInTriangle(ref result, node, num9 - 4, num10 + 4, num11 - 4, num12 + 4, srcLoc))
                {
                    result = srcLoc;
                }
            }
            if (PathfindingUtility.MoveAxisY)
            {
                PathfindingUtility.CalculateY(ref result, node);
            }
        }
        else
        {
            int   rhs2;
            int   edge2;
            VInt3 vInt4;
            if (num < num6)
            {
                rhs2  = num - num6;
                edge2 = (edge + 2) % 3;
                vInt4 = vertex;
            }
            else
            {
                rhs2  = num - num7;
                edge2 = (edge + 1) % 3;
                vInt4 = vertex2;
            }
            VInt3            vInt5 = vInt2 * rhs2 / 1000000f;
            int              startEdge;
            TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge2, out startEdge);
            if (neighborByEdge != null)
            {
                PathfindingUtility.checkedNodes.Add(node);
                PathfindingUtility.MoveFromNode(neighborByEdge, startEdge, vInt4, vInt5 + vInt4, state, out result);
            }
            else
            {
                if (checkAnotherEdge)
                {
                    VInt3 vertex3 = node.GetVertex((edge + 2) % 3);
                    VInt3 lhs2    = (vertex3 - vInt4).NormalizeTo(1000);
                    if (VInt3.Dot(lhs2, vInt5) > 0)
                    {
                        PathfindingUtility.checkedNodes.Add(node);
                        PathfindingUtility.MoveAlongEdge(node, edge2, vInt4, vInt5 + vInt4, state, out result, false);
                        return;
                    }
                }
                result = vInt4;
            }
        }
    }
コード例 #4
0
    private static void MoveAlongEdge(TriangleMeshNode node, int edge, Int3 srcLoc, Int3 destLoc, out Int3 result, bool checkAnotherEdge = true)
    {
        Int3 vertex  = node.GetVertex(edge);
        Int3 vertex2 = node.GetVertex((edge + 1) % 3);
        Int3 vInt    = destLoc - srcLoc;

        vInt.y = 0;
        Int3 vInt2 = vertex2 - vertex;

        vInt2.y = 0;
        vInt2.NormalizeTo(1000);
        int num;

        num = vInt2.x * vInt.x + vInt2.z * vInt.z;

        bool flag;
        Int3 rhs = Polygon.IntersectionPoint(ref vertex, ref vertex2, ref srcLoc, ref destLoc, out flag);

        if (!flag)
        {
            if (!Polygon.IsColinear(vertex, vertex2, srcLoc) || !Polygon.IsColinear(vertex, vertex2, destLoc))
            {
                result = srcLoc;
                return;
            }
            if (num >= 0)
            {
                int num2 = vInt2.x * (vertex2.x - vertex.x) + vInt2.z * (vertex2.z - vertex.z);
                int num3 = vInt2.x * (destLoc.x - vertex.x) + vInt2.z * (destLoc.z - vertex.z);
                rhs = ((num2 <= num3) ? vertex2 : destLoc);
            }
            else
            {
                int num4 = -vInt2.x * (vertex.x - vertex2.x) - vInt2.z * (vertex.z - vertex2.z);
                int num5 = -vInt2.x * (destLoc.x - vertex2.x) - vInt2.z * (destLoc.z - vertex2.z);
                rhs = ((Mathf.Abs(num4) <= Mathf.Abs(num5)) ? vertex : destLoc);
            }
        }
        int num6 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 1000000L);
        int num7 = IntMath.Sqrt(vertex2.XZSqrMagnitude(rhs) * 1000000L);

        if (num >= num6 && num <= num7)
        {
            result = IntMath.Divide(vInt2, (long)num, 1000000L) + rhs;
            if (!node.ContainsPoint(result))
            {
                Vector3 vector = (Vector3)(vertex2 - vertex);
                vector.y = 0f;
                vector.Normalize();
                Int3 lhs = vertex2 - vertex;
                lhs.y = 0;
                lhs  *= 10000;
                long      num8    = (long)lhs.magnitude;
                IntFactor vFactor = default(IntFactor);
                vFactor.numerator   = (long)num;
                vFactor.denominator = num8 * 1000L;
                int num9;
                int num10;
                PathfindingUtility.getMinMax(out num9, out num10, (long)lhs.x, ref vFactor);
                int num11;
                int num12;
                PathfindingUtility.getMinMax(out num11, out num12, (long)lhs.z, ref vFactor);
                if (!PathfindingUtility.MakePointInTriangle(ref result, node, num9, num10, num11, num12, srcLoc) && !PathfindingUtility.MakePointInTriangle(ref result, node, num9 - 4, num10 + 4, num11 - 4, num12 + 4, srcLoc))
                {
                    result = srcLoc;
                }
            }
            if (PathfindingUtility.MoveAxisY)
            {
                PathfindingUtility.CalculateY(ref result, node);
            }
        }
        else
        {
            int  rhs2;
            int  edge2;
            Int3 vInt4;
            if (num < num6)
            {
                rhs2  = num - num6;
                edge2 = (edge + 2) % 3;
                vInt4 = vertex;
            }
            else
            {
                rhs2  = num - num7;
                edge2 = (edge + 1) % 3;
                vInt4 = vertex2;
            }
            Int3             vInt5 = vInt2 * rhs2 / 1000000f;
            int              startEdge;
            TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge2, out startEdge);
            if (neighborByEdge != null)
            {
                PathfindingUtility.checkedNodes.Add(node);
                PathfindingUtility.MoveFromNode(neighborByEdge, startEdge, vInt4, vInt5 + vInt4, out result);
            }
            else
            {
                if (checkAnotherEdge)
                {
                    Int3 vertex3 = node.GetVertex((edge + 2) % 3);
                    Int3 lhs2    = (vertex3 - vInt4).NormalizeTo(1000);
                    if (Int3.Dot(lhs2, vInt5) > 0)
                    {
                        PathfindingUtility.checkedNodes.Add(node);
                        PathfindingUtility.MoveAlongEdge(node, edge2, vInt4, vInt5 + vInt4, out result, false);
                        return;
                    }
                }
                result = vInt4;
            }
        }
    }