CgExamples.Gl_06_vertex_twisting.triangleDivide C# (CSharp) Method

triangleDivide() static private method

Apply an inefficient but simple-to-implement subdivision scheme for a triangle.
static private triangleDivide ( int depth, float a, float b, float c, float ca, float cb, float cc ) : void
depth int
a float
b float
c float
ca float
cb float
cc float
return void
        static void triangleDivide(int depth,
                                   float[] a, float[] b, float[] c,
                                   float[] ca, float[] cb, float[] cc)
        {
            if (depth == 0)
            {
                Gl.glColor3fv(ca);
                Gl.glVertex2fv(a);
                Gl.glColor3fv(cb);
                Gl.glVertex2fv(b);
                Gl.glColor3fv(cc);
                Gl.glVertex2fv(c);
            }
            else
            {
                float[] d = { (a[0] + b[0]) / 2, (a[1] + b[1]) / 2 },
                            e = { (b[0] + c[0]) / 2, (b[1] + c[1]) / 2 },
                            f = { (c[0] + a[0]) / 2, (c[1] + a[1]) / 2 };
                float[] cd = { (ca[0] + cb[0]) / 2, (ca[1] + cb[1]) / 2, (ca[2] + cb[2]) / 2 },
                            ce = { (cb[0] + cc[0]) / 2, (cb[1] + cc[1]) / 2, (cb[2] + cc[2]) / 2 },
                            cf = { (cc[0] + ca[0]) / 2, (cc[1] + ca[1]) / 2, (cc[2] + ca[2]) / 2 };

                depth -= 1;
                triangleDivide(depth, a, d, f, ca, cd, cf);
                triangleDivide(depth, d, b, e, cd, cb, ce);
                triangleDivide(depth, f, e, c, cf, ce, cc);
                triangleDivide(depth, d, e, f, cd, ce, cf);
            }
        }