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


C# OpenGL.UnProject方法代码示例

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


在下文中一共展示了OpenGL.UnProject方法的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: PointToVertexOnPlane

        /// <summary>
        /// This is a utility function that will turn a click
        /// on the control to a point on a specified plane.
        /// </summary>
        /// <param name="gl">OpenGL.</param>
        /// <param name="plane">The plane to project onto.</param>
        /// <param name="x">The X part of the point.</param>
        /// <param name="y">The Y part of the point.</param>
        /// <returns>A three-tuple representing the point on the floor.</returns>
        protected Vertex PointToVertexOnPlane(OpenGL gl, Plane plane, int x, int y)
        {
            //	The first thing we do is turn the click into a vector that
            //	is from the camera to the cursor.
            double[] point1 = gl.UnProject((double)x, (double)y, 0);
            double[] point2 = gl.UnProject((double)x, (double)y, 1);

            double[] direction = {point2[0] - point1[0],
                                     point2[1] - point1[1],
                                     point2[2] - point1[2]};

            //	Now we find out the position when the line intersects the
            //	ground level.
            if(direction[1] == 0)
                return null;

            double dist = 0;
            switch(plane)
            {
                case Plane.xy:
                    dist = -1.0 * point1[2] / direction[2];
                    break;
                case Plane.xz:
                    dist = -1.0 * point1[1] / direction[1];
                    break;
                case Plane.yz:
                    dist = -1.0 * point1[0] / direction[0];
                    break;
            }

            double px = point1[0] + dist*direction[0];
            double py = point1[1] + dist*direction[1];
            double pz = point1[2] + dist*direction[2];

            return new Vertex((float)px, (float)py, (float)pz);
        }
开发者ID:nromik,项目名称:sharpgl,代码行数:45,代码来源:Builder.cs


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