示例#1
0
 public static void DrawAxis(int x, int y, GLCamera BBCamera)
 {
     OpenTK.Graphics.OpenGL.GL.PushMatrix();
     OpenTK.Graphics.OpenGL.GL.Viewport(x, y, 100, 100);
     OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Projection);
     OpenTK.Graphics.OpenGL.GL.LoadIdentity();
     Glu.Perspective(45.0, 1.0, 1.0, 100000.0);
     OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Modelview);
     OpenTK.Graphics.OpenGL.GL.LoadIdentity();
     OpenTK.Graphics.OpenGL.GL.Translate(0.0f, 0.0f, -5f);
     OpenTK.Graphics.OpenGL.GL.Rotate(BBCamera.GetXRotation(), 1f, 0.0f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.Rotate(BBCamera.GetYRotation(), 0.0f, 1f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.Rotate(BBCamera.GetZRotation(), 0.0f, 0.0f, 1f);
     OpenTK.Graphics.OpenGL.GL.PushMatrix();
     OpenTK.Graphics.OpenGL.GL.LineWidth(4f);
     OpenTK.Graphics.OpenGL.GL.Color3(1f, 0.0f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
     OpenTK.Graphics.OpenGL.GL.Vertex3(0.0f, 0.0f, -1f);
     OpenTK.Graphics.OpenGL.GL.Vertex3(0, 0, 0);
     OpenTK.Graphics.OpenGL.GL.End();
     OpenTK.Graphics.OpenGL.GL.Color3(0.0f, 1f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
     OpenTK.Graphics.OpenGL.GL.Vertex3(0.0f, 1f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.Vertex3(0, 0, 0);
     OpenTK.Graphics.OpenGL.GL.End();
     OpenTK.Graphics.OpenGL.GL.Color3(0.0f, 0.0f, 1f);
     OpenTK.Graphics.OpenGL.GL.Begin(OpenTK.Graphics.OpenGL.BeginMode.Lines);
     OpenTK.Graphics.OpenGL.GL.Vertex3(-1f, 0.0f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.Vertex3(0.0f, 0.0f, 0.0f);
     OpenTK.Graphics.OpenGL.GL.End();
     OpenTK.Graphics.OpenGL.GL.PopMatrix();
     OpenTK.Graphics.OpenGL.GL.PopMatrix();
 }
示例#2
0
        /// <summary>Initialize the GL view</summary>
        public void InitializeView()
        {
            if (glControl.ClientSize.Height == 0)
            {
                glControl.ClientSize = new System.Drawing.Size(glControl.ClientSize.Width, 1);
            }
            GL.Viewport(0, 0, glControl.ClientSize.Width, glControl.ClientSize.Height);

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            var ratio = glControl.ClientSize.Width / (double)glControl.ClientSize.Height;

            if (PerspectiveProjection)
            {
                Glu.Perspective(45, ratio, .1, 100);
            }
            else
            {
                double size = transformActive.Location.Z * -.4;
                GL.Ortho(-ratio * size, ratio * size, -size, size, -100, 100);
            }
            GL.MatrixMode(MatrixMode.Modelview);                    // Select The Modelview Matrix
            GL.LoadIdentity();                                      // Reset The Modelview Matrix
        }
示例#3
0
        public static void DrawJinjos(int x, int y, bool[] jinjos)
        {
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            OpenTK.Graphics.OpenGL.GL.Viewport(x, y, 400, 100);
            OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Projection);
            OpenTK.Graphics.OpenGL.GL.LoadIdentity();
            Glu.Perspective(45.0, 1.0 * 4.0, 1.0, 100000.0);
            OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Modelview);
            OpenTK.Graphics.OpenGL.GL.LoadIdentity();
            OpenTK.Graphics.OpenGL.GL.Translate(-2f, -1f, -3f);
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            int num = 1;

            OpenTK.Graphics.OpenGL.GL.Disable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);
            OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Texture2D);
            OpenTK.Graphics.OpenGL.GL.Color3(1f, 1f, 1f);
            for (int index = 0; index < 5; ++index)
            {
                if (jinjos[index])
                {
                    OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_cjinjos[index]);
                }
                else
                {
                    OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_ncjinjos[index]);
                }
                BBUI.Draw2DRectangle(0.0f, 0.0f, 1f, 1f);
                OpenTK.Graphics.OpenGL.GL.Translate((float)num, 0.0f, 0.0f);
            }
            OpenTK.Graphics.OpenGL.GL.Disable(OpenTK.Graphics.OpenGL.EnableCap.Texture2D);
            OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
        }
示例#4
0
        /// <summary>
        /// set up viewport, projection and modelview matrices
        /// </summary>
        protected override void UpdateMatrices(float width2D, float height2D, float zDepth)
        {
            if (ClientSize.IsEmpty)
            {
                return;
            }
            if (m_plotBoxScreenRectF.Size.IsEmpty)
            {
                return;
            }

            float      worldSceneWidth;
            float      worldSceneHeight;
            ILPoint3Df camPos = m_camera.Position;
            ILPoint3Df top;
            ILPoint3Df moveOffset;

            helperUpdateMatrices(width2D, height2D, out worldSceneWidth, out worldSceneHeight, out top, out moveOffset);

            #region projection
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            float nearPlane = 0.2f; //Math.Max(0.0f, m_camera.Distance - m_clippingView.SphereRadius);
            float farPlane  = m_camera.Distance + m_clippingView.SphereRadius * 100;
            if (m_projection == Projection.Perspective)
            {
                float angle = (float)Math.Atan2(worldSceneHeight / 2.0f, m_camera.Distance - (zDepth / 2)) * 2.0f;
                Glu.Perspective(angle / Math.PI * 180, (double)worldSceneWidth / worldSceneHeight,
                                nearPlane, farPlane);
            }
            else
            {
                GL.Ortho(
                    -worldSceneWidth / 2.0, worldSceneWidth / 2.0
                    , -worldSceneHeight / 2.0, worldSceneHeight / 2.0
                    , nearPlane, farPlane);
            }
            GL.GetDouble(GetPName.ProjectionMatrix, m_projMatrix);
            // set viewport
            GL.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
            GL.GetInteger(GetPName.Viewport, m_viewMatrix);
            #endregion

            #region modelview
            MakeCurrent();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            //top = ILPoint3Df.normalize(top);
            Glu.LookAt(camPos.X, camPos.Y, camPos.Z
                       , m_camera.LookAt.X, m_camera.LookAt.Y, m_camera.LookAt.Z
                       , m_camera.Top.X, m_camera.Top.Y, m_camera.Top.Z);
            GL.Translate(moveOffset.X, moveOffset.Y, moveOffset.Z);
            GL.GetDouble(GetPName.ModelviewMatrix, m_modelViewMatrix);
            #endregion
        }
示例#5
0
        public void AffectResize(int width, int height)
        {
            if (width == 0 || height == 0)
            {
                return;
            }
            GL.Viewport(0, 0, width, height);
            var aspectRatio = width / (double)height;

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            Glu.Perspective(CameraFovy, aspectRatio, CameraZnear, CameraZfar);
        }
示例#6
0
        private void UpdateProjection()
        {
            if (Width > 0 && Height > 0)
            {
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();

                Glu.Perspective(camera.Perspective.Angle,
                                Width / (double)Height,
                                camera.Perspective.Near,
                                camera.Perspective.Far);

                GL.Viewport(0, 0, Width, Height);
            }
        }
示例#7
0
        // --- functions ---

        /// <summary>Sets the viewing angle and updates the perspective accordingly. This function changes the current matrix to GL_MODELVIEW once finished.</summary>
        /// <param name="verticalViewingAngle">The vertical viewing angle in radians.</param>
        internal void SetViewingAngle(double verticalViewingAngle)
        {
            double aspectRatio = (double)Screen.Width / (double)Screen.Height;

            this.HorizontalViewingAngle = 2.0 * Math.Atan(aspectRatio * Math.Tan(0.5 * this.VerticalViewingAngle));
            this.VerticalViewingAngle   = verticalViewingAngle;
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            const double inverseDegrees = 57.295779513082320877;

            // TODO //
            // The old renderer assumes a negative aspect ratio. Once the new renderer
            // is implemented, change the aspect ratio in the following line to positive.
            Glu.Perspective(this.VerticalViewingAngle * inverseDegrees, -aspectRatio, 1.0, this.ViewingDistance);
            GL.MatrixMode(MatrixMode.Modelview);
        }
示例#8
0
        public static void DrawStats(LevelStat ls)
        {
            OpenTK.Graphics.OpenGL.GL.LoadIdentity();
            OpenTK.Graphics.OpenGL.GL.Viewport(0, 0, 120, 120);
            OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Projection);
            OpenTK.Graphics.OpenGL.GL.LoadIdentity();
            Glu.Perspective(45.0, 1.0, 1.0, 100000.0);
            OpenTK.Graphics.OpenGL.GL.MatrixMode(OpenTK.Graphics.OpenGL.MatrixMode.Modelview);
            OpenTK.Graphics.OpenGL.GL.LoadIdentity();
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            OpenTK.Graphics.OpenGL.GL.Translate(-2f, 0.0f, -5f);
            OpenTK.Graphics.OpenGL.GL.Disable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);
            OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.Texture2D);
            OpenTK.Graphics.OpenGL.GL.Color3(1f, 1f, 1f);
            OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_stats);
            BBUI.Draw2DRectangle(-2f, -2f, 2f, 2f);
            float  x1  = 0.0f;
            string str = ls.jiggy.ToString();

            OpenTK.Graphics.OpenGL.GL.Translate(1f, 0.0f, 0.0f);
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            OpenTK.Graphics.OpenGL.GL.Translate(0.0f, 0.8f, 0.0f);
            for (int index1 = 0; index1 < str.Length; ++index1)
            {
                int index2 = int.Parse(str[index1].ToString());
                OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_numbers[index2]);
                OpenTK.Graphics.OpenGL.GL.Translate(x1, 0.0f, 0.0f);
                BBUI.Draw2DRectangle(0.0f, 0.0f, 1f, 1f);
                x1 = 0.6f;
            }
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
            OpenTK.Graphics.OpenGL.GL.Translate(0.0f, -0.1f, 0.0f);
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            float x2 = 0.0f;

            foreach (char ch in ls.note.ToString())
            {
                int index = int.Parse(ch.ToString());
                OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_numbers[index]);
                OpenTK.Graphics.OpenGL.GL.Translate(x2, 0.0f, 0.0f);
                BBUI.Draw2DRectangle(0.0f, 0.0f, 1f, 1f);
                x2 = 0.6f;
            }
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
            OpenTK.Graphics.OpenGL.GL.Translate(0.0f, -0.8f, 0.0f);
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            float x3 = 0.0f;

            foreach (char ch in ls.eh.ToString())
            {
                int index = int.Parse(ch.ToString());
                OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_numbers[index]);
                OpenTK.Graphics.OpenGL.GL.Translate(x3, 0.0f, 0.0f);
                BBUI.Draw2DRectangle(0.0f, 0.0f, 1f, 1f);
                x3 = 0.6f;
            }
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
            OpenTK.Graphics.OpenGL.GL.Translate(0.0f, -0.9f, 0.0f);
            OpenTK.Graphics.OpenGL.GL.PushMatrix();
            float x4 = 0.0f;

            foreach (char ch in ls.mumbo.ToString())
            {
                int index = int.Parse(ch.ToString());
                OpenTK.Graphics.OpenGL.GL.BindTexture(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, BBUI.t_numbers[index]);
                OpenTK.Graphics.OpenGL.GL.Translate(x4, 0.0f, 0.0f);
                BBUI.Draw2DRectangle(0.0f, 0.0f, 1f, 1f);
                x4 = 0.6f;
            }
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
            OpenTK.Graphics.OpenGL.GL.Disable(OpenTK.Graphics.OpenGL.EnableCap.Texture2D);
            OpenTK.Graphics.OpenGL.GL.Enable(OpenTK.Graphics.OpenGL.EnableCap.DepthTest);
            OpenTK.Graphics.OpenGL.GL.PopMatrix();
        }
        private void DrawAll()
        {
            //SETGL
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.ClearColor(Color.Black);
            GL.ClearColor(1.0f, 1.0f, 0.5f, 0.7f);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //SETVIEW
            GL.Viewport(0, 0, this.Bounds.Width, this.Bounds.Height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            Glu.Perspective(45.0f, (float)this.Bounds.Width / (float)this.Bounds.Height, 1.0, 10.0);
            Glu.LookAt(0.0, 0.0, 4.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            // 计算新的旋转矩阵,即:M = E · R = R
            GL.Rotate(theta, axis[0], axis[1], axis[2]);
            // 左乘上前一次的矩阵,即:M = R · L
            GL.MultMatrix(lastMatrix);
            // 保存此次处理结果,即:L = M
            GL.GetFloat(GetPName.ModelviewMatrix, lastMatrix);
            theta = 0.0f;

            // 画坐标轴
            DrawOLineInGL(0, 0, 1.5f, 2.0f, Color.Red, true);
            DrawOLineInGL(Math.PI, 0, 1.5f, 2.0f, Color.Red, false);
            DrawOLineInGL(Math.PI / 2, 0, 1.5f, 2.0f, Color.Lime, true);
            DrawOLineInGL(-Math.PI / 2, 0, 1.5f, 2.0f, Color.Lime, false);
            DrawOLineInGL(0, Math.PI / 2, 1.5f, 2.0f, Color.Blue, true);
            DrawOLineInGL(0, -Math.PI / 2, 1.5f, 2.0f, Color.Blue, false);
            //DrawOLineInGL(_azi, _ele, 1.2f, 3.0f, Color.White, true);

            GL.Begin(BeginMode.Quads);
            // 坐标面
            //GL.Color4(1.0f, 0.0f, 0.0f, 0.4f);
            //GL.Vertex3(0.0f, 1.0f, 1.0f);
            //GL.Vertex3(0.0f, 1.0f, -1.0f);
            //GL.Vertex3(0.0f, -1.0f, -1.0f);
            //GL.Vertex3(0.0f, -1.0f, 1.0f);
            //GL.Color4(0.0f, 1.0f, 0.0f, 0.4f);
            //GL.Vertex3(1.0f, 0.0f, 1.0f);
            //GL.Vertex3(1.0f, 0.0f, -1.0f);
            //GL.Vertex3(-1.0f, 0.0f, -1.0f);
            //GL.Vertex3(-1.0f, 0.0f, 1.0f);
            //GL.Color4(0.0f, 0.0f, 1.0f, 0.4f);
            //GL.Vertex3(1.0f, 1.0f, 0.0f);
            //GL.Vertex3(1.0f, -1.0f, 0.0f);
            //GL.Vertex3(-1.0f, -1.0f, 0.0f);
            //GL.Vertex3(-1.0f, 1.0f, 0.0f);

            //曲面
            if (_binaryFunction != null)
            {
                GL.Color4(0.5f, 0.5f, 1.0f, 0.8f);
                for (double i = -10d; i < 10d; i = i + 0.2d)
                {
                    for (double j = -10d; j < 10d; j = j + 0.2d)
                    {
                        GL.Vertex3(i / 10, j / 10, _binaryFunction(i, j) / 10);
                        GL.Vertex3(i / 10, (j + 0.2d) / 10, _binaryFunction(i, j + 0.2d) / 10);
                        GL.Vertex3((i + 0.2d) / 10, (j + 0.2d) / 10, _binaryFunction(i + 0.2d, j + 0.2d) / 10);
                        GL.Vertex3((i + 0.2d) / 10, j / 10, _binaryFunction(i + 0.2d, j) / 10);
                    }
                }
            }
            GL.End();

            GL.Disable(EnableCap.DepthTest);

            byte[] lettersX =
            {
                0x00, 0xef, 0x46, 0x2c, 0x2c, 0x18, 0x18, 0x18, 0x34, 0x34, 0x62, 0xf7, 0x00
            };
            byte[] lettersY =
            {
                0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x2c, 0x2c, 0x46, 0x46, 0xef, 0x00
            };
            byte[] lettersZ =
            {
                0x00, 0xfe, 0x63, 0x63, 0x30, 0x30, 0x18, 0x0c, 0x0c, 0x06, 0xc6, 0x7f, 0x00
            };
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1.0f);
            GL.Color3(1.0f, 0.0f, 0.0f);
            GL.RasterPos3(1.4f, 0.0f, 0.0f);
            GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersX);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.RasterPos3(0.0f, 1.4f, 0.0f);
            GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersY);
            GL.Color3(0.0f, 0.0f, 1.0f);
            GL.RasterPos3(0.0f, 0.0f, 1.4f);
            GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersZ);
            SwapBuffers();
        }
示例#10
0
        //画出全部图像:
        private void DrawAll()
        {
            #region  SET GL(设置GL)
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.ClearColor(Color.Black);
            // GL.ClearColor(0.1f, 0.2f, 0.2f, 0.7f); //画布背景色
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

            //SETVIEW(设置视口):
            GL.Viewport(0, 0, this.Bounds.Width, this.Bounds.Height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            Glu.Perspective(45.0f, (float)this.Bounds.Width / (float)this.Bounds.Height, 1.0, 10.0);
            Glu.LookAt(0.0, 0.0, 4.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            #endregion

            //画大地,画天空(静止背景)=================================
            //DrawBg();  //Draw the Background
            //=========================================================

            #region 全局变换(缩放,平移,旋转)
            //全局缩放:
            GL.Scale(1 + whl, 1 + whl, 1 + whl);
            whl = 0;

            //全局平移(对象的X,Y轴方向平移):
            GL.Translate(dltx, dlty, dltz);
            //dltx = 0; dlty = 0; dltz = 0;

            //全局旋转,计算新的旋转矩阵,即:M = E · R = R
            GL.Rotate(theta, axis[0], axis[1], axis[2]);
            //GL.Rotate(theta,0, 0, 1);
            //左乘上前一次的矩阵,即:M = R · L
            GL.MultMatrix(lastMatrix);

            //保存此次处理结果,即:L = M
            GL.GetFloat(GetPName.ModelviewMatrix, lastMatrix);
            theta = 0.0f;


            #endregion


            //================  动画  ===================
            this.Invalidate();   //引发重绘,动画必须
            ng    = 0.1;         //速度控制
            theta = (float)(ng); //在原基础上,递增的旋转角
            mg    = mg % 360 + 0.01;
            mg2   = mg2 % 360 + 0.05;
            mg3   = mg3 % (2 * Math.PI) + 0.01;

            planetRotateSpeed = 20;
            int zoomscale = 60;      //画行星和运行轨迹,把星体半径放大n倍,否则太小
            showOrbit = false;
            merSpeed  = merSpeed % 360 + getSpeed(88);
            venSpeed  = venSpeed % 360 + getSpeed(225);
            earSpeed  = earSpeed % 360 + getSpeed(365);
            marSpeed  = marSpeed % 360 + getSpeed(657);
            jupSpeed  = jupSpeed % 360 + getSpeed(12 * 365);
            satSpeed  = satSpeed % 360 + getSpeed(29 * 365);
            uraSpeed  = uraSpeed % 360 + getSpeed(84 * 365);
            nepSpeed  = nepSpeed % 360 + getSpeed(165 * 365);


            //也可结合时间控制:DateTime.Now.Ticks,DateTime.Now.Millisecond
            //======================================



            //DrawAixs();//绘制坐标轴
            //DrawChar();//绘制字母X,Y,Z


            //DrawModels();//内置立体件
            //DrawTorus(); //圆环轮胎体
            //DrawPlane();//绘制X,Y,Z坐标平面

            //DrawArc();//通过不在同一直线上的三点画圆弧
            //DrawCylinder();//绘制空间圆柱,圆台,圆锥


            // DrawBody(0,0,0,43,430,0,0,1,mg, Color.OrangeRed);//SUN
            // GenerateStars(10);
            DrawPlanet(0, 43 * zoomscale, nepSpeed, false, Color.OrangeRed, 0);           //SUN
            DrawPlanet(3590, 0.15 * zoomscale, merSpeed, false, Color.Silver, 0);         //Mercury
            DrawPlanet(6720, 0.37 * zoomscale, venSpeed, false, Color.Gold, 0);           //Venus
            DrawPlanet(9300, 0.39 * zoomscale, earSpeed, true, Color.DeepSkyBlue, 1);     //Earth
            DrawPlanet(14160, 0.21 * zoomscale, marSpeed, false, Color.DarkRed, 0);       //Mars
            DrawPlanet(48380, 4.34 * zoomscale, jupSpeed, true, Color.Brown, 4);          //Jupiter
            DrawPlanet(89070, 3.62 * zoomscale, satSpeed, true, Color.SandyBrown, 4);     //Saturn
            DrawPlanet(178400, 1.576 * zoomscale, uraSpeed, false, Color.DeepSkyBlue, 0); //Uranus
            DrawPlanet(279300, 1.024 * zoomscale, nepSpeed, false, Color.DeepSkyBlue, 0); //Neptune
            //======================================
            GL.Disable(EnableCap.DepthTest);
            SwapBuffers();
        }
示例#11
0
        //画出全部图像:
        private void DrawAll()
        {
            #region  SET GL(设置GL)
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.ClearColor(Color.Black);
            GL.ClearColor(0.1f, 0.2f, 0.2f, 0.7f); //画布背景色
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusConstantAlpha);

            //SETVIEW(设置视口):
            GL.Viewport(0, 0, this.Bounds.Width, this.Bounds.Height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            Glu.Perspective(45.0f, (float)this.Bounds.Width / (float)this.Bounds.Height, 1.0, 10.0);
            Glu.LookAt(0.0, 0.0, 4.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            #endregion

            //画大地,画天空(静止背景)=================================
            DrawBg();  //Draw the Background
            //=========================================================

            #region 全局变换(缩放,平移,旋转)
            //全局缩放:
            GL.Scale(1 + whl, 1 + whl, 1 + whl);
            whl = 0;

            //全局平移(对象的X,Y轴方向平移):
            GL.Translate(dltx, dlty, dltz);
            //dltx = 0; dlty = 0; dltz = 0;

            //全局旋转,计算新的旋转矩阵,即:M = E · R = R
            GL.Rotate(theta, axis[0], axis[1], axis[2]);

            //左乘上前一次的矩阵,即:M = R · L
            GL.MultMatrix(lastMatrix);

            //保存此次处理结果,即:L = M
            GL.GetFloat(GetPName.ModelviewMatrix, lastMatrix);
            theta = 0.0f;
            #endregion

            //======================================

            DrawAixs();//绘制坐标轴            
            DrawChar();//绘制字母X,Y,Z

            //DrawModels();//内置立体件
            //DrawTorus(); //圆环轮胎体
            //DrawPlane();//绘制X,Y,Z坐标平面
 
            //DrawArc();//通过不在同一直线上的三点画圆弧
            //DrawCylinder();//绘制空间圆柱
            
            //DrawBody();//绘制曲面体
            dwP3D();//绘制三维点集
            //dwDepth();//绘制三维点集

            //======================================
            GL.Disable(EnableCap.DepthTest);
            this.Invalidate();
            SwapBuffers();

            
        }       
示例#12
0
        private void DrawAll()
        {
            //SETGL
            GL.Enable(EnableCap.Blend);
            GL.Enable(EnableCap.DepthTest);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.ClearColor(Color.White);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            //SETVIEW
            GL.Viewport(0, 0, this.Bounds.Width, this.Bounds.Height);
            //把当前矩阵制定用于投影变换,后续的变换调用所影响的是投影矩阵projection matrix
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            /*Glu.Perspective表示创建一个表示对称透视视图平截头体的矩阵,并把它与当前矩阵相乘。fovy是YZ平面上视野的角度,范围【0,180】。
             * aspect是这个平截头体的纵横比,也就是宽度除于高度。near和far值分别是观察点与近侧裁剪平面以及远侧裁剪平
             * 面的距离(沿Z轴负方向)这两个值都是正的。
             */
            Glu.Perspective(45.0f, (float)this.Bounds.Width / (float)this.Bounds.Height, 1.0, 10.0);
            //摄像机位置在(0,0,4) 镜头瞄准(0,0,3) 镜头方向为方向为Y轴向上
            Glu.LookAt(0.0, 0.0, 4.0, 0.0, 0.0, 3.0, 0.0, 1.0, 0.0);
            //调用后表示以后影响的不再是投影矩阵而是模型矩阵
            GL.MatrixMode(MatrixMode.Modelview);
            //清除颜色和深度缓冲
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.LoadIdentity();
            GL.PushMatrix();
            GL.Begin(BeginMode.Quads);
            GL.Color3(0.7, 0.7, 0.7);
            //画后墙
            GL.Vertex3(-1.5f, 1.5f, -1.5f);
            GL.Vertex3(1.5f, 1.5f, -1.5f);
            GL.Vertex3(1.5f, -1.5f, -1.5f);
            GL.Vertex3(-1.5f, -1.5f, -1.5f);
            //画左墙
            GL.Color3(0.7, 0.2, 0.3);
            GL.Vertex3(-1.5f, 1.5f, -1.5f);
            GL.Vertex3(-1.5f, -1.5f, -1.5f);
            GL.Vertex3(-1.5f, -1.5f, 1.5f);
            GL.Vertex3(-1.5f, 1.5f, 1.5f);
            //画地面
            //画左墙
            GL.Color3(0.2, 0.7, 0.3);
            GL.Vertex3(-1.5f, -1.5f, -1.5f);
            GL.Vertex3(1.5f, -1.5f, -1.5f);
            GL.Vertex3(1.5f, -1.5f, 1.5f);
            GL.Vertex3(-1.5f, -1.5f, 1.5f);
            GL.End();
            GL.PopMatrix();

            //对当前投影矩阵进行初始化
            GL.LoadIdentity();
            // 计算新的旋转矩阵,即:M = E · R = R,围绕axis向量旋转theta角度
            GL.Rotate(theta, axis[0], axis[1], axis[2]);
            // 左乘上前一次的矩阵,即:M = R · L
            GL.MultMatrix(lastMatrix);
            // 保存此次处理结果,即:L = M
            GL.GetFloat(GetPName.ModelviewMatrix, lastMatrix);
            theta = 0.0f;

            //    GL.LoadIdentity();
            //根据角度旋转四轴
            GL.Rotate(_angleX, 1, 0, 0);
            //       GL.Rotate(_angleY, 0, 1, 0);
            GL.Rotate(_angleZ, 0, 0, 1);
            // 画坐标轴
            DrawAxis();
            // 画四轴
            DrawAirCraft();



            GL.Disable(EnableCap.DepthTest);

            byte[] lettersX =
            {
                0x00, 0xef, 0x46, 0x2c, 0x2c, 0x18, 0x18, 0x18, 0x34, 0x34, 0x62, 0xf7, 0x00
            };
            byte[] lettersY =
            {
                0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x2c, 0x2c, 0x46, 0x46, 0xef, 0x00
            };
            byte[] lettersZ =
            {
                0x00, 0xfe, 0x63, 0x63, 0x30, 0x30, 0x18, 0x0c, 0x0c, 0x06, 0xc6, 0x7f, 0x00
            };
            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1.0f);
            GL.Color3(1.0f, 0.0f, 0.0f);
            GL.RasterPos3(1.4f, 0.0f, 0.0f);
            GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersX);
            GL.Color3(0.0f, 1.0f, 0.0f);
            GL.RasterPos3(0.0f, 1.4f, 0.0f);
            GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersZ);
            GL.Color3(0.0f, 0.0f, 1.0f);
            GL.RasterPos3(0.0f, 0.0f, 1.4f);
            GL.Bitmap(8, 13, 0.0f, 0.0f, 20.0f, 0.0f, lettersY);
            SwapBuffers();
        }