Exemplo n.º 1
0
        public static IEnumerable <Line3D> CreateWiredCylinder(BoundingCylinder cylinder, int segments)
        {
            List <Line3D> resultList = new List <Line3D>();

            var verts = cylinder.GetVertices(segments);

            for (int i = 0; i < segments; i++)
            {
                if (i == segments - 1)
                {
                    resultList.Add(new Line3D(verts[i], verts[0]));
                    resultList.Add(new Line3D(verts[i + segments], verts[0 + segments]));

                    resultList.Add(new Line3D(verts[i], verts[i + segments]));
                }
                else
                {
                    resultList.Add(new Line3D(verts[i], verts[i + 1]));
                    resultList.Add(new Line3D(verts[i + segments], verts[i + 1 + segments]));

                    resultList.Add(new Line3D(verts[i], verts[i + segments]));
                }
            }

            return(resultList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate a triangle list from cylinder
        /// </summary>
        /// <param name="topology">Topology</param>
        /// <param name="cylinder">Cylinder</param>
        /// <param name="segments">Number of segments</param>
        /// <returns>Returns the triangle list</returns>
        public static IEnumerable <Triangle> ComputeTriangleList(Topology topology, BoundingCylinder cylinder, int segments)
        {
            List <Triangle> triangleList = new List <Triangle>();

            if (topology == Topology.TriangleList)
            {
                var verts = cylinder.GetVertices(segments);

                for (int i = 0; i < segments - 2; i++)
                {
                    triangleList.Add(new Triangle(verts[0], verts[i + 2], verts[i + 1]));
                    triangleList.Add(new Triangle(verts[0 + segments], verts[i + 1 + segments], verts[i + 2 + segments]));
                }

                for (int i = 0; i < segments; i++)
                {
                    if (i == segments - 1)
                    {
                        triangleList.Add(new Triangle(verts[i], verts[0], verts[i + segments]));
                        triangleList.Add(new Triangle(verts[0], verts[0 + segments], verts[i + segments]));
                    }
                    else
                    {
                        triangleList.Add(new Triangle(verts[i], verts[i + 1], verts[i + segments]));
                        triangleList.Add(new Triangle(verts[i + 1], verts[i + 1 + segments], verts[i + segments]));
                    }
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            return(triangleList.ToArray());
        }