Exemplo n.º 1
0
        private void DrawTestSolids(OpenGL gl)
        {
            if (this.isPlaneVisible)
            {
                GLDrawHelper.DrawPlane2D(gl, 2, 0.0f, 0.0f, -10.0f, 5.0f, System.Drawing.Color.Coral);
            }

            if (this.isCubeVisible)
            {
                GLDrawHelper.DrawFilledCube3D(gl, 0.0f, 0.0f, -20.0f, 5.0f, System.Drawing.Color.DarkGreen);
            }

            if (this.isParallelepipedVisible)
            {
                GLDrawHelper.DrawFilledBox3D(gl, 0.0f, 0.0f, -30.0f, 4.0f, 3.0f, 5.0f, System.Drawing.Color.Aqua);
            }

            if (this.isPyramidVisible)
            {
                GLDrawHelper.DrawPyramid(gl, 5.0f, 6.0f, 3.0f, System.Drawing.Color.CadetBlue, System.Drawing.Color.Gold);
            }

            if (this.isCylinderVisible)
            {
                GLDrawHelper.DrawCylinder(gl, 10.0f, 2.5f, 2.5f, 24, System.Drawing.Color.LightSkyBlue, System.Drawing.Color.Chocolate);
            }

            if (this.isConeVisible)
            {
                GLDrawHelper.DrawCylinder(gl, 10.0f, 2.5f, 0.0f, 24, System.Drawing.Color.LightSkyBlue, System.Drawing.Color.Chocolate);
            }

            if (this.isSphereVisible)
            {
                GLDrawHelper.DrawSphere(gl, 4.0f, System.Drawing.Color.Red, System.Drawing.Color.SeaShell);
            }
        }
Exemplo n.º 2
0
        private void OpenGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
        {
            OpenGL gl = this.openGLControl.OpenGL;

            /* Установка цвета, которым будет заполнен буфер кадра. */
            gl.ClearColor(backgroundColorRConstant, backgroundColorGConstant, backgroundColorBConstant, 1.0f);

            /* Очистка буферов цвета и глубины. */
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            gl.LoadIdentity();

            /* Преобразование сцены. */
            TransformScene(gl);

            /* Отрисовка главной системы координат. */
            if (this.isCoordinateSystemVisible)
            {
                Axes.Draw(gl, new Point(), this.coordinateSystemSize,
                          this.coordinateSystemLineWidth, this.coordinateSystemLineWidth, this.coordinateSystemLineWidth,
                          System.Drawing.Color.Red, System.Drawing.Color.GreenYellow, System.Drawing.Color.DeepSkyBlue);
            }

            /* Создание гизмо в центре. */
            if (this.isStartVisible)
            {
                GLDrawHelper.DrawStartTriangle(gl);
            }

            /* Отрисовка главных сеток. */
            if (this.isXYGridVisible)
            {
                Grid.Draw(gl, 0, new Point(), this.gridCellSize, this.gridSizeInCells, this.gridSizeInCells,
                          this.gridLineWidth, System.Drawing.Color.DarkGray);
            }

            if (this.isYZGridVisible)
            {
                Grid.Draw(gl, 1, new Point(), this.gridCellSize, this.gridSizeInCells, this.gridSizeInCells,
                          this.gridLineWidth, System.Drawing.Color.DarkGray);
            }

            if (this.isXZGridVisible)
            {
                Grid.Draw(gl, 2, new Point(), this.gridCellSize, this.gridSizeInCells, this.gridSizeInCells,
                          this.gridLineWidth, System.Drawing.Color.DarkGray);
            }

            if (this.isCreatingMode)
            {
                GLDrawHelper.DrawCube3D(gl, this.cubeX, this.cubeY, 0.0f,
                                        this.cubeSize, 3.0f, System.Drawing.Color.OrangeRed);
            }

            if (this.isCubeCreated)
            {
                GLDrawHelper.DrawFilledCube3D(gl, this.cubeX, this.cubeY, 0.0f,
                                              this.cubeSize, System.Drawing.Color.LightSkyBlue);
            }

            DrawTestSolids(gl);

            foreach (var tank in this.tankPlatoon)
            {
                tank.Draw(gl, System.Drawing.Color.Green, System.Drawing.Color.Green, System.Drawing.Color.Green);
            }

            if (wasFire)
            {
                foreach (var bullet in this.bullets)
                {
                    bullet.Draw(gl, 0.09f, System.Drawing.Color.Red);
                    bullet.Go();
                }
            }

            foreach (var tank in this.tankPlatoon)
            {
                if ((this.coordinateSystemSize < tank.Center.X) && (tank.RotationValue.Y > -180.0f))
                {
                    Point newRotationValue = tank.RotationValue;

                    tank.Step = new Point();

                    newRotationValue.Y -= 0.5f;
                    tank.RotationValue  = newRotationValue;
                }
                else if ((-this.coordinateSystemSize > tank.Center.X) && (tank.RotationValue.Y < 0.0f))
                {
                    Point newRotationValue = tank.RotationValue;

                    tank.Step = new Point();

                    newRotationValue.Y += 0.5f;
                    tank.RotationValue  = newRotationValue;
                }
                else
                {
                    if (tank.RotationValue.Y <= -180.0f)
                    {
                        tank.Step = new Point(-0.15f, 0.0f, 0.0f);
                    }
                    else if (tank.RotationValue.Y >= 0.0f)
                    {
                        tank.Step = new Point(0.15f, 0.0f, 0.0f);
                    }
                }

                tank.Go();
            }

            gl.Flush();

            gl.LoadIdentity();
        }