public VFactor GetCosineAngle(VInt3 dest, MoveDirectionState state, out int edgeIndex)
        {
            VInt3 vInt  = this.v1 - this.v0;
            VInt3 vInt2 = this.v2 - this.v0;
            VInt3 vInt3 = dest - this.v0;

            vInt3.NormalizeTo(1000);
            vInt.NormalizeTo(1000);
            vInt2.NormalizeTo(1000);
            long    num    = VInt3.DotXZLong(ref vInt3, ref vInt);
            long    num2   = VInt3.DotXZLong(ref vInt3, ref vInt2);
            VFactor result = default(VFactor);

            result.den = 1000000L;
            if (num > num2)
            {
                edgeIndex  = this.vi;
                result.nom = num;
            }
            else
            {
                edgeIndex  = (this.vi + 2) % 3;
                result.nom = num2;
            }
            return(result);
        }
Example #2
0
        public VFactor GetCosineAngle(VInt3 dest, MoveDirectionState state, out int edgeIndex)
        {
            VInt3 rhs  = this.v1 - this.v0;
            VInt3 num2 = this.v2 - this.v0;
            VInt3 lhs  = dest - this.v0;

            lhs.NormalizeTo(0x3e8);
            rhs.NormalizeTo(0x3e8);
            num2.NormalizeTo(0x3e8);
            long    num4   = VInt3.DotXZLong(ref lhs, ref rhs);
            long    num5   = VInt3.DotXZLong(ref lhs, ref num2);
            VFactor factor = new VFactor {
                den = 0xf4240L
            };

            if (num4 > num5)
            {
                edgeIndex  = this.vi;
                factor.nom = num4;
                return(factor);
            }
            edgeIndex  = (this.vi + 2) % 3;
            factor.nom = num5;
            return(factor);
        }
Example #3
0
 public static VInt3 Move(ActorRoot actor, VInt3 delta, out VInt groundY, MoveDirectionState state = null)
 {
     if (actor.isMovable)
     {
         groundY = (actor == null) ? 0 : actor.groundY;
         return(InternalMove(actor.location, delta, ref groundY, actor, state));
     }
     groundY = actor.groundY;
     return(VInt3.zero);
 }
 public static VInt3 Move(ActorRoot actor, VInt3 delta, out VInt groundY, MoveDirectionState state = null)
 {
     if (actor.isMovable)
     {
         groundY = ((actor != null) ? actor.groundY : 0);
         VInt3 location = actor.location;
         return(PathfindingUtility.InternalMove(location, delta, ref groundY, actor, state));
     }
     groundY = actor.groundY;
     return(VInt3.zero);
 }
Example #5
0
 private static void MoveFromNode(TriangleMeshNode node, int startEdge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result)
 {
     result = srcLoc;
     while (node != null)
     {
         int num;
         int num10;
         int count = 2;
         if (node.IsVertex(srcLoc, out num))
         {
             int vertexIndex             = node.GetVertexIndex(num);
             List <TMNodeInfo> nodeInfos = null;
             GetAllNodesByVert(ref nodeInfos, node, vertexIndex);
             TriangleMeshNode node2 = null;
             int vi = -1;
             for (int i = 0; i < nodeInfos.Count; i++)
             {
                 TMNodeInfo info = nodeInfos[i];
                 if ((!checkedNodes.Contains(info.node) && !Polygon.LeftNotColinear(info.v0, info.v2, destLoc)) && Polygon.Left(info.v0, info.v1, destLoc))
                 {
                     node2 = info.node;
                     vi    = info.vi;
                     break;
                 }
             }
             if (node2 != null)
             {
                 node      = node2;
                 startEdge = (vi + 1) % 3;
                 count     = 1;
             }
             else
             {
                 int     num6   = -1;
                 VFactor factor = new VFactor {
                     nom = -2L,
                     den = 1L
                 };
                 for (int j = 0; j < nodeInfos.Count; j++)
                 {
                     TMNodeInfo info2 = nodeInfos[j];
                     if (!checkedNodes.Contains(info2.node))
                     {
                         int     num8;
                         VFactor factor2 = info2.GetCosineAngle(destLoc, state, out num8);
                         if (factor2 > factor)
                         {
                             factor = factor2;
                             num6   = num8;
                             node2  = info2.node;
                         }
                     }
                 }
                 if (node2 != null)
                 {
                     MoveAlongEdge(node2, num6, srcLoc, destLoc, state, out result, true);
                     break;
                 }
             }
         }
         int edge = -1;
         if (startEdge == -1)
         {
             edge = node.EdgeIntersect(srcLoc, destLoc);
         }
         else
         {
             edge = node.EdgeIntersect(srcLoc, destLoc, startEdge, count);
         }
         if (edge == -1)
         {
             if (node.ContainsPoint(destLoc))
             {
                 result = destLoc;
                 if (MoveAxisY)
                 {
                     CalculateY(ref result, node);
                 }
             }
             else
             {
                 edge = node.GetColinearEdge(srcLoc, destLoc);
                 if (edge != -1)
                 {
                     MoveAlongEdge(node, edge, srcLoc, destLoc, state, out result, true);
                 }
             }
             break;
         }
         TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge, out num10);
         if (neighborByEdge != null)
         {
             node      = neighborByEdge;
             startEdge = num10 + 1;
             count     = 2;
         }
         else
         {
             MoveAlongEdge(node, edge, srcLoc, destLoc, state, out result, true);
             break;
         }
     }
 }
