当前位置: 首页>>代码示例>>C#>>正文


C# Polygon.Triangulate方法代码示例

本文整理汇总了C#中Polygon.Triangulate方法的典型用法代码示例。如果您正苦于以下问题:C# Polygon.Triangulate方法的具体用法?C# Polygon.Triangulate怎么用?C# Polygon.Triangulate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polygon的用法示例。


在下文中一共展示了Polygon.Triangulate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseData

        /// <summary>
        /// This takes the feedback data and turns it into triangles.
        /// </summary>
        /// <param name="gl"></param>
        /// <param name="values">The number of triangles.</param>
        protected override void ParseData(OpenGL gl, int values)
        {
            int count = values;

            //	Create the triangle.
            triangle = new Polygon();
            triangle.Name = "Triangulated Polygon";

            //	For every value in the buffer...
            while (count != 0)
            {
                //	Get the token.
                float token = feedbackBuffer[values - count];

                //	Decrement count (move to the next token).
                count--;

                //	Check the type of the token.
                switch ((int)token)
                {
                    case (int)OpenGL.GL_PASS_THROUGH_TOKEN:
                        count--;
                        break;
                    case (int)OpenGL.GL_POINT_TOKEN:
                        //	We use only polygons, skip this single vertex (11 floats).
                        count -= 11;
                        break;
                    case (int)OpenGL.GL_LINE_TOKEN:
                        //	We use only polygons, skip this vertex pair (22 floats).
                        count -= 22;
                        break;
                    case (int)OpenGL.GL_LINE_RESET_TOKEN:
                        //	We use only polygons, skip this vertex pair (22 floats).
                        count -= 22;
                        break;
                    case (int)OpenGL.GL_POLYGON_TOKEN:

                        //	Get the number of vertices.
                        int vertexCount = (int)feedbackBuffer[values - count--];

                        //	Create an array of vertices.
                        Vertex[] vertices = new Vertex[vertexCount];

                        //	Parse them.
                        for (int i = 0; i < vertexCount; i++)
                        {
                            vertices[i] = new Vertex();
                            double x = (double)feedbackBuffer[values - count--];
                            double y = (double)feedbackBuffer[values - count--];
                            double z = (double)feedbackBuffer[values - count--];
                            double[] coords = gl.UnProject(x, y, z);
                            vertices[i].X = (float)coords[0];
                            vertices[i].Y = (float)coords[1];
                            vertices[i].Z = (float)coords[2];

                            //	Ignore the four r,g,b,a values and four material coords.
                            count -= 8;
                        }

                        //	Add a new face to the current polygon.
                        triangle.AddFaceFromVertexData(vertices);

                        break;
                }
            }

            //	Triangulate it.
            triangle.Triangulate();
        }
开发者ID:hhool,项目名称:sharpgl,代码行数:74,代码来源:Triangulator.cs

示例2: ReadData

        /// <summary>
        /// This function reads a polygon.
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected override object ReadData(BinaryReader reader)
        {
            //	Create a polygon.
            Polygon poly = new Polygon();

            //	Read a name chunk.
            CaligariName name = new CaligariName();
            name.Read(reader);
            poly.Name = name.name;

            //	Read the local axies.
            CaligariAxies axies = new CaligariAxies();
            axies.Read(reader);
            poly.Transformation.TranslateX = axies.centre.X;
            poly.Transformation.TranslateY = axies.centre.Y;
            poly.Transformation.TranslateZ = axies.centre.Z;
            //	poly.Rotate = axies.rotate;

            //	Read the position matrix.
            CaligariPosition pos = new CaligariPosition();
            pos.Read(reader);

            //	Read number of verticies.
            int verticesCount = reader.ReadInt32();

            //	Get them all
            for (int i = 0; i < verticesCount; i++)
            {
                //	Read a vertex.
                Vertex vertex = new Vertex(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                //	Multiply it by the position matrix.
                vertex = vertex * pos.matrix;

                //	Add it.
                poly.Vertices.Add(vertex);
            }

            //	Read UV count.
            int uvsCount = reader.ReadInt32();

            //	Read all of the UVs
            for (int i = 0; i < uvsCount; i++)
                poly.UVs.Add(new UV(reader.ReadInt32(), reader.ReadInt32()));

            //	Read faces count.
            int faces = reader.ReadInt32();

            //	Read each face.
            for (int f = 0; f < faces; f++)
            {
                Face face = new Face();
                poly.Faces.Add(face);

                //	Read face type flags.
                byte flags = reader.ReadByte();

                //	Read vertex count
                short verticesInFace = reader.ReadInt16();

                //	Do we read a material number?
                if ((flags & 0x08) == 0)	//	is it a 'hole' face?
                    reader.ReadInt16();

                //	Now read the indices, a vertex index and a uv index.
                for (short j = 0; j < verticesInFace; j++)
                    face.Indices.Add(new Index(reader.ReadInt32(), reader.ReadInt32()));
            }

            //	Any extra stuff?
            if (header.minorVersion > 4)
            {
                //	read flags.
                reader.ReadChars(4);

                if ((header.minorVersion > 5) && (header.minorVersion < 8))
                    reader.ReadChars(2);
            }

            //	Now that we've loaded the polygon, we triangulate it.
            poly.Triangulate();

            //	Finally, we update normals.
            poly.Validate(true);

            return poly;
        }
开发者ID:chantsunman,项目名称:sharpgl,代码行数:92,代码来源:PolygonChunk.cs


注:本文中的Polygon.Triangulate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。