예제 #1
0
        //        public static void FillPoly(PointF[] points, Color color) {
        //            if (points == null) {
        //                throw new ArgumentNullException("points");
        //            }
        //            
        //            byte[] colors = new byte[points.Length * 4];
        //            for (int i = 0; i < colors.Length; i += 4) {
        //                colors[i] = color.R;
        //                colors[i + 1] = color.G;
        //                colors[i + 2] = color.B;
        //                colors[i + 3] = color.A;
        //            }
        //            
        //            GL.ColorPointer(4, All.UnsignedByte, 0, colors);
        //            GL.EnableClientState(All.ColorArray);
        //            
        //            
        //            if (color.A != 255) {
        //                GL.BlendFunc(All.SrcAlpha, All.OneMinusSrcAlpha);
        //            }
        //            
        //            Vertex2F[] poli = PointsToVerticesForTriangleStrip(points);
        //            
        //            GL.VertexPointer(2, All.Float, 0, poli);
        //            GL.EnableClientState(All.VertexArray);
        //            
        //            GL.DrawArrays(All.TriangleStrip, 0, poli.Length);
        //            
        //            GL.DisableClientState(All.ColorArray);
        //            GL.DisableClientState(All.VertexArray);
        //            
        //            if (color.A != 255) {
        //                GL.BlendFunc(BlendFunc.DefaultBlendSrc, BlendFunc.DefaultBlendDst);
        //            }
        //        }
        public static void DrawCircle(PointF center, float radius, float a, int segments, bool drawLineToCenter)
        {
            int additionalSegment = drawLineToCenter ? 2 : 1;

            float coef = 2f * (float)Math.PI / segments;

            Vertex2F[] vertices = new Vertex2F[segments + 2];

            for (int i = 0; i <= segments; ++i) {
                float rads = i * coef;
                float j = radius * (float)Math.Cos(rads + a) + center.X;
                float k = radius * (float)Math.Sin(rads + a) + center.Y;

                vertices[i].X = j;
                vertices[i].Y = k;
            }
            vertices[segments + 1] = center.ToVertex2F();

            GL.VertexPointer(2, All.Float, 0, vertices);
            GL.EnableClientState(All.VertexArray);

            GL.DrawArrays(All.LineStrip, 0, segments + additionalSegment);

            GL.DisableClientState(All.VertexArray);
        }
예제 #2
0
        public static void DrawCubicBezier(PointF origin, PointF control1, PointF control2, PointF destination, int segments)
        {
            Vertex2F[] vertices = new Vertex2F[segments + 1];

            float t = 0;
            for (int i = 0; i < segments; ++i) {
                float x = (float)Math.Pow(1 - t, 3) * origin.X + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.X + 3.0f * (1 - t) * t * t * control2.X + t * t * t * destination.X;
                float y = (float)Math.Pow(1 - t, 3) * origin.Y + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.Y + 3.0f * (1 - t) * t * t * control2.Y + t * t * t * destination.Y;

                vertices[i].X = x;
                vertices[i].Y = y;
                t += 1f / segments;
            }

            vertices[segments] = destination.ToVertex2F();

            GL.VertexPointer(2, All.Float, 0, vertices);
            GL.EnableClientState(All.VertexArray);
            GL.DrawArrays(All.LineStrip, 0, segments + 1);
            GL.DisableClientState(All.VertexArray);
        }
예제 #3
0
        public static Vertex2F ToVertex2F(this PointF p)
        {
            Vertex2F v = new Vertex2F();
            v.X = p.X;
            v.Y = p.Y;

            return v;
        }
예제 #4
0
        private static Vertex2F[] PointsToVertices(PointF[] points)
        {
            Vertex2F[] vertices = new Vertex2F[points.Length];
            for (int i = 0; i < points.Length; ++i) {
                vertices[i] = points[i].ToVertex2F();
            }

            return vertices;
        }