Example #6
0
    private static void MoveAlongEdge(TriangleMeshNode node, int edge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result, bool checkAnotherEdge = true)
    {
        bool flag;

        DebugHelper.Assert((edge >= 0) && (edge <= 2));
        VInt3 vertex = node.GetVertex(edge);
        VInt3 num2   = node.GetVertex((edge + 1) % 3);
        VInt3 a      = destLoc - srcLoc;

        a.y = 0;
        VInt3 lhs = num2 - vertex;

        lhs.y = 0;
        lhs.NormalizeTo(0x3e8);
        int num5 = 0;

        if (state != null)
        {
            num5 = a.magnitude2D * 0x3e8;
            VInt3 num6 = !state.enabled ? a : state.firstAdjDir;
            if (VInt3.Dot(ref lhs, ref num6) < 0)
            {
                num5 = -num5;
                num6 = -lhs;
            }
            else
            {
                num6 = lhs;
            }
            if (!state.enabled)
            {
                state.enabled     = true;
                state.firstAdjDir = VInt3.Lerp(a, num6, 1, 3);
                state.firstDir    = state.curDir;
                state.adjDir      = num6;
            }
            else if (VInt3.Dot(ref state.adjDir, ref num6) >= 0)
            {
                state.adjDir = num6;
            }
            else
            {
                num5 = 0;
            }
            state.applied = true;
        }
        else
        {
            num5 = (lhs.x * a.x) + (lhs.z * a.z);
        }
        VInt3 rhs = Polygon.IntersectionPoint(ref vertex, ref num2, ref srcLoc, ref destLoc, out flag);

        if (!flag)
        {
            if (!Polygon.IsColinear(vertex, num2, srcLoc) || !Polygon.IsColinear(vertex, num2, destLoc))
            {
                result = srcLoc;
                return;
            }
            if (num5 >= 0)
            {
                int num8 = (lhs.x * (num2.x - vertex.x)) + (lhs.z * (num2.z - vertex.z));
                int num9 = (lhs.x * (destLoc.x - vertex.x)) + (lhs.z * (destLoc.z - vertex.z));
                rhs = (num8 <= num9) ? num2 : destLoc;
                DebugHelper.Assert((num8 >= 0) && (num9 >= 0));
            }
            else
            {
                int num10 = (-lhs.x * (vertex.x - num2.x)) - (lhs.z * (vertex.z - num2.z));
                int num11 = (-lhs.x * (destLoc.x - num2.x)) - (lhs.z * (destLoc.z - num2.z));
                rhs = (Mathf.Abs(num10) <= Mathf.Abs(num11)) ? vertex : destLoc;
                DebugHelper.Assert((num10 >= 0) && (num11 >= 0));
            }
        }
        int num12 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 0xf4240L);
        int num13 = IntMath.Sqrt(num2.XZSqrMagnitude(rhs) * 0xf4240L);

        if ((num5 >= num12) && (num5 <= num13))
        {
            result = IntMath.Divide(lhs, (long)num5, 0xf4240L) + rhs;
            if (!node.ContainsPoint(result))
            {
                int     num16;
                int     num17;
                int     num18;
                int     num19;
                Vector3 vector = (Vector3)(num2 - vertex);
                vector.y = 0f;
                vector.Normalize();
                VInt3 num14 = num2 - vertex;
                num14.y = 0;
                num14  *= 0x2710;
                long    magnitude = num14.magnitude;
                VFactor factor    = new VFactor {
                    nom = num5,
                    den = magnitude * 0x3e8L
                };
                getMinMax(out num16, out num18, (long)num14.x, ref factor);
                getMinMax(out num17, out num19, (long)num14.z, ref factor);
                if (!MakePointInTriangle(ref result, node, num16, num18, num17, num19, srcLoc) && !MakePointInTriangle(ref result, node, num16 - 4, num18 + 4, num17 - 4, num19 + 4, srcLoc))
                {
                    result = srcLoc;
                }
            }
            if (MoveAxisY)
            {
                CalculateY(ref result, node);
            }
        }
        else
        {
            int   num20;
            int   num21;
            VInt3 num22;
            int   num24;
            if (num5 < num12)
            {
                num20 = num5 - num12;
                num21 = (edge + 2) % 3;
                num22 = vertex;
            }
            else
            {
                num20 = num5 - num13;
                num21 = (edge + 1) % 3;
                num22 = num2;
            }
            VInt3            num23          = (VInt3)((lhs * num20) / 1000000f);
            TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num21, out num24);
            if (neighborByEdge != null)
            {
                checkedNodes.Add(node);
                MoveFromNode(neighborByEdge, num24, num22, num23 + num22, state, out result);
            }
            else
            {
                if (checkAnotherEdge)
                {
                    VInt3 num27 = node.GetVertex((edge + 2) % 3) - num22;
                    if (VInt3.Dot(num27.NormalizeTo(0x3e8), num23) > 0)
                    {
                        checkedNodes.Add(node);
                        MoveAlongEdge(node, num21, num22, num23 + num22, state, out result, false);
                        return;
                    }
                }
                result = num22;
            }
        }
    }
