private int drawRose(SceneBrep scene, Matrix4 m, string param)
        {
            int    number_of_points = segments;
            double period           = Math.PI * d;

            if ((n % 2 == 0) || (d % 2 == 0))
            {
                period *= 2;
            }

            double s  = 0.0;
            double ds = 1.0 / number_of_points;

            double     dtheta = period / number_of_points;
            List <int> points = new List <int>();
            double     k      = (double)n / d;

            for (int i = 0; i < number_of_points; i++)
            {
                double theta = i * dtheta;
                double r     = scale * Math.Cos(k * theta);
                float  x     = (float)(r * Math.Cos(theta * ratioX));
                float  y     = (float)(r * Math.Sin(theta * ratioY));
                float  z     = (float)(r * Math.Cos(theta * i * ratioZ));
                if (noRatioZ)
                {
                    z = (float)(r * Math.Cos(theta));
                }
                if (noRatioX)
                {
                    x = (float)(r * Math.Cos(theta));
                }
                if (noRatioY)
                {
                    y = (float)(r * Math.Sin(theta));
                }


                Vector3 A = new Vector3(x, y, z);
                int     v = scene.AddVertex(Vector3.TransformPosition(A, m));
                points.Add(v);
                scene.SetTxtCoord(v, new Vector2((float)s, (float)s));
                System.Drawing.Color c = Raster.Draw.ColorRamp(0.5 * (s + 1.0));
                scene.SetColor(v, new Vector3(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f));
                s += ds;
            }

            for (int i = 0; i < number_of_points - 1; i++)
            {
                scene.AddLine(points[i], points[i + 1]);
            }
            scene.AddLine(points[0], points[points.Count - 1]);
            return(number_of_points);
        }
Beispiel #2
0
 internal void RenderSceneJustCurve(SceneBrep scene)
 {
     for (int i = 0; i < Vertices.Count; i++)
     {
         scene.AddVertex(Vertices[i]);
         if (i > 0)
         {
             scene.AddLine(i - 1, i);
         }
     }
     scene.AddLine(0, Vertices.Count - 1);
 }
Beispiel #3
0
 void AddToScene(SceneBrep scene, List <Vector3> v, int total)
 {
     for (int i = total; i > total - v.Count + 1; i--)
     {
         scene.AddLine(i, i - 1);
     }
 }
        private int drawKoch(SceneBrep scene, Matrix4 m, string param)
        {
            Vector3 A, B, C, D;
            int     one, two, three, four;

            //float a = 1.0f;
            A.X   = 0;
            A.Y   = 0;
            A.Z   = 0;
            one   = scene.AddVertex(Vector3.TransformPosition(A, m));
            B.X   = 1.0f;
            B.Y   = 1.0f;
            B.Z   = 0;
            two   = scene.AddVertex(Vector3.TransformPosition(B, m));
            C.X   = 0;
            C.Y   = 1.0f;
            C.Z   = 1.0f;
            three = scene.AddVertex(Vector3.TransformPosition(C, m));
            D.X   = 1.0f;
            D.Y   = 0;
            D.Z   = 1.0f;
            four  = scene.AddVertex(Vector3.TransformPosition(D, m));

            scene.AddLine(one, two);
            scene.AddLine(two, three);
            scene.AddLine(three, one);
            scene.AddLine(four, one);
            scene.AddLine(four, two);
            scene.AddLine(four, three);

            drawKochRecursive(depthParam, scene, m, param, A, B, C, D);

            return(segments + (int)Math.Pow(4, depthParam) + 1);
        }
        private int drawLineBezier(SceneBrep scene, Matrix4 m, string param, Vector3 P0, Vector3 P1, Vector3 P2)
        {
            int segm = 200;

            float hun = 100.0f;


            List <int> pointsList = new List <int>();

            addCube(scene, m, param);


            //P0 -= delta; P1 -= delta;P2 -= delta;

            for (int i = 0; i <= 100; i++)
            {
                float   t = ((float)(i)) / hun;
                Vector3 P = (1 - t) * ((1 - t) * P0 + t * P1) + t * ((1 - t) * P1 + t * P2);
                //float x = (1-t)*(1-t)*x1 + 2*(1-t)*t*x2+t*t*x3;
                //float y = (1-t)*(1-t)*y1 + 2*(1-t)*t*y2+t*t*y3;
                pointsList.Add(scene.AddVertex(Vector3.TransformPosition(P, m)));
            }

            for (int i = 0; i < pointsList.Count - 1; i++)
            {
                scene.AddLine(pointsList[i], pointsList[i + 1]);
            }

            int p0, p1, p2;

            p0 = scene.AddVertex(Vector3.TransformPosition(P0, m));
            p1 = scene.AddVertex(Vector3.TransformPosition(P1, m));
            p2 = scene.AddVertex(Vector3.TransformPosition(P2, m));

            scene.AddLine(p0, p1);
            scene.AddLine(p1, p2);

            return(segm + 2);
        }
Beispiel #6
0
        /// <summary>
        /// Construct a new Brep solid (preferebaly closed = regular one).
        /// </summary>
        /// <param name="scene">B-rep scene to be modified</param>
        /// <param name="m">Transform matrix (object-space to world-space)</param>
        /// <param name="param">Shape parameters if needed</param>
        /// <returns>Number of generated faces (0 in case of failure)</returns>
        public int AddMesh(SceneBrep scene, Matrix4 m, string param)
        {
            // {{ TODO: put your Mesh-construction code here

            parseParams(param);

            // If there will be large number of new vertices, reserve space for them to save time.
            scene.Reserve(segments + 1);

            double t  = 0.0;
            double dt = maxT / segments;
            double s  = 0.0; // for both texture coordinate & color ramp
            double ds = 1.0 / segments;

            int     vPrev = 0;
            Vector3 A;

            for (int i = 0; i <= segments; i++)
            {
                // New vertex's coordinates.
                A.X = (float)(radius * Math.Cos(kx * t + dx));
                A.Y = (float)(radius * Math.Cos(ky * t + dy));
                A.Z = (float)(radius * Math.Cos(kz * t + dz));

                // New vertex.
                int v = scene.AddVertex(Vector3.TransformPosition(A, m));

                // Vertex attributes.
                scene.SetTxtCoord(v, new Vector2((float)s, (float)s));
                System.Drawing.Color c = Raster.Draw.ColorRamp(0.5 * (s + 1.0));
                scene.SetColor(v, new Vector3(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f));

                // New line?
                if (i > 0)
                {
                    scene.AddLine(vPrev, v);
                }

                // Next vertex.
                t    += dt;
                s    += ds;
                vPrev = v;
            }

            // Thick line (for rendering).
            scene.LineWidth = 3.0f;

            return(segments);

            // }}
        }
        private int drawSpiral(SceneBrep scene, Matrix4 m, string param)
        {
            int number_of_points = segments;

            double     period = Math.PI * scale;
            double     dtheta = period / number_of_points;
            List <int> points = new List <int>();
            double     ds     = 1.0 / (double)number_of_points;
            double     s      = 0.0;

            for (int i = 0; i < number_of_points; i++)
            {
                double theta = i * dtheta;
                float  x     = (float)(s * s * Math.Cos(theta * ratioX));
                float  y     = (float)(s * s * Math.Sin(theta * ratioY));
                float  z     = (float)(s * s);



                Vector3 A = new Vector3(x, y, z);
                int     v = scene.AddVertex(Vector3.TransformPosition(A, m));

                scene.SetTxtCoord(v, new Vector2((float)s, (float)s));
                System.Drawing.Color c = Raster.Draw.ColorRamp(0.5 * (s + 1.0));
                scene.SetColor(v, new Vector3(c.R / 255.0f, c.G / 255.0f, c.B / 255.0f));

                points.Add(v);
                s += ds;
            }

            for (int i = 0; i < number_of_points - 1; i++)
            {
                scene.AddLine(points[i], points[i + 1]);
            }
            //scene.AddLine(points[0], points[points.Count - 1]);
            return(number_of_points);
        }
        private int drawTetrahedron(SceneBrep scene, Matrix4 m, string param)
        {
            segments = 4;
            scene.Reserve(segments + (int)Math.Pow(4, depthParam) + 1);

            /*c.Line(0, 0, 0, c.Height);
             * c.Line(0, c.Height, c.Width, c.Height / 2);
             * c.Line(c.Width, c.Height / 2, 0, 0);
             */
            Vector3 A, B, C, D;
            int     one, two, three, four;

            //float a = 1.0f;
            A.X   = 0;
            A.Y   = 0;
            A.Z   = 0;
            one   = scene.AddVertex(Vector3.TransformPosition(A, m));
            B.X   = 1.0f;
            B.Y   = 1.0f;
            B.Z   = 0;
            two   = scene.AddVertex(Vector3.TransformPosition(B, m));
            C.X   = 0;
            C.Y   = 1.0f;
            C.Z   = 1.0f;
            three = scene.AddVertex(Vector3.TransformPosition(C, m));
            D.X   = 1.0f;
            D.Y   = 0;
            D.Z   = 1.0f;
            four  = scene.AddVertex(Vector3.TransformPosition(D, m));

            scene.AddLine(one, two);
            scene.AddLine(two, three);
            scene.AddLine(three, one);
            scene.AddLine(four, one);
            scene.AddLine(four, two);
            scene.AddLine(four, three);

            drawTetrahedronRecursive(depthParam, scene, m, param, A, B, C, D);

            return(segments + (int)Math.Pow(4, depthParam) + 1);
        }
        private void drawKochRecursive(int depth, SceneBrep scene, Matrix4 m, string param, Vector3 a, Vector3 b, Vector3 c, Vector3 d)
        {
            if (depth == 0)
            {
                return;
            }

            Vector3 stand;

            stand.X = 0;
            stand.Y = 0;
            stand.Z = 0;
            int     ab, ac, ad, bc, bd, cd, headabc, headadb, headacd, headbdc;
            Vector3 AB = stand, AC = stand, AD = stand;
            Vector3 BC = stand, BD = stand;
            Vector3 CD = stand;

            calculateMiddle(a, b, c, d, ref AB, ref AC, ref AD, ref BC, ref BD, ref CD);
            float lengthOfSide = (float)Math.Sqrt((AB.X - BC.X) * (AB.X - BC.X) + (AB.Y - BC.Y) * (AB.Y - BC.Y) + (AB.Z - BC.Z) * (AB.Z - BC.Z));
            float height       = lengthOfSide * (float)Math.Sqrt(6) / 3.0f;

            Vector3 headABC = calculateHeightVertex(a, b, c, height);
            Vector3 headADB = calculateHeightVertex(a, d, b, height);
            Vector3 headACD = calculateHeightVertex(a, c, d, height);
            Vector3 headBDC = calculateHeightVertex(b, d, c, height);


            ab      = scene.AddVertex(Vector3.TransformPosition(AB, m));
            ac      = scene.AddVertex(Vector3.TransformPosition(AC, m));
            ad      = scene.AddVertex(Vector3.TransformPosition(AD, m));
            bc      = scene.AddVertex(Vector3.TransformPosition(BC, m));
            bd      = scene.AddVertex(Vector3.TransformPosition(BD, m));
            cd      = scene.AddVertex(Vector3.TransformPosition(CD, m));
            headabc = scene.AddVertex(Vector3.TransformPosition(headABC, m));
            headadb = scene.AddVertex(Vector3.TransformPosition(headADB, m));
            headacd = scene.AddVertex(Vector3.TransformPosition(headACD, m));
            headbdc = scene.AddVertex(Vector3.TransformPosition(headBDC, m));


            scene.AddLine(ab, ac);
            scene.AddLine(ac, bc);
            scene.AddLine(bc, ab);
            scene.AddLine(ab, headabc);
            scene.AddLine(ac, headabc);
            scene.AddLine(bc, headabc);


            scene.AddLine(ab, bd);
            scene.AddLine(bd, ad);
            scene.AddLine(ad, ab);
            scene.AddLine(ab, headadb);
            scene.AddLine(bd, headadb);
            scene.AddLine(ad, headadb);


            scene.AddLine(ac, ad);
            scene.AddLine(ad, cd);
            scene.AddLine(cd, ac);
            scene.AddLine(ac, headacd);
            scene.AddLine(ad, headacd);
            scene.AddLine(cd, headacd);


            scene.AddLine(bc, cd);
            scene.AddLine(cd, bd);
            scene.AddLine(bd, bc);
            scene.AddLine(bc, headbdc);
            scene.AddLine(bd, headbdc);
            scene.AddLine(cd, headbdc);

            drawKochRecursive(depth - 1, scene, m, param, AB, AC, BC, headABC);
            drawKochRecursive(depth - 1, scene, m, param, AB, BD, AD, headADB);
            drawKochRecursive(depth - 1, scene, m, param, AD, CD, AC, headACD);
            drawKochRecursive(depth - 1, scene, m, param, BD, BC, CD, headBDC);
        }
        private int drawOctahedron(SceneBrep scene, Matrix4 m, string param, float sc, Vector3 color, double s, double theta)
        {
            int     one, two, three, four, five, six;
            float   localScale = (float)sc;
            Vector4 row1       = new Vector4((float)Math.Cos(theta), (float)-Math.Sin(theta), 0, 0);
            Vector4 row2       = new Vector4((float)Math.Sin(theta), (float)Math.Cos(theta), 0, 0);
            Vector4 row3       = new Vector4(0, 0, 1, 0);
            Vector4 row4       = new Vector4(0, 0, 0, 1);

            m = new Matrix4(row1, row2, row3, row4);

            Vector3 A = new Vector3(localScale, 0, 0);

            one   = scene.AddVertex(Vector3.TransformPosition(A, m));
            A     = new Vector3(0, localScale, 0);
            two   = scene.AddVertex(Vector3.TransformPosition(A, m));
            A     = new Vector3(-localScale, 0, 0);
            three = scene.AddVertex(Vector3.TransformPosition(A, m));
            A     = new Vector3(0, -localScale, 0);
            four  = scene.AddVertex(Vector3.TransformPosition(A, m));
            A     = new Vector3(0, 0, localScale);
            five  = scene.AddVertex(Vector3.TransformPosition(A, m));
            A     = new Vector3(0, 0, -localScale);
            six   = scene.AddVertex(Vector3.TransformPosition(A, m));

            scene.SetTxtCoord(one, new Vector2((float)s, (float)s));
            scene.SetTxtCoord(two, new Vector2((float)s, (float)s));
            scene.SetTxtCoord(three, new Vector2((float)s, (float)s));
            scene.SetTxtCoord(four, new Vector2((float)s, (float)s));
            scene.SetTxtCoord(five, new Vector2((float)s, (float)s));
            scene.SetTxtCoord(six, new Vector2((float)s, (float)s));

            scene.SetColor(one, color);
            scene.SetColor(two, color);
            scene.SetColor(three, color);
            scene.SetColor(four, color);
            scene.SetColor(five, color);
            scene.SetColor(six, color);


            scene.AddLine(one, two);
            scene.AddLine(two, three);
            scene.AddLine(three, four);
            scene.AddLine(four, one);

            scene.AddLine(five, one);
            scene.AddLine(five, two);
            scene.AddLine(five, three);
            scene.AddLine(five, four);

            scene.AddLine(six, one);
            scene.AddLine(six, two);
            scene.AddLine(six, three);
            scene.AddLine(six, four);


            return(6);
        }
        private int dragonCurve(SceneBrep scene, Matrix4 m, string param)
        {
            int        retValue     = 1;
            List <int> turnSequence = new List <int>();

            for (int i = 0; i < depthParam; i++)
            {
                var copy = new List <int>(turnSequence);
                copy.Reverse();
                turnSequence.Add(1);
                foreach (int turn in copy)
                {
                    turnSequence.Add(-turn);
                }
            }
            bool    increasez = false;
            int     one, two;
            double  z2;
            double  startingAngle = -depthParam * (Math.PI / 4);
            double  side = 400 / Math.Pow(2, depthParam / 2.0);
            double  angle = startingAngle;
            int     x1 = 230, y1 = 350;
            int     x2 = x1 + (int)(Math.Cos(angle) * side);
            int     y2 = y1 + (int)(Math.Sin(angle) * side);
            Vector3 A  = new Vector3(x1, y1, 0);

            one = scene.AddVertex(Vector3.TransformPosition(A, m));
            A   = new Vector3(x2, y2, 0);
            two = scene.AddVertex(Vector3.TransformPosition(A, m));
            scene.AddLine(one, two);
            x1  = x2;
            y1  = y2;
            one = two;
            int turns = turnSequence.Count / 100;
            int j     = 0;

            z2 = 1;
            int direction = 0;

            foreach (int turn in turnSequence)
            {
                angle += turn * (Math.PI / 2);
                x2     = x1 + (int)(Math.Cos(angle) * side);
                y2     = y1 + (int)(Math.Sin(angle) * side);
                if (j >= turns)
                {
                    j         = 0;
                    increasez = !increasez;
                    if (increasez)
                    {
                        direction++;
                    }
                }
                if (increasez)
                {
                    if (direction % 2 == 0)
                    {
                        z2 = z2 + Math.Abs((int)(Math.Cos(angle) * side));
                    }
                    else
                    {
                        z2 = z2 - Math.Abs((int)(Math.Cos(angle) * side));
                    }
                }

                A   = new Vector3(x2, y2, (float)z2);
                two = scene.AddVertex(Vector3.TransformPosition(A, m));
                scene.AddLine(one, two);
                x1  = x2;
                y1  = y2;
                one = two;
                retValue++;
                j++;
            }
            return(retValue);
        }
        private void addCube(SceneBrep scene, Matrix4 m, string param)
        {
            Vector3 P0, P1, P2, P3;
            Vector3 D0, D1, D2, D3;

            P0.X = 0;
            P0.Y = 0;
            P0.Z = 0;

            P1.X = 1;
            P1.Y = 0;
            P1.Z = 0;

            P2.X = 1;
            P2.Y = 1;
            P2.Z = 0;

            P3.X = 0;
            P3.Y = 1;
            P3.Z = 0;

            D0.X = 0;
            D0.Y = 0;
            D0.Z = 1;

            D1.X = 1;
            D1.Y = 0;
            D1.Z = 1;

            D2.X = 1;
            D2.Y = 1;
            D2.Z = 1;

            D3.X = 0;
            D3.Y = 1;
            D3.Z = 1;

            /*Vector3 delta;
             * delta.X = 0.5f;
             * delta.Y = 0.5f;
             * delta.Z = 0.5f;
             *
             * P0 -= delta;P1 -= delta;P2 -= delta;P3 -= delta;
             * D0 -= delta;
             * D1 -= delta;
             * D2 -= delta;
             * D3 -= delta;*/

            int p0 = scene.AddVertex(Vector3.TransformPosition(P0, m));
            int p1 = scene.AddVertex(Vector3.TransformPosition(P1, m));
            int p2 = scene.AddVertex(Vector3.TransformPosition(P2, m));
            int p3 = scene.AddVertex(Vector3.TransformPosition(P3, m));

            int d0 = scene.AddVertex(Vector3.TransformPosition(D0, m));
            int d1 = scene.AddVertex(Vector3.TransformPosition(D1, m));
            int d2 = scene.AddVertex(Vector3.TransformPosition(D2, m));
            int d3 = scene.AddVertex(Vector3.TransformPosition(D3, m));

            scene.AddLine(p0, p1);
            scene.AddLine(p1, p2);
            scene.AddLine(p2, p3);
            scene.AddLine(p3, p0);

            scene.AddLine(d0, d1);
            scene.AddLine(d1, d2);
            scene.AddLine(d2, d3);
            scene.AddLine(d3, d0);

            scene.AddLine(p0, d0);
            scene.AddLine(p1, d1);
            scene.AddLine(p2, d2);
            scene.AddLine(p3, d3);
        }
        private void drawTetrahedronRecursive(int depth, SceneBrep scene, Matrix4 m, string param, Vector3 a, Vector3 b, Vector3 c, Vector3 d)
        {
            if (depth == 0)
            {
                return;
            }
            Vector3 stand;

            stand.X = 0;
            stand.Y = 0;
            stand.Z = 0;
            int     ab, ac, ad, bc, bd, cd;
            Vector3 AB = stand, AC = stand, AD = stand;
            Vector3 BC = stand, BD = stand;
            Vector3 CD = stand;

            calculateMiddle(a, b, c, d, ref AB, ref AC, ref AD, ref BC, ref BD, ref CD);

            ab = scene.AddVertex(Vector3.TransformPosition(AB, m));
            ac = scene.AddVertex(Vector3.TransformPosition(AC, m));
            ad = scene.AddVertex(Vector3.TransformPosition(AD, m));
            bc = scene.AddVertex(Vector3.TransformPosition(BC, m));
            bd = scene.AddVertex(Vector3.TransformPosition(BD, m));
            cd = scene.AddVertex(Vector3.TransformPosition(CD, m));

            scene.AddLine(ab, ac);
            scene.AddLine(ac, bc);
            scene.AddLine(bc, ab);

            scene.AddLine(ab, bd);
            scene.AddLine(bd, ad);
            scene.AddLine(ad, ab);

            scene.AddLine(ac, ad);
            scene.AddLine(ad, cd);
            scene.AddLine(cd, ac);

            scene.AddLine(bc, cd);
            scene.AddLine(cd, bd);
            scene.AddLine(bd, bc);

            drawTetrahedronRecursive(depth - 1, scene, m, param, AB, b, BC, BD);
            drawTetrahedronRecursive(depth - 1, scene, m, param, a, AB, AC, AD);
            drawTetrahedronRecursive(depth - 1, scene, m, param, AC, BC, c, CD);
            drawTetrahedronRecursive(depth - 1, scene, m, param, AD, BD, CD, d);
        }
Beispiel #14
0
        /// <summary>
        /// Construct a new Brep solid (preferebaly closed = regular one).
        /// </summary>
        /// <param name="scene">B-rep scene to be modified</param>
        /// <param name="m">Transform matrix (object-space to world-space)</param>
        /// <param name="param">Shape parameters if needed</param>
        /// <returns>Number of generated faces (0 in case of failure)</returns>
        public int AddMesh(SceneBrep scene, Matrix4 m, string param)
        {
            parseParams(param);
            scene.LineWidth = lineWidth;

            // create shape
            // create vertices in 3D local space
            Vector3[] shapeVerticesLocal = new Vector3[]
            {
                new Vector3(0, 1, depth),
                new Vector3(0.866025f, 0.5f, depth),
                new Vector3(0.866025f, -0.5f, depth),
                new Vector3(0, -1, depth),
                new Vector3(-0.866025f, -0.5f, depth),
                new Vector3(-0.866025f, 0.5f, depth),
                new Vector3(0, 0, depth),

                new Vector3(0, 1, -depth),
                new Vector3(0.866025f, 0.5f, -depth),
                new Vector3(0.866025f, -0.5f, -depth),
                new Vector3(0, -1, -depth),
                new Vector3(-0.866025f, -0.5f, -depth),
                new Vector3(-0.866025f, 0.5f, -depth),
                new Vector3(0, 0, -depth),
            };

            // push vertices to scene and get theirs indexes
            int[] shapeVerticesIndex = new int[shapeVerticesLocal.Length];
            for (int i = 0; i < shapeVerticesLocal.Length; i++)
            {
                int vertexIndex = scene.AddVertex(Vector3.TransformPosition(shapeVerticesLocal[i], m));
                shapeVerticesIndex[i] = vertexIndex;
                scene.SetColor(vertexIndex, new Vector3(0, 0, 0));
            }

            Vector3[] edgeColors = new Vector3[] { new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 0) };

            // { vertex, vertex, color }
            List <int[, ]> shapeEdges = new List <int[, ]>();

            shapeEdges.Add(new int[2, 3] {
                { 0, 1, 0 }, { 8, 9, 0 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 1, 2, 1 }, { 9, 13, 1 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 2, 6, 1 }, { 10, 9, 1 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 2, 3, 0 }, { 10, 11, 0 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 3, 4, 1 }, { 11, 13, 1 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 4, 6, 1 }, { 12, 11, 1 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 4, 5, 0 }, { 12, 7, 0 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 5, 0, 1 }, { 7, 13, 1 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 0, 6, 1 }, { 8, 7, 1 }
            });

            shapeEdges.Add(new int[2, 3] {
                { 6, 0, 2 }, { 9, 13, 2 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 6, 2, 2 }, { 11, 13, 2 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 6, 4, 2 }, { 7, 13, 2 }
            });

            shapeEdges.Add(new int[2, 3] {
                { 0, 1, 3 }, { 7, 8, 3 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 1, 2, 3 }, { 8, 9, 3 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 2, 3, 3 }, { 9, 10, 3 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 3, 4, 3 }, { 10, 11, 3 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 4, 5, 3 }, { 11, 12, 3 }
            });
            shapeEdges.Add(new int[2, 3] {
                { 5, 0, 3 }, { 12, 7, 3 }
            });



            // push edges to scene
            foreach (int[,] group in shapeEdges)
            {
                scene.AddLine(shapeVerticesIndex[group[0, 0]], shapeVerticesIndex[group[0, 1]]);
                scene.AddLine(shapeVerticesIndex[group[1, 0]], shapeVerticesIndex[group[1, 1]]);
            }


            //push faces to scene
            foreach (int[,] group in shapeEdges)
            {
                for (int i = 0; i < splits; i++)
                {
                    Vector3 beginDiff = shapeVerticesLocal[group[0, 0]] - shapeVerticesLocal[group[0, 1]];
                    beginDiff /= splits;
                    Vector3 begin = shapeVerticesLocal[group[0, 0]] - beginDiff * i;

                    Vector3 endDiff = shapeVerticesLocal[group[1, 0]] - shapeVerticesLocal[group[1, 1]];
                    endDiff /= splits;
                    Vector3 end = shapeVerticesLocal[group[1, 0]] - endDiff * i;


                    int beginIndex = scene.AddVertex(Vector3.TransformPosition(begin, m));
                    scene.SetColor(beginIndex, edgeColors[group[0, 2]]);

                    int endIndex = scene.AddVertex(Vector3.TransformPosition(end, m));
                    scene.SetColor(endIndex, edgeColors[group[1, 2]]);

                    scene.AddLine(beginIndex, endIndex);
                }
            }
            return(1); // some magic number
        }
Beispiel #15
0
        /// <summary>
        /// Construct a new Brep solid (preferebaly closed = regular one).
        /// </summary>
        /// <param name="scene">B-rep scene to be modified</param>
        /// <param name="m">Transform matrix (object-space to world-space)</param>
        /// <param name="param">Shape parameters if needed</param>
        /// <returns>Number of generated faces (0 in case of failure)</returns>
        public int AddMesh(SceneBrep scene, Matrix4 m, string param)
        {
            parseParams(param);

            int elements = 6 + (depth > 0 ? 8 * (int)Math.Pow(3, depth - 1) : 0) + (center ? 1 : 0);

            scene.Reserve(elements);

            int middle = scene.AddVertex(Vector3.TransformPosition(new Vector3(0, 0, 0), m));

            GenerateBaseVertices();
            GenerateSubVertices();

            // Generate int positions
            {
                Queue <Vertex> currentVertices = new Queue <Vertex>(baseVertices);

                while (currentVertices.Count > 0)
                {
                    Vertex currentVertex = currentVertices.Dequeue();
                    currentVertex.Position = scene.AddVertex(Vector3.TransformPosition(currentVertex.Vector3, m));

                    for (int i = 0; i < currentVertex.SubVertices.Count; i++)
                    {
                        currentVertices.Enqueue(currentVertex.SubVertices[i]);
                    }
                }
            }


            if (neighbors)
            {
                Queue <Vertex> currentVertices = new Queue <Vertex>(baseVertices);

                while (currentVertices.Count > 0)
                {
                    Vertex currentVertex = currentVertices.Dequeue();
                    for (int i = 0; i < currentVertex.Neighbors.Count; i++)
                    {
                        scene.AddLine(currentVertex.Position, currentVertex.Neighbors[i].Position);
                    }

                    for (int i = 0; i < currentVertex.SubVertices.Count; i++)
                    {
                        currentVertices.Enqueue(currentVertex.SubVertices[i]);
                    }
                }
            }

            if (center)
            {
                Queue <Vertex> currentVertices = new Queue <Vertex>(baseVertices);

                while (currentVertices.Count > 0)
                {
                    Vertex currentVertex = currentVertices.Dequeue();
                    scene.AddLine(currentVertex.Position, middle);

                    for (int i = 0; i < currentVertex.SubVertices.Count; i++)
                    {
                        currentVertices.Enqueue(currentVertex.SubVertices[i]);
                    }
                }
            }

            scene.LineWidth = 3.0f;

            return(elements);
        }