예제 #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);
                        }
                    }
                }
            }
        }
        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);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #3
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();
        }
예제 #4
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);
        }