Example #7
0
    public static VInt3 Move(ActorRoot actor, VInt3 delta, out VInt groundY, out bool collided, MoveDirectionState state = null)
    {
        VInt3 num = Move(actor, delta, out groundY, state);

        collided = (num.x != delta.x) || (num.z != delta.z);
        return(num);
    }
Example #8
0
    private static VInt3 InternalMove(VInt3 srcLoc, VInt3 delta, ref VInt groundY, ActorRoot actor, MoveDirectionState state = null)
    {
        VInt3 num4;

        if (AstarPath.active == null)
        {
            return(VInt3.zero);
        }
        if ((delta.x == 0) && (delta.z == 0))
        {
            return(delta);
        }
        VInt3            end                 = srcLoc + delta;
        int              edge                = -1;
        int              actorCamp           = (int)actor.TheActorMeta.ActorCamp;
        AstarData        data                = AstarPath.active.GetData(actorCamp);
        TriangleMeshNode locatedByRasterizer = data.GetLocatedByRasterizer(srcLoc);

        if (locatedByRasterizer == null)
        {
            TriangleMeshNode node2 = data.IntersectByRasterizer(srcLoc, end, out edge);
            if (node2 == null)
            {
                return(VInt3.zero);
            }
            locatedByRasterizer = node2;
        }
        if (state != null)
        {
            state.BeginMove();
            MoveFromNode(locatedByRasterizer, edge, srcLoc, end, state, out num4);
            state.EndMove();
        }
        else
        {
            MoveFromNode(locatedByRasterizer, edge, srcLoc, end, null, out num4);
        }
        checkedNodes.Clear();
        groundY = num4.y;
        if (!MoveAxisY)
        {
            num4.y = srcLoc.y;
        }
        return(num4 - srcLoc);
    }
 private static void MoveFromNode(TriangleMeshNode node, int startEdge, VInt3 srcLoc, VInt3 destLoc, MoveDirectionState state, out VInt3 result)
 {
     result = srcLoc;
     while (node != null)
     {
         int count = 2;
         int i;
         if (node.IsVertex(srcLoc, out i))
         {
             int vertexIndex = node.GetVertexIndex(i);
             List <PathfindingUtility.TMNodeInfo> list = null;
             PathfindingUtility.GetAllNodesByVert(ref list, node, vertexIndex);
             TriangleMeshNode triangleMeshNode = null;
             int num = -1;
             for (int j = 0; j < list.get_Count(); j++)
             {
                 PathfindingUtility.TMNodeInfo tMNodeInfo = list.get_Item(j);
                 if (!PathfindingUtility.checkedNodes.Contains(tMNodeInfo.node) && !Polygon.LeftNotColinear(tMNodeInfo.v0, tMNodeInfo.v2, destLoc) && Polygon.Left(tMNodeInfo.v0, tMNodeInfo.v1, destLoc))
                 {
                     triangleMeshNode = tMNodeInfo.node;
                     num = tMNodeInfo.vi;
                     break;
                 }
             }
             if (triangleMeshNode != null)
             {
                 node      = triangleMeshNode;
                 startEdge = (num + 1) % 3;
                 count     = 1;
             }
             else
             {
                 int     edge = -1;
                 VFactor b    = new VFactor
                 {
                     nom = -2L,
                     den = 1L
                 };
                 for (int k = 0; k < list.get_Count(); k++)
                 {
                     PathfindingUtility.TMNodeInfo tMNodeInfo2 = list.get_Item(k);
                     if (!PathfindingUtility.checkedNodes.Contains(tMNodeInfo2.node))
                     {
                         int     num2;
                         VFactor cosineAngle = tMNodeInfo2.GetCosineAngle(destLoc, state, out num2);
                         if (cosineAngle > b)
                         {
                             b                = cosineAngle;
                             edge             = num2;
                             triangleMeshNode = tMNodeInfo2.node;
                         }
                     }
                 }
                 if (triangleMeshNode != null)
                 {
                     PathfindingUtility.MoveAlongEdge(triangleMeshNode, edge, srcLoc, destLoc, state, out result, true);
                     break;
                 }
             }
         }
         int num3;
         if (startEdge == -1)
         {
             num3 = node.EdgeIntersect(srcLoc, destLoc);
         }
         else
         {
             num3 = node.EdgeIntersect(srcLoc, destLoc, startEdge, count);
         }
         if (num3 == -1)
         {
             if (node.ContainsPoint(destLoc))
             {
                 result = destLoc;
                 if (PathfindingUtility.MoveAxisY)
                 {
                     PathfindingUtility.CalculateY(ref result, node);
                 }
             }
             else
             {
                 num3 = node.GetColinearEdge(srcLoc, destLoc);
                 if (num3 != -1)
                 {
                     PathfindingUtility.MoveAlongEdge(node, num3, srcLoc, destLoc, state, out result, true);
                 }
             }
             break;
         }
         int num4;
         TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(num3, out num4);
         if (neighborByEdge == null)
         {
             PathfindingUtility.MoveAlongEdge(node, num3, srcLoc, destLoc, state, out result, true);
             break;
         }
         node      = neighborByEdge;
         startEdge = num4 + 1;
     }
 }
    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;
            }
        }
    }
    private static VInt3 InternalMove(VInt3 srcLoc, VInt3 delta, ref VInt groundY, ActorRoot actor, MoveDirectionState state = null)
    {
        if (!AstarPath.active)
        {
            return(VInt3.zero);
        }
        if (delta.x == 0 && delta.z == 0)
        {
            return(delta);
        }
        VInt3            vInt             = srcLoc + delta;
        int              startEdge        = -1;
        int              actorCamp        = (int)actor.TheActorMeta.ActorCamp;
        AstarData        data             = AstarPath.active.GetData(actorCamp);
        TriangleMeshNode triangleMeshNode = data.GetLocatedByRasterizer(srcLoc);

        if (triangleMeshNode == null)
        {
            TriangleMeshNode triangleMeshNode2 = data.IntersectByRasterizer(srcLoc, vInt, out startEdge);
            if (triangleMeshNode2 == null)
            {
                return(VInt3.zero);
            }
            triangleMeshNode = triangleMeshNode2;
        }
        VInt3 lhs;

        if (state != null)
        {
            state.BeginMove();
            PathfindingUtility.MoveFromNode(triangleMeshNode, startEdge, srcLoc, vInt, state, out lhs);
            state.EndMove();
        }
        else
        {
            PathfindingUtility.MoveFromNode(triangleMeshNode, startEdge, srcLoc, vInt, null, out lhs);
        }
        PathfindingUtility.checkedNodes.Clear();
        groundY = lhs.y;
        if (!PathfindingUtility.MoveAxisY)
        {
            lhs.y = srcLoc.y;
        }
        return(lhs - srcLoc);
    }
    public static VInt3 Move(ActorRoot actor, VInt3 delta, out VInt groundY, out bool collided, MoveDirectionState state = null)
    {
        VInt3 result = PathfindingUtility.Move(actor, delta, out groundY, state);

        collided = (result.x != delta.x || result.z != delta.z);
        return(result);
    }
Example #13
0
 public bool Equals(MoveDirectionState other)
 {
     return(this.enabled == other.enabled && this.applied == other.applied && this.adjDir == other.adjDir && this.curAdjDir == other.curAdjDir && this.curDir == other.curDir && this.firstAdjDir == other.firstAdjDir && this.firstDir == other.firstDir);
 }