コード例 #1
0
        private void ConeColor_Click(object sender, EventArgs e)
        {
            ColorDialog dialog = new ColorDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                SelectedFigure.Color = dialog.Color;
                using (FastBitmap fast = ((Bitmap)ConeColor.Image).FastLock())
                {
                    fast.Clear(dialog.Color);
                }
                ConeColor.Refresh();
            }
        }
コード例 #2
0
        public Form1()
        {
            InitializeComponent();
            bitmap = new Bitmap(Canvas.Width, Canvas.Height);
            Render.Clear(bitmap);
            Canvas.Image = bitmap;
            //Figures.Add(new Cuboid() { Center = new Point4(3, 0, 3) });
            //Figures.Add(new Sphere() { Center = new Point4(-3, 0, -3) });
            //Figures.Add(new Cone() { Center = new Point4(-3, 0, 3) });
            //Figures.Add(new Cylinder() { Center = new Point4(3, 0, -3) });
            FigureDataGrid.DataSource = Figures;

            SelectedCamera = new Camera();
            Cameras.Add(SelectedCamera);
            CameraListBox.DataSource    = Cameras;
            CameraListBox.DisplayMember = "DisplayName";
            CameraListBox.SelectedIndex = 0;

            LightColor.Image = new Bitmap(LightColor.Width, LightColor.Height);
            LightColor.Refresh();

            SelectedLight = new Light();
            Lights.Add(SelectedLight);
            LightListBox.DataSource    = Lights;
            LightListBox.DisplayMember = "DisplayName";
            LightListBox.SelectedIndex = 0;

            RefreshTimer.Tick    += RefreshTimer_Tick;
            RefreshTimer.Interval = 8;
            RefreshTimer.Start();
            frametime = DateTime.Now;

            Render.ZBuffering      = zbufferingToolStripMenuItem.Checked;
            Render.FillTriangles   = fillTrianglesToolStripMenuItem.Checked;
            Render.BackfaceCulling = backfaceCullingToolStripMenuItem.Checked;

            CuboidColor.Image = new Bitmap(CuboidColor.Width, CuboidColor.Height);
            CuboidColor.Refresh();

            SphereColor.Image = new Bitmap(SphereColor.Width, SphereColor.Height);
            SphereColor.Refresh();

            CylinderColor.Image = new Bitmap(CylinderColor.Width, CylinderColor.Height);
            CylinderColor.Refresh();

            ConeColor.Image = new Bitmap(ConeColor.Width, ConeColor.Height);
            ConeColor.Refresh();
        }
コード例 #3
0
        private void FigureDataGrid_SelectionChanged(object sender, EventArgs e)
        {
            CuboidGroupBox.Visible   = false;
            SphereGroupBox.Visible   = false;
            CylinderGroupBox.Visible = false;
            ConeGroupBox.Visible     = false;
            if (FigureDataGrid.SelectedRows.Count != 0)
            {
                SelectedFigure = (IFigure)FigureDataGrid.SelectedRows[0].DataBoundItem;
                if (SelectedFigure is Cuboid)
                {
                    Cuboid cube = SelectedFigure as Cuboid;
                    CuboidGroupBox.Visible = true;
                    CuboidPosX.Value       = (decimal)cube.Center.X;
                    CuboidPosY.Value       = (decimal)cube.Center.Y;
                    CuboidPosZ.Value       = (decimal)cube.Center.Z;

                    CuboidDimX.Value = (decimal)cube.DimX;
                    CuboidDimY.Value = (decimal)cube.DimY;
                    CuboidDimZ.Value = (decimal)cube.DimZ;

                    CuboidRotX.Value = (decimal)(cube.RotX * 180f / Math.PI);
                    CuboidRotY.Value = (decimal)(cube.RotY * 180f / Math.PI);
                    CuboidRotZ.Value = (decimal)(cube.RotZ * 180f / Math.PI);

                    CuboidX.Value = (decimal)cube.X;
                    CuboidY.Value = (decimal)cube.Y;
                    CuboidZ.Value = (decimal)cube.Z;

                    using (FastBitmap fast = ((Bitmap)CuboidColor.Image).FastLock())
                    {
                        fast.Clear(cube.Color);
                    }
                    CuboidColor.Refresh();
                }
                else if (SelectedFigure is Sphere)
                {
                    SphereGroupBox.Visible = true;
                    Sphere sphere = SelectedFigure as Sphere;
                    SpherePosX.Value = (decimal)sphere.Center.X;
                    SpherePosY.Value = (decimal)sphere.Center.Y;
                    SpherePosZ.Value = (decimal)sphere.Center.Z;

                    SphereDimX.Value = (decimal)sphere.DimX;
                    SphereDimY.Value = (decimal)sphere.DimY;
                    SphereDimZ.Value = (decimal)sphere.DimZ;

                    SphereRotX.Value = (decimal)(sphere.RotX * 180f / Math.PI);
                    SphereRotY.Value = (decimal)(sphere.RotY * 180f / Math.PI);
                    SphereRotZ.Value = (decimal)(sphere.RotZ * 180f / Math.PI);

                    SphereLat.Value    = (decimal)sphere.Lat;
                    SphereLon.Value    = (decimal)sphere.Lon;
                    SphereRadius.Value = (decimal)sphere.Radius;

                    using (FastBitmap fast = ((Bitmap)SphereColor.Image).FastLock())
                    {
                        fast.Clear(sphere.Color);
                    }
                    SphereColor.Refresh();
                }
                else if (SelectedFigure is Cylinder)
                {
                    CylinderGroupBox.Visible = true;
                    Cylinder cylinder = SelectedFigure as Cylinder;
                    CylinderPosX.Value = (decimal)cylinder.Center.X;
                    CylinderPosY.Value = (decimal)cylinder.Center.Y;
                    CylinderPosZ.Value = (decimal)cylinder.Center.Z;

                    CylinderDimX.Value = (decimal)cylinder.DimX;
                    CylinderDimY.Value = (decimal)cylinder.DimY;
                    CylinderDimZ.Value = (decimal)cylinder.DimZ;

                    CylinderRotX.Value = (decimal)(cylinder.RotX * 180f / Math.PI);
                    CylinderRotY.Value = (decimal)(cylinder.RotY * 180f / Math.PI);
                    CylinderRotZ.Value = (decimal)(cylinder.RotZ * 180f / Math.PI);

                    CylinderDiv.Value    = (decimal)cylinder.Division;
                    CylinderHeight.Value = (decimal)cylinder.Height;
                    CylinderRadius.Value = (decimal)cylinder.Radius;

                    using (FastBitmap fast = ((Bitmap)CylinderColor.Image).FastLock())
                    {
                        fast.Clear(cylinder.Color);
                    }
                    CylinderColor.Refresh();
                }
                else if (SelectedFigure is Cone)
                {
                    ConeGroupBox.Visible = true;
                    Cone cone = SelectedFigure as Cone;
                    ConePosX.Value = (decimal)cone.Center.X;
                    ConePosY.Value = (decimal)cone.Center.Y;
                    ConePosZ.Value = (decimal)cone.Center.Z;

                    ConeDimX.Value = (decimal)cone.DimX;
                    ConeDimY.Value = (decimal)cone.DimY;
                    ConeDimZ.Value = (decimal)cone.DimZ;

                    ConeRotX.Value = (decimal)(cone.RotX * 180f / Math.PI);
                    ConeRotY.Value = (decimal)(cone.RotY * 180f / Math.PI);
                    ConeRotZ.Value = (decimal)(cone.RotZ * 180f / Math.PI);

                    ConeDiv.Value    = (decimal)cone.Division;
                    ConeHeight.Value = (decimal)cone.Height;
                    ConeRadius.Value = (decimal)cone.Radius;

                    using (FastBitmap fast = ((Bitmap)ConeColor.Image).FastLock())
                    {
                        fast.Clear(cone.Color);
                    }
                    ConeColor.Refresh();
                }
            }
        }