Пример #1
0
        public void DrawLine(IVector <T> Start, IVector <T> End, bool DoAA)
        {
            if (Start == End)
            {
                return;
            }
            Gl.glPushAttrib(Gl.GL_ALL_ATTRIB_BITS);

            CheckLineImageCache();

            ImageGLDisplayListPlugin <T> GLBuffer = ImageGLDisplayListPlugin <T> .GetImageGLDisplayListPlugin(m_LineImageCache);

            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            Gl.glColor4f(0, 0, 0, 1);

            IVector <T> Normal = (End.Subtract(Start));

            Normal = Normal.Normalize();

            IVector <T> PerpendicularNormal = Normal.GetPerpendicular();
            float       Width = 40;

            if (DoAA)
            {
                Width--;
            }
            IVector <T> OffsetPos = PerpendicularNormal.Multiply(Width);
            IVector <T> OffsetNeg = PerpendicularNormal.Multiply(-(Width + 1));

            RendererOpenGL <T> .PushOrthoProjection();

            Gl.glDisable(Gl.GL_TEXTURE_2D);

            IVector <T> StartLeft  = Start.Add(OffsetPos);
            IVector <T> StartRight = Start.Add(OffsetNeg);
            IVector <T> EndLeft    = End.Add(OffsetPos);
            IVector <T> EndRight   = End.Add(OffsetNeg);

            Gl.glBegin(Gl.GL_QUADS);
            {
                Gl.glVertex2d(StartLeft[0].ToDouble(), StartLeft[1].ToDouble());
                Gl.glVertex2d(EndLeft[0].ToDouble(), EndLeft[1].ToDouble());
                Gl.glVertex2d(EndRight[0].ToDouble(), EndRight[1].ToDouble());
                Gl.glVertex2d(StartRight[0].ToDouble(), StartRight[1].ToDouble());
            }
            Gl.glEnd();

            if (DoAA)
            {
                double EdgeWith = 2;
                //IVector<DoubleComponent> StartLeftAA = StartLeft + PerpendicularNormal * EdgeWith - Normal * EdgeWith;
                //IVector<DoubleComponent> StartRightAA = StartRight - PerpendicularNormal * EdgeWith - Normal * EdgeWith;
                //IVector<DoubleComponent> EndLeftAA = EndLeft + PerpendicularNormal * EdgeWith + Normal * EdgeWith;
                //IVector<DoubleComponent> EndRightAA = EndRight - PerpendicularNormal * EdgeWith + Normal * EdgeWith;

                IVector <T> StartLeftAA =
                    StartLeft
                    .Add(PerpendicularNormal)
                    .Multiply(EdgeWith)
                    .Subtract(Normal)
                    .Multiply(EdgeWith);


                IVector <T> StartRightAA =
                    StartRight
                    .Subtract(PerpendicularNormal)
                    .Multiply(EdgeWith)
                    .Subtract(Normal)
                    .Multiply(EdgeWith);


                IVector <T> EndLeftAA =
                    EndLeft
                    .Add(PerpendicularNormal)
                    .Multiply(EdgeWith)
                    .Add(Normal)
                    .Multiply(EdgeWith);


                IVector <T> EndRightAA =
                    EndRight
                    .Subtract(PerpendicularNormal)
                    .Multiply(EdgeWith)
                    .Add(Normal)
                    .Multiply(EdgeWith);



                Gl.glEnable(Gl.GL_TEXTURE_2D);
                Gl.glBindTexture(Gl.GL_TEXTURE_2D, GLBuffer.GLTextureHandle);

                Gl.glBegin(Gl.GL_QUADS);
                {
                    // left edge
                    Gl.glTexCoord2d(0, 0);
                    Gl.glVertex2d(StartLeft[0].ToDouble(), StartLeft[1].ToDouble());
                    Gl.glVertex2d(EndLeft[0].ToDouble(), EndLeft[1].ToDouble());
                    Gl.glTexCoord2d(1, 0);
                    Gl.glVertex2d(EndLeftAA[0].ToDouble(), EndLeftAA[1].ToDouble());
                    Gl.glVertex2d(StartLeftAA[0].ToDouble(), StartLeftAA[1].ToDouble());

                    // right edge
                    Gl.glTexCoord2d(0, 0);
                    Gl.glVertex2d(StartRight[0].ToDouble(), StartRight[1].ToDouble());
                    Gl.glVertex2d(EndRight[0].ToDouble(), EndRight[1].ToDouble());
                    Gl.glTexCoord2d(1, 0);
                    Gl.glVertex2d(EndRightAA[0].ToDouble(), EndRightAA[1].ToDouble());
                    Gl.glVertex2d(StartRightAA[0].ToDouble(), StartRightAA[1].ToDouble());

                    // start edge
                    EdgeWith = 20;
                    Gl.glTexCoord2d(0, 0);
                    Gl.glVertex2d(StartLeft[0].ToDouble(), StartLeft[1].ToDouble());
                    Gl.glVertex2d(StartRight[0].ToDouble(), StartRight[1].ToDouble());
                    Gl.glTexCoord2d(1, 0);
                    Gl.glVertex2d(StartRightAA[0].ToDouble(), StartRightAA[1].ToDouble());
                    Gl.glVertex2d(StartLeftAA[0].ToDouble(), StartLeftAA[1].ToDouble());

                    // end edge
                    Gl.glTexCoord2d(0, 0);
                    Gl.glVertex2d(EndLeft[0].ToDouble(), EndLeft[1].ToDouble());
                    Gl.glVertex2d(EndRight[0].ToDouble(), EndRight[1].ToDouble());
                    Gl.glTexCoord2d(1, 0);
                    Gl.glVertex2d(EndRightAA[0].ToDouble(), EndRightAA[1].ToDouble());
                    Gl.glVertex2d(EndLeftAA[0].ToDouble(), EndLeftAA[1].ToDouble());
                }
                Gl.glEnd();
            }

            RendererOpenGL <T> .PopOrthoProjection();

            Gl.glPopAttrib();
        }