Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#OpenGL(SharpGL)程序生成的墨卡托球体(极坐标)_C#_Opengl_Geometry_Procedural Generation_Sharpgl - Fatal编程技术网

C#OpenGL(SharpGL)程序生成的墨卡托球体(极坐标)

C#OpenGL(SharpGL)程序生成的墨卡托球体(极坐标),c#,opengl,geometry,procedural-generation,sharpgl,C#,Opengl,Geometry,Procedural Generation,Sharpgl,我想知道在“开始-结束”批处理中使用for循环写入点是否有效,因此我阅读了一个sphere算法,并根据我的阅读结果生成了该算法。正如您在下面的输出屏幕截图中看到的,它存在一些问题。我的目标是按程序生成一个球体,然后在运行时对其进行修改 但我想把我的目标定在短期内,并找出这些面孔不正确的原因。有人有什么想法吗 我有这个密码: private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e) { /

我想知道在“开始-结束”批处理中使用for循环写入点是否有效,因此我阅读了一个sphere算法,并根据我的阅读结果生成了该算法。正如您在下面的输出屏幕截图中看到的,它存在一些问题。我的目标是按程序生成一个球体,然后在运行时对其进行修改

但我想把我的目标定在短期内,并找出这些面孔不正确的原因。有人有什么想法吗

我有这个密码:

private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
    {
        //  Get the OpenGL object.
        OpenGL gl = openGLControl.OpenGL;

        //  Clear the color and depth buffer.
        gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

        //  Load the identity matrix.
        gl.LoadIdentity();

        //  Rotate around the Y axis.
        gl.Rotate(rotation, 0.0f, 1.0f, 0.0f);

        //Draw a ball
        //Drawing Mode
        gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
        //ball fields
        double radius = 4.0d;
        const double DEGREE = Math.PI/11.25;
        double x = 0;
        double y = 0;
        double z = 0;
        // ball batch
        gl.Begin(OpenGL.GL_TRIANGLE_STRIP_ADJACENCY);
        for (double j = 0.0d; j < Math.PI; j = j +DEGREE)
        {

            for (double i = 0; i < 2 * Math.PI; i = i + DEGREE)
            {

                x = radius * Math.Cos(i) * Math.Sin(j);
                y = radius * Math.Sin(j) * Math.Sin(i);
                z = radius * Math.Cos(j);
                gl.Color(Math.Abs(x + y), Math.Abs(y + z), Math.Abs(z + x));
                gl.Vertex(x, y, z);
            }

        }
        gl.End();

        //  Nudge the rotation.
        rotation += 3.0f;
    }
private void openGLControl\u OpenGLDraw(对象发送器、RenderEventArgs e)
{
//获取OpenGL对象。
OpenGL=openGLControl.OpenGL;
//清除颜色和深度缓冲区。
gl.Clear(OpenGL.gl_COLOR_BUFFER_BIT | OpenGL.gl_DEPTH_BUFFER_BIT);
//加载标识矩阵。
gl.LoadIdentity();
//绕Y轴旋转。
gl.旋转(旋转,0.0f,1.0f,0.0f);
//抽签
//绘图模式
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack,SharpGL.Enumerations.PolygonMode.Lines);
//球场
双半径=4.0d;
常数双度=Math.PI/11.25;
双x=0;
双y=0;
双z=0;
//球料
开始(OpenGL.gl\u三角形\u条带\u邻接);
对于(双j=0.0d;j

您目前获得了什么输出?您期望得到什么?看起来您正在尝试绘制三角形,但从未更新x和y,只更新z,因此三角形的所有点都是共线的。另外,如果对所有顶点只使用一种颜色,那么可以在循环之前调用gl.color。是的,这是完全有效的(为什么不呢?)。但是帮你自己一个忙,远离即时模式(glBegin…glEnd)。使用顶点数组,它更易于使用(从长远来看)并提供更好的性能。user3256930感谢您的洞察力,我已经将此项目搁置了很长时间,但我可以从我的输出外观看出您在说什么,但我对将更新应用于z的代码段有点困惑。我是一个新手,尝试处理复杂的事情,因为我就是这样做的。