C# 如何在opengl中修改相机,以便在屏幕上看到整个曲面图?

C# 如何在opengl中修改相机,以便在屏幕上看到整个曲面图?,c#,opengl,sharpgl,C#,Opengl,Sharpgl,我在我的wpf应用程序中使用sharpgl,我有一个曲面图。问题是,当我试图移开观察摄像头时,我的很多情节都消失了。。。。我是opengl新手,如何调整我的相机以便从多个侧面看到我的绘图 namespace SharpGLWPFApplication1 { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class M

我在我的wpf应用程序中使用sharpgl,我有一个曲面图。问题是,当我试图移开观察摄像头时,我的很多情节都消失了。。。。我是opengl新手,如何调整我的相机以便从多个侧面看到我的绘图

namespace SharpGLWPFApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

     ///this is a set of 29 by 121 arrays cant put all data here on stackoverflow
        double[][] surface = new double[29][] 
            {new double[] { 0.157502594025719, 0.160975938019107, 0.168564003076642, 0.171284471913381, 0.174722441310675, 0.182467533566265, 0.190681891360462, 0.197452867532186, ..... }};



        /// <summary>Initializes a new instance of the <see cref="MainWindow"/> class.</summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the OpenGLDraw event of the openGLControl1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
        private void openGLControl_OpenGLDraw(object sender, OpenGLEventArgs args)
        {
            //  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);

            //  Nudge the rotation.
            rotation += 3.0f;

            float R = 0.3f;
            float G = 0.2f;
            float B = 0.1f;

            gl.Translate(-10f, 0f, 0f);
            gl.Begin(OpenGL.GL_TRIANGLES);
            for (int x = 1; x < surface.GetUpperBound(0); ++x)
            {

                for (int y = 1; y < surface[0].GetUpperBound(0) + 1; ++y)
                {
                    gl.Color(R, G, B);
                    double a = surface[x - 1][y - 1];
                    double b = surface[x][y - 1];
                    double c = surface[x][y];
                    double d = surface[x - 1][y];
                    // get four points on the surface (they form a quad)

                    gl.Vertex(x - 1, a, y - 1);
                    gl.Vertex(x, b, y - 1);
                    gl.Vertex(x, c, y);
                    // draw triangle abc

                    gl.Vertex(x - 1, a, y - 1);
                    gl.Vertex(x, c, y);
                    gl.Vertex(x - 1, d, y);
                    // draw triangle acd
                    R += y;
                    B += .0003f;
                    G += .0001f;
                }
                //R += .03f;
                //B += .03f;
                //G += .03f;
            }

            gl.End();




        }

        /// <summary>
        /// Handles the OpenGLInitialized event of the openGLControl1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
        private void openGLControl_OpenGLInitialized(object sender, OpenGLEventArgs args)
        {
            //  TODO: Initialise OpenGL here.

            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            //  Set the clear color.
            gl.ClearColor(0, 0, 0, 0);
        }

        /// <summary>
        /// Handles the Resized event of the openGLControl1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
        private void openGLControl_Resized(object sender, OpenGLEventArgs args)
        {
            //  TODO: Set the projection matrix here.

            //  Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            //  Set the projection matrix.
            gl.MatrixMode(OpenGL.GL_PROJECTION);

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

            //  Create a perspective transformation.
            gl.Perspective(60.0f, (double)Width / (double)Height, 0.01, 100.0);

            //  Use the 'look at' helper function to position and aim the camera.
            gl.LookAt(-105, 105, -105, 50, 0, 0, 0, 1, 0);

            //  Set the modelview matrix.
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
        }

        /// <summary>
        /// The current rotation.
        /// </summary>
        private float rotation = 0.0f;
    }
}

不确定是否使用SharpGL,但在透视图中,您表示希望远剪裁平面为100,现在您将相机设置为-105、105、-105,远大于100。因此,您可以通过将远剪裁平面设置得更远来解决问题?

不确定是否要使用SharpGL,但在透视图中,您表示希望远剪裁平面为100,现在您将相机设置为-105,105,-105,这比100更远。因此,您可以通过将远剪裁平面设置得更远来解决问题。

Nate Robins at提供了一些极好的示例,帮助您了解gl.Perspective和gl.LookAt以及更多的工作方式。

Nate Robins at提供了一些极好的示例,帮助您了解gl.Perspective和gl.LookAt以及更多的工作方式。

谢谢你,这就是问题所在,但是你有没有关于相机教程的好参考资料,这样我可以学到更多?谢谢,这就是问题所在,但是你有没有关于相机教程的好参考资料,这样我可以学到更多?