public void Initialize(NavAgent agent)
 {
     this.mAgent = agent;
     mCrowdDebug = null;
     mCorners    = null;
     mCorridor   = null;
 }
Beispiel #2
0
        public static void Render(ArrayGrid2D <double> grid, CornerData corners, double range, double h, Random random,
                                  out double min, out double max)
        {
            if (grid.Width != grid.Height)
            {
                throw new Exception();
            }

            var ctx = new Context()
            {
                Random  = random,
                Grid    = grid,
                Corners = corners,
                Range   = range,
                H       = h,
                Min     = Math.Min(Math.Min(Math.Min(corners.SW, corners.SE), corners.NE), corners.NW),
                Max     = Math.Max(Math.Max(Math.Max(corners.SW, corners.SE), corners.NE), corners.NW),
            };

            grid[0, 0] = corners.SW;
            grid[grid.Width - 1, 0] = corners.SE;
            grid[grid.Width - 1, grid.Height - 1] = corners.NE;
            grid[0, grid.Height - 1] = corners.NW;

            HeightMap(ctx);

            min = ctx.Min;
            max = ctx.Max;
        }
Beispiel #3
0
    void SortHitPoints()
    {
        for (int i = 0; i < hitPointList.Count; i++)
        {
            CornerData temp = new CornerData();

            temp.pos = hitPointList[i];

            // temp.angle = Vector2.Angle(transform.position, hitPointList[i]);

            Vector2 pos = transform.position;
            temp.angle = pos.AngleTo(hitPointList[i]);

            // temp.angle = transform.position.AngleTo(hitPointList[i]);

            // float angle = (Mathf.Atan2(x, y) / Mathf.PI) * 180f;
            // if(angle < 0)
            // {
            // angle += 360f;
            // }

            cornerDataList.Add(temp);
        }

        hitPointList.Clear();

        // cornerDataList.Sort((a, b) => a.angle.CompareTo(b.angle));
        cornerDataList.Sort((a, b) => b.angle.CompareTo(a.angle));
        // list.Sort((a, b) => a.x.CompareTo(b.x));

        for (int i = 0; i < cornerDataList.Count; i++)
        {
            hitPointList.Add(cornerDataList[i].pos);
        }
    }
Beispiel #4
0
        public static void Render(ArrayGrid2D<double> grid, CornerData corners, double range, double h, int randomSeed,
			out double min, out double max)
        {
            if (grid.Width != grid.Height)
                throw new Exception();

            var ctx = new Context()
            {
                Random = new Random(randomSeed),
                Grid = grid,
                Corners = corners,
                Range = range,
                H = h,
                Min = Math.Min(Math.Min(Math.Min(corners.SW, corners.SE), corners.NE), corners.NW),
                Max = Math.Max(Math.Max(Math.Max(corners.SW, corners.SE), corners.NE), corners.NW),
            };

            grid[0, 0] = corners.SW;
            grid[grid.Width - 1, 0] = corners.SE;
            grid[grid.Width - 1, grid.Height - 1] = corners.NE;
            grid[0, grid.Height - 1] = corners.NW;

            HeightMap(ctx);

            min = ctx.Min;
            max = ctx.Max;
        }
Beispiel #5
0
    void Cast()
    {
        Vector2 pos = transform.position;
        Vector2 dir;
        // float distance = Mathf.Infinity;
        float distance  = 36;
        int   layerMask = LayerMask.GetMask("Player");

        // int layerMask = LayerMask.GetMask("UI");

        hitPointList.Clear();
        hitPointDataList.Clear();

        for (int i = 0; i < corners.Count; i++)
        {
            dir = corners[i] - pos;

            // RaycastHit2D hit = Physics2D.Raycast(pos, dir, distance);
            RaycastHit2D hit = Physics2D.Raycast(pos, dir, distance, ~layerMask);

            CornerData temp = new CornerData();
            temp.pos   = hit.point;
            temp.angle = pos.AngleTo(hit.point);
            hitPointDataList.Add(temp);

            Vector2 debugRayInfo = hit.point - pos;
            Debug.DrawRay(pos, debugRayInfo, Color.green);

            Vector2 offsetDir = dir;
            offsetDir = Quaternion.Euler(0, 0, -0.01f) * offsetDir;

            // RaycastHit2D hitAfter2 = Physics2D.Raycast(pos, offsetDir, distance);
            RaycastHit2D hitAfter2 = Physics2D.Raycast(pos, offsetDir, distance, ~layerMask);

            CornerData temp2 = new CornerData();
            temp2.pos   = hitAfter2.point;
            temp2.angle = pos.AngleTo(hitAfter2.point);
            hitPointDataList.Add(temp2);

            Vector2 debugRayInfo2 = hitAfter2.point - pos;
            Debug.DrawRay(pos, debugRayInfo2, Color.red);

            Vector2 offsetDir2 = dir;
            offsetDir2 = Quaternion.Euler(0, 0, 0.01f) * offsetDir2;

            // RaycastHit2D hitAfter = Physics2D.Raycast(pos, offsetDir2, distance);
            RaycastHit2D hitAfter = Physics2D.Raycast(pos, offsetDir2, distance, ~layerMask);

            CornerData temp3 = new CornerData();
            temp3.pos   = hitAfter.point;
            temp3.angle = pos.AngleTo(hitAfter.point);
            hitPointDataList.Add(temp3);

            Vector2 debugRayInfo3 = hitAfter.point - pos;
            Debug.DrawRay(pos, debugRayInfo3, Color.red);
        }
    }
    void OnRenderObject()
    {
        if (!mDebugEnabled || mAgent == null)
        {
            return;
        }

        if (mAgent.crowdAgent != null)
        {
            if (mCrowdDebug == null)
            {
                mCorners    = null;
                mCorridor   = null;
                mCrowdDebug = new CrowdAgentDebug(mAgent.navGroup.crowd.Navmesh);
            }
            mCrowdDebug.DrawAll(mAgent.crowdAgent);
        }
        else if ((mAgent.data.flags & NavFlag.CorridorInUse) != 0)
        {
            if (mCorridor == null)
            {
                mCorners    = new CornerData();
                mCorridor   = new PathCorridorData(mAgent.corridor.MaxPathSize);
                mCrowdDebug = null;
            }
            int n = mAgent.corridor.FindCorners(mCorners);
            mCorners.cornerCount = n; // v0.3.0 bug workaround.
            mAgent.corridor.GetData(mCorridor);
            NavDebug.Draw(mAgent.navGroup.mesh, mCorridor);
            NavDebug.Draw(mCorners);
        }

        if (mAgent.crowdAgent == null)
        {
            Vector3 pos    = mAgent.data.position.point;
            float   height = mAgent.crowdConfig.height; // Might be zero.

            Vector3 velocity = mAgent.data.desiredVelocity;
            DebugDraw.Arrow(pos + Vector3.up * height
                            , pos + velocity + Vector3.up * height
                            , 0, 0.05f, CrowdAgentDebug.desiredVelocityColor);
        }

        DebugDraw.DiamondMarker(mAgent.data.position.point
                                , 0.1f
                                , NavDebug.positionColor);

        DebugDraw.DiamondMarker(mAgent.data.goal.point
                                , 0.1f
                                , NavDebug.goalColor);
    }
Beispiel #7
0
        /// <summary>
        /// Draws a debug visualization of corner data.
        /// </summary>
        /// <param name="corners">The corners to draw.</param>
        public static void Draw(CornerData corners)
        {
            if (corners.cornerCount == 0)
            {
                return;
            }

            DebugDraw.SimpleMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            GL.Color(cornerColor);

            for (int i = 0; i < corners.cornerCount; i++)
            {
                DebugDraw.AppendXMarker(corners.verts[i], cornerScale);
            }

            GL.End();
        }
Beispiel #8
0
    void SortCorners()
    {
        for (int i = 0; i < corners.Count; i++)
        {
            CornerData temp = new CornerData();

            temp.pos   = corners[i];
            temp.angle = Vector2.Angle(transform.position, corners[i]);

            cornerDataList.Add(temp);
        }

        corners.Clear();

        cornerDataList.Sort((a, b) => a.angle.CompareTo(b.angle));
        // list.Sort((a, b) => a.x.CompareTo(b.x));

        for (int i = 0; i < cornerDataList.Count; i++)
        {
            corners.Add(cornerDataList[i].pos);
        }
    }
Beispiel #9
0
 public static extern void dtcaGetAgentCorners(IntPtr agent
                                               , [In, Out] CornerData resultData);
Beispiel #10
0
    void Cast()
    {
        Vector2 pos = transform.position;
        Vector2 dir;
        // float distance = Mathf.Infinity;
        float distance  = 36;
        int   layerMask = LayerMask.GetMask("Player") | LayerMask.GetMask("Trigger") | LayerMask.GetMask("IgnoreShadow");

        // int layerMask = LayerMask.GetMask("UI");

        hitPointDataList.Clear();

        // for (int i = 0; i < corners.Count; i++)
        for (int i = 0; i < cornerPositions.Length; i++)
        {
            // dir = corners[i] - pos;
            dir = cornerPositions[i] - pos;

            // RaycastHit2D hit = Physics2D.Raycast(pos, dir, distance);
            RaycastHit2D hit = Physics2D.Raycast(pos, dir, distance, ~layerMask);

            // if (Mathf.Abs(Vector2.Distance(cornerPositions[i], pos) - Vector2.Distance(hit.point, pos)) > 1f)
            // {
            // Vector2 debugRayInfoT = hit.point - pos;
            // Debug.DrawRay(pos, debugRayInfoT, Color.green);
            // continue;
            // }

            CornerData temp = new CornerData();
            temp.pos   = hit.point;
            temp.angle = pos.AngleTo(hit.point);
            hitPointDataList.Add(temp);

            Vector2 debugRayInfo = hit.point - pos;
            Debug.DrawRay(pos, debugRayInfo, Color.green);

            Vector2 offsetDir = dir;
            offsetDir = Quaternion.Euler(0, 0, -0.01f) * offsetDir;

            // RaycastHit2D hitAfter2 = Physics2D.Raycast(pos, offsetDir, distance);
            RaycastHit2D hitAfter2 = Physics2D.Raycast(pos, offsetDir, distance, ~layerMask);

            CornerData temp2 = new CornerData();
            temp2.pos   = hitAfter2.point;
            temp2.angle = pos.AngleTo(hitAfter2.point);
            hitPointDataList.Add(temp2);

            Vector2 debugRayInfo2 = hitAfter2.point - pos;
            Debug.DrawRay(pos, debugRayInfo2, Color.red);

            Vector2 offsetDir2 = dir;
            offsetDir2 = Quaternion.Euler(0, 0, 0.01f) * offsetDir2;

            // RaycastHit2D hitAfter = Physics2D.Raycast(pos, offsetDir2, distance);
            RaycastHit2D hitAfter = Physics2D.Raycast(pos, offsetDir2, distance, ~layerMask);

            CornerData temp3 = new CornerData();
            temp3.pos   = hitAfter.point;
            temp3.angle = pos.AngleTo(hitAfter.point);
            hitPointDataList.Add(temp3);

            Vector2 debugRayInfo3 = hitAfter.point - pos;
            Debug.DrawRay(pos, debugRayInfo3, Color.red);
        }
    }
        /// <summary>
        /// Draws a debug visualization of corner data.
        /// </summary>
        /// <param name="corners">The corners to draw.</param>
        public static void Draw(CornerData corners)
        {
            if (corners.cornerCount == 0)
                return;

            DebugDraw.SimpleMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            GL.Color(cornerColor);

            for (int i = 0; i < corners.cornerCount; i++)
            {
                DebugDraw.AppendXMarker(corners.verts[i], cornerScale);
            }

            GL.End();
        }