Ejemplo n.º 1
0
        public void DisplayGrid()
        {
            Vector3 offset = new Vector3(0, 0.01f, 0);

            foreach (WalkCell w in cellGrid.walkCells)
            {
                foreach (WalkPointGroup walkPoint in w.walkGroups)
                {
                    if (walkPoint.points.Length == 0)
                    {
                        continue;
                    }

                    for (int i = 0; i < walkPoint.points.Length - 1; i++)
                    {
                        GL_Utils.DrawLine(walkPoint.points[i] + offset, walkPoint.points[i + 1] + offset, Color.white);
                    }

                    if (walkPoint.walkEdgePoints != null)
                    {
                        for (int i = 0; i < walkPoint.walkEdgePoints.Length - 1; i++)
                        {
                            GL_Utils.DrawLine(walkPoint.walkEdgePoints[i] + offset, walkPoint.walkEdgePoints[i + 1] + offset, Color.red);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
    void OnEnable()
    {
        //Debug.Log("OnEnable!!");
        // must be called before trying to draw lines..
        lineMaterial = GL_Utils.CreateLineMaterial();

        SetUpdateData();
    }
        void OnRenderObject()
        {
            _DisplayCylinders = DisplayCylinders;


            GL.PushMatrix();

            if (lineMaterial == null)
            {
                lineMaterial = GL_Utils.CreateLineMaterial();
            }

            lineMaterial.SetPass(0);

            GL.Begin(GL.LINES);

            DisplayFreeWalkEdgesAndBlockedWalkEdges();
            DisplayGrid();

            GL.End();
            GL.PopMatrix();
        }
Ejemplo n.º 4
0
        private void Erode(ref Poll[,] polls, out bool[,] culledTestPoints, out List <Cylinder> cylinders, float pollSpacing, int gridLength, float playerRadius, float playerStepHeight)
        {
            culledTestPoints = new bool[gridLength, gridLength];
            cylinders        = new List <Cylinder>();
            //errod
            // foreach walkEdgePoints erods poll map
            for (int x = 0; x < gridLength - 1; x++)
            {
                for (int y = 0; y < gridLength - 1; y++)
                {
                    foreach (var wG in walkCells[x, y].walkGroups)
                    {
                        if (wG == null || wG.walkEdgePoints == null || wG.walkPointConfiguration > 0)
                        {
                            continue;
                        }

                        foreach (var wE in wG.walkEdgePoints)
                        {
                            int count  = Mathf.CeilToInt(playerRadius * 2 / pollSpacing);
                            int offset = Mathf.CeilToInt(count / 2f);

                            int i = Mathf.Max(0, x - offset);
                            for (; i < gridLength && i < x + offset + 1; i++)
                            {
                                int j = Mathf.Max(0, y - offset);
                                for (; j < gridLength && j < y + offset + 1; j++)
                                {
                                    Vector2 mapPos  = new Vector2(polls[i, j].postition.x, polls[i, j].postition.z);
                                    Vector2 walkPos = new Vector2(wE.x, wE.z);

                                    if (polls[i, j].yHeights.Count != 0 && (mapPos - walkPos).sqrMagnitude < playerRadius * playerRadius)
                                    {
                                        for (int a = polls[i, j].yHeights.Count - 1; a >= 0; a--)
                                        {
                                            float p = polls[i, j].yHeights[a];

                                            if (p < wE.y + playerStepHeight * 0.1 && p > wE.y - playerStepHeight)
                                            {
                                                culledTestPoints[i, j] = true;
                                                polls[i, j].yHeights.Remove(p);
                                                polls[i, j].yBlockedHeights.Add(p);
                                            }
                                        }
                                    }
                                }
                            }
                            cylinders.Add(new Cylinder(wE, playerStepHeight * 0.8f, playerRadius));
                            if (FreeWalkEdgeTest._DisplayCylinders)
                            {
                                GL_Utils.DrawCircle(wE, playerRadius, Vector3.up, Color.red);
                            }
                        }
                    }
                }
            }

            //We only need distinct cylinders
            cylinders = cylinders.GroupBy(c => c.pos).Select(c => c.First()).ToList();


            //for (int x = 0; x < gridLength; x++)
            //{
            //    for (int y = 0; y < gridLength; y++)
            //    {
            //        if (culledTestPoints[x, y] == true)
            //        {
            //            GL_Utils.DrawCrossVertical(map[x, y].postition, Color.cyan);
            //        }

            //    }
            //}
        }
 void Awake()
 {
     // must be called before trying to draw lines..
     lineMaterial = GL_Utils.CreateLineMaterial();
 }
        public void DisplayGrid()
        {
            Vector3 offset = new Vector3(0, 0.01f, 0);


            if (DisplayVaildPoints || DisplayBlockedPoints)
            {
                foreach (var p in polls)
                {
                    Vector3 point = p.postition;
                    if (DisplayVaildPoints)
                    {
                        foreach (var f in p.yHeights)
                        {
                            point.y = f;
                            GL_Utils.DrawCrossVertical(point, Color.white);
                        }
                    }

                    if (DisplayBlockedPoints)
                    {
                        foreach (var f in p.yBlockedHeights)
                        {
                            point.y = f;
                            GL_Utils.DrawCrossVertical(point, Color.red);
                        }
                    }
                }
            }

            if (DisplayWalkPoints || DisplayFreeWalkPointEdges || DisplayBlockedWalkPointEdges)
            {
                foreach (WalkCell w in cellGrid.walkCells)
                {
                    foreach (WalkPointGroup walkPoint in w.walkGroups)
                    {
                        if (walkPoint.points.Length == 0)
                        {
                            continue;
                        }
                        if (DisplayWalkPoints)
                        {
                            for (int i = 0; i < walkPoint.points.Length - 1; i++)
                            {
                                GL_Utils.DrawLine(walkPoint.points[i] + offset, walkPoint.points[i + 1] + offset, Color.white);
                            }
                        }

                        if (walkPoint.walkEdgePoints != null)
                        {
                            if (DisplayFreeWalkPointEdges && walkPoint.walkPointConfiguration > 0 || DisplayBlockedWalkPointEdges && walkPoint.walkPointConfiguration < 0)
                            {
                                for (int i = 0; i < walkPoint.walkEdgePoints.Length - 1; i++)
                                {
                                    Color walkEdgeColor = (walkPoint.walkPointConfiguration > 0) ? Color.green : Color.red;

                                    GL_Utils.DrawLine(walkPoint.walkEdgePoints[i] + offset, walkPoint.walkEdgePoints[i + 1] + offset, walkEdgeColor);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void TestGLPoints()
        {
            GL.PushMatrix();

            if (lineMaterial == null)
            {
                CreateLineMaterial();
            }

            lineMaterial.SetPass(0);


            // Draw lines
            GL.Begin(GL.LINES);

            Vector3 pos = this.transform.position;

            float count   = Mathf.Sqrt(lineCount);
            float spacing = (1f / (count - 1)) * SqrSize;

            for (int i = 0; i < count; i++)
            {
                for (int b = 0; b < count; b++)
                {
                    Vector3 point = pos + new Vector3(0 - (SqrSize / 2) + i * spacing, 0, 0 - (SqrSize / 2) + b * spacing);


                    RaycastHit[] hits = Physics.RaycastAll(point, Vector3.down);

                    hits = hits.OrderBy(v => v.point.y).Reverse().ToArray();

                    if (hits.Length != 0)
                    {
                        List <Collider> blockerCollider = new List <Collider>();

                        for (int h = 0; h < hits.Length; h++)
                        {
                            Color crossColor = Color.white;

                            RaycastHit hit = hits[h];
                            RaycastHit hit2;

                            foreach (var c in blockerCollider)
                            {
                                if (IsPointInCollider(c, hit.point))
                                {
                                    crossColor = Color.red;
                                }
                            }


                            if (hit.collider.gameObject.layer == 8)
                            {
                                blockerCollider.Add(hit.collider);
                            }

                            if (h != 0 &&
                                hit.point.y + playerHeight > hits[h - 1].point.y ||
                                Physics.Raycast(hit.point, Vector3.up, out hit2, playerHeight))     //TODO (Carl) can significantly reduce the amount of raycasts
                                                                                                    // if we assume hits[0] is the top most point
                                                                                                    // in the world
                            {
                                crossColor = Color.red;
                            }
                            //else //Shows all extra raycasts that are needed
                            //{
                            //    if (Physics.Raycast(hit.point, Vector3.up, out hit2, playerHeight))
                            //    {
                            //        crossColor = Color.red;
                            //        DrawLine(hit.point, hit2.point, Color.red);
                            //    }
                            //    else
                            //    {
                            //        DrawLine(hit.point, hit.point + Vector3.up * 10, Color.blue);
                            //    }
                            //}

                            GL_Utils.DrawCrossNormal(hit.point + Vector3.up * 0.01f, hit.normal, crossColor);
                        }
                        if (drawRay)
                        {
                            GL_Utils.DrawLine(point, hits[hits.Length - 1].point, Color.green);
                        }
                    }
                }
            }

            //RaycastHit[] hits = Physics.RaycastAll(this.transform.position, Vector3.down);

            //if(hits.Length != 0)
            //{
            //    foreach (RaycastHit hit in hits)
            //    {
            //        DrawCrossNormal(hit.point, hit.normal, Color.red);
            //    }

            //    DrawLine(this.transform.position, hits[Mathf.Max(0, hits.Length - 1)].point, Color.green);
            //}


            //DrawLine(new Vector3(0, 0, 0), new Vector3(1, 1, 1), Color.red);
            //DrawLine(new Vector3(1, 0, 0), new Vector3(1, 0.1f, 1), Color.red);

            //DrawCrossVertical(new Vector3(0,0.1f,0), Color.white);
            //DrawCrossNormal(new Vector3(1,0.1f,0.5f), new Vector3(0,0,0), Color.red, 0.1f);

            //DrawPlusMark

            GL.End();
            GL.PopMatrix();
        }
Ejemplo n.º 8
0
        public void GenerateWalkGrid(float squareSize, int sideCount, float playerHeight, float stepHeight, float playerRadius, Vector3 pos)
        {
            if (squareSize <= 0.01 || sideCount < 1)
            {
                return;
            }

            pos.y = maxHeight;


            Poll[,] polls = new Poll[sideCount, sideCount];


            float spacing = (1f / (sideCount - 1)) * squareSize;

            for (int x = 0; x < sideCount; x++)
            {
                for (int y = 0; y < sideCount; y++)
                {
                    Vector3 point = pos + new Vector3(0 - (squareSize / 2) + x * spacing, 0, 0 - (squareSize / 2) + y * spacing);

                    RaycastHit[] hits = Physics.RaycastAll(point, Vector3.down);

                    hits = hits.OrderBy(v => v.point.y).Reverse().ToArray();

                    List <float> validPoints = new List <float>();

                    if (hits.Length != 0)
                    {
                        List <Collider> blockerCollider = new List <Collider>();

                        for (int h = 0; h < hits.Length; h++)
                        {
                            bool valid = true;

                            RaycastHit hit = hits[h];
                            RaycastHit hit2;

                            if (hit.collider.gameObject.layer == 8)
                            {
                                blockerCollider.Add(hit.collider);
                                valid = false;
                            }
                            else
                            {
                                foreach (var c in blockerCollider)
                                {
                                    if (IsPointInCollider(c, hit.point))
                                    {
                                        valid = false;
                                        break;
                                    }
                                }
                            }

                            if (valid && h != 0 &&
                                (hit.point.y + playerHeight > hits[h - 1].point.y || Physics.Raycast(hit.point, Vector3.up, out hit2, playerHeight)))
                            {
                                valid = false;
                            }

                            if (valid)
                            {
                                validPoints.Add(hit.point.y);
                            }

                            if (drawCross)
                            {
                                GL_Utils.DrawCrossNormal(hit.point + Vector3.up * 0.01f, hit.normal, valid ? Color.white : Color.red);
                            }
                        }


                        if (drawRay)
                        {
                            GL_Utils.DrawLine(point, hits[hits.Length - 1].point, Color.green);
                        }
                    }
                    polls[x, y] = new Poll(new Vector3(point.x, 0, point.z), validPoints);
                }
            }

            cellGrid = new CellGrid(polls, spacing, playerHeight, stepHeight, playerRadius);
        }