Пример #1
0
        void WorldSpaceDrawLine(UCL.Core.Physic.UCL_Line3D line)
        {
            if (line == null || line.m_Width <= 0 || line.m_Points.Count <= 1)
            {
                return;
            }

            m_Mat.SetPass(0);
            m_Mat.SetColor("_Color", line.m_Col);
            //GL.LoadOrtho();
            GL.LoadIdentity();
            GL.LoadProjectionMatrix(m_ProjectMatrix);

            System.Action <Vector3, Vector3> draw = delegate(Vector3 a, Vector3 b) {
                if (a.z < m_Camera.nearClipPlane || b.z < m_Camera.nearClipPlane)
                {
                    return;
                }
                float z_dis = m_Camera.farClipPlane - m_Camera.nearClipPlane;
                a.z = -(a.z - m_Camera.nearClipPlane) / a.z;
                b.z = -(b.z - m_Camera.nearClipPlane) / b.z;

                GL.Begin(GL.LINES);
                GL.Color(line.m_Col);
                GL.Vertex(a);
                GL.Vertex(b);
                GL.End();
            };
            Vector3 PrevPoint = m_Camera.WorldToScreenPoint(line.m_Points[0]);

            Vector3 Point  = PrevPoint;
            var     StartP = Point;
            int     count  = line.m_Points.Count;

            for (int i = 1; i < count; i++)
            {
                Point = m_Camera.WorldToScreenPoint(line.m_Points[i]);

                draw(PrevPoint, Point);

                PrevPoint = Point;
            }
            if (line.m_Loop)
            {
                draw(PrevPoint, StartP);
            }
        }
Пример #2
0
        void WorldSpace_DrawRect(UCL.Core.Physic.UCL_Line3D line)
        {
            if (line == null || line.m_Width <= 0 || line.m_Points.Count <= 1)
            {
                return;
            }
            bool draw_out_line = line.m_OutLineCol != Color.clear;

            m_Mat.SetPass(0);
            m_Mat.SetColor("_Color", line.m_Col);
            //GL.LoadOrtho();
            GL.LoadIdentity();
            GL.LoadProjectionMatrix(m_ProjectMatrix);

            Vector3 pa       = Vector3.negativeInfinity;
            Vector3 pb       = Vector3.negativeInfinity;
            Vector3 prev_pa  = Vector3.negativeInfinity;
            Vector3 prev_pb  = Vector3.negativeInfinity;
            Vector3 start_pa = Vector3.negativeInfinity;

            System.Func <Vector3, Vector3, bool> draw = delegate(Vector3 a, Vector3 b) {
                if (a.z < 0 || b.z < 0)
                {
                    return(false);
                }
                float z_dis = m_Camera.farClipPlane - m_Camera.nearClipPlane;
                a.z = -(a.z - m_Camera.nearClipPlane) / a.z;
                b.z = -(b.z - m_Camera.nearClipPlane) / b.z;

                var del = b - a;
                var n   = Vector3.Cross(del, new Vector3(0, 0, 1));
                n.Normalize();
                n      *= line.m_Width;
                prev_pa = pa;
                prev_pb = pb;
                pa      = a + n;
                pb      = b + n;
                if (start_pa.Equals(Vector3.negativeInfinity))
                {
                    start_pa = a + n;
                }
                if (!prev_pb.Equals(Vector3.negativeInfinity))
                {
                    GL.Begin(GL.TRIANGLES);
                    GL.Color(line.m_Col);
                    GL.Vertex(prev_pb);

                    GL.Vertex(a);
                    GL.Vertex(pa);
                    GL.End();
                    if (draw_out_line)
                    {
                        GL.Begin(GL.LINES);
                        GL.Color(line.m_OutLineCol);
                        GL.Vertex(prev_pb);
                        GL.Vertex(pa);
                        GL.End();
                    }
                }

                GL.Begin(GL.QUADS);
                GL.Color(line.m_Col);
                GL.Vertex(a);
                GL.Vertex(b);
                GL.Vertex(pb);
                GL.Vertex(pa);
                GL.End();

                if (draw_out_line)
                {
                    GL.Begin(GL.LINES);
                    GL.Color(line.m_OutLineCol);
                    GL.Vertex(a);
                    GL.Vertex(b);
                    GL.End();

                    GL.Begin(GL.LINES);
                    GL.Color(line.m_OutLineCol);
                    GL.Vertex(a + n);
                    GL.Vertex(b + n);
                    GL.End();
                }
                return(true);
            };

            Vector3 PrevPoint = m_Camera.WorldToScreenPoint(line.GetPoint(0));
            Vector3 Point     = PrevPoint;
            var     StartP    = Point;
            int     count     = line.Count;
            bool    draw_flag = false;

            for (int i = 1; i < count; i++)
            {
                Point = m_Camera.WorldToScreenPoint(line.GetPoint(i));

                draw_flag = draw(PrevPoint, Point);

                PrevPoint = Point;
            }

            if (line.m_Loop)
            {
                draw(PrevPoint, StartP);
                if (draw_flag)
                {
                    StartP.z = -(StartP.z - m_Camera.nearClipPlane) / StartP.z;
                    if (StartP.z >= 0 && start_pa.z >= 0 && pb.z >= 0)
                    {
                        GL.Begin(GL.TRIANGLES);
                        GL.Color(line.m_Col);//line.m_Col
                        GL.Vertex(pb);
                        GL.Vertex(StartP);
                        GL.Vertex(start_pa);
                        GL.End();
                        if (draw_out_line)
                        {
                            GL.Begin(GL.LINES);
                            GL.Color(line.m_OutLineCol);
                            GL.Vertex(pb);
                            GL.Vertex(start_pa);
                            GL.End();
                        }
                    }
                }
            }
        }
Пример #3
0
 public void DrawLine(UCL.Core.Physic.UCL_Line3D line)
 {
     m_NextData.m_Lines.Add(line);//.Clone()
 }
Пример #4
0
 // Start is called before the first frame update
 void Start()
 {
     m_Line = new Physic.UCL_Line3D(m_RecordLen);
 }