Beispiel #1
0
 public void TriggerDataInterrupt()
 {
     if (dataEn.Value)
     {
         if (int3Data.Value)
         {
             Int3.Set(false);
             Int3.Set(true);
             Int3.Set(false);
             this.Log(LogLevel.Noisy, "Data interrupt triggered on pin 3!");
         }
         if (int4Data.Value)
         {
             Int4.Set(false);
             Int4.Set(true);
             Int4.Set(false);
             this.Log(LogLevel.Noisy, "Data interrupt triggered on pin 4!");
         }
     }
 }
Beispiel #2
0
        public override bool LineCastForMoving(ref HitInfo hit, MoveType mov)
        {
            Int3 from = hit.from;
            Int3 to   = hit.to;

            int halfAgentHeightStep = Math.Max(1, navGraphData.buildConfig.agentHeightStep / 2);

            Int3 blockPoint = from;
            int  stepLen    = navGraphData.buildConfig.cellSize / 5;
            bool blocked    = false;

            // y = a*x + b
            Fix64 a_xz = (Fix64)0;
            int   dx   = to.x - from.x;
            int   dz   = to.z - from.z;

            if (Math.Abs(dx) > Math.Abs(dz))
            {
                a_xz = (Fix64)dz / (Fix64)dx;
                int step  = to.x - from.x > 0 ? stepLen : -stepLen;
                int lastY = from.y;
                for (int x = from.x + step; step > 0 ? x <to.x + step : x> to.x - step; x += step)
                {
                    x = step > 0 ? System.Math.Min(x, to.x) : System.Math.Max(x, to.x);
                    Fix64 z = (Fix64)from.z + a_xz * (Fix64)(x - from.x);
                    int   y = lastY;

                    // stairs
                    bool passable = false;
                    for (int iy = halfAgentHeightStep; iy >= -halfAgentHeightStep; iy--)
                    {
                        int  tmpy = y + iy * navGraphData.buildConfig.cellSize;
                        Int3 pt3d = FixVector3ToInt3(new Int3(x, tmpy, (int)z));
                        var  node = GetNodeAt(pt3d.x, pt3d.y, pt3d.z);
                        if (IsNodePassable(pt3d.x, pt3d.y, pt3d.z))
                        {
                            y        = node.worldPosition.y;
                            lastY    = y;
                            passable = true;
                            break;
                        }
                    }
                    if (!passable)
                    {
                        blocked = true;
                        break;
                    }

                    /*if (!IsPassable(new FixVector3(x, (long)y, (long)z)))
                     * {
                     *      blocked = true;
                     *      break;
                     * }*/

                    blockPoint.Set(x, (int)y, (int)z);
                }
            }
            else
            {
                a_xz = (Fix64)dx / (Fix64)dz;
                int step  = to.z - from.z > 0 ? stepLen : -stepLen;
                int lastY = from.y;
                for (int z = from.z + step; step > 0 ? z <to.z + step : z> to.z - step; z += step)
                {
                    z = step > 0 ? System.Math.Min(z, to.z) : System.Math.Max(z, to.z);
                    Fix64 x = (Fix64)from.x + a_xz * (Fix64)(z - from.z);
                    int   y = lastY;

                    // stairs
                    bool passable = false;
                    for (int iy = halfAgentHeightStep; iy >= -halfAgentHeightStep; iy--)
                    {
                        int  tmpy = y + iy * navGraphData.buildConfig.cellSize;
                        Int3 pt3d = FixVector3ToInt3(new Int3((int)x, tmpy, z));
                        var  node = GetNodeAt(pt3d.x, pt3d.y, pt3d.z);
                        if (IsNodePassable(pt3d.x, pt3d.y, pt3d.z))
                        {
                            y        = node.worldPosition.y;
                            lastY    = y;
                            passable = true;
                            break;
                        }
                    }
                    if (!passable)
                    {
                        blocked = true;
                        break;
                    }

                    /*if (!IsPassable(new FixVector3((long)x, (long)y, z)))
                     * {
                     *      blocked = true;
                     *      break;
                     * }*/

                    blockPoint.Set((int)x, (int)y, z);
                }
            }

            if (blockPoint != from || blocked)
            {
                hit.hitPosition = blockPoint;
                return(true);
            }
            else
            {
                hit.hitPosition   = to;
                hit.hitPosition.y = GetGroundHeight3D(hit.hitPosition);
                return(false);
            }
        }
Beispiel #3
0
 public static long DistanceSqr2D(Int3 p1, Int3 p2)
 {
     p1.Set(p1.x, 0, p1.z);
     p2.Set(p2.x, 0, p2.z);
     return(DistanceSqr(p1, p2));
 }
Beispiel #4
0
        // 射线碰撞,计算起点到终点间的最远可到达点
        public override bool LineCastForMoving(ref HitInfo hit, MoveType mov)
        {
            Int3 from = hit.from;
            Int3 to   = hit.to;

            Int3 blockPoint = from;
            int  stepLen    = Math.Min(200, navData.GridSize);
            bool blocked    = false;

            // y = a*x + b
            Fix64 a  = (Fix64)0;
            int   dx = to.x - from.x;
            int   dz = to.z - from.z;

            if (Math.Abs(dx) > Math.Abs(dz))
            {
                a = (Fix64)dz / (Fix64)dx;
                int step = to.x - from.x > 0 ? stepLen : -stepLen;
                for (int x = from.x + step; step > 0 ? x <to.x + step : x> to.x - step; x += step)
                {
                    x = step > 0 ? Math.Min(x, to.x) : Math.Max(x, to.x);
                    Fix64 z      = (Fix64)from.z + a * (Fix64)(x - from.x);
                    var   tmpPos = new Int3(x, 0, (int)z);
                    if (!IsWalkable(tmpPos))
                    {
                        if (!SpecialTerrainPassable(tmpPos, mov))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    blockPoint.Set(x, from.y, (int)z);
                }
            }
            else
            {
                a = (Fix64)dx / (Fix64)dz;
                int step = to.z - from.z > 0 ? stepLen : -stepLen;
                for (int z = from.z + step; step > 0 ? z <to.z + step : z> to.z - step; z += step)
                {
                    z = step > 0 ? Math.Min(z, to.z) : Math.Max(z, to.z);
                    Fix64 x      = (Fix64)from.x + a * (Fix64)(z - from.z);
                    var   tmpPos = new Int3((int)x, 0, z);
                    if (!IsWalkable(tmpPos))
                    {
                        if (!SpecialTerrainPassable(tmpPos, mov))
                        {
                            blocked = true;
                            break;
                        }
                    }

                    blockPoint.Set((int)x, from.y, z);
                }
            }

            if (blockPoint != from)
            {
                hit.hitPosition = blockPoint;
            }
            else
            {
                hit.hitPosition = to;
            }
            return(blocked);
        }