Beispiel #1
0
        private void Form_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(
                    new vec3(5, 3, 4), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                var scene = new Scene(camera, this.glCanvas1);
                scene.ClearColor       = Color.SkyBlue;
                this.glCanvas1.Resize += scene.Resize;
                this.scene             = scene;
                var cameraManipulater = new SatelliteManipulater();
                cameraManipulater.Bind(camera, this.glCanvas1);
                this.cameraManipulater = cameraManipulater;
            }
            {
                const int      gridsPer2Unit = 20;
                const int      scale         = 2;
                GroundRenderer renderer      = GroundRenderer.Create(new GroundModel(gridsPer2Unit * scale));
                renderer.Scale = new vec3(scale, scale, scale);
                SceneObject obj = renderer.WrapToSceneObject(generateBoundingBox: true);
                this.scene.RootObject.Children.Add(obj);
            }
            {
                var arcballManipulater = new ArcBallManipulater();
                arcballManipulater.Bind(this.scene.Camera, this.glCanvas1);
                SimpleRenderer renderer = SimpleRenderer.Create(new Teapot());
                SceneObject    obj      = renderer.WrapToSceneObject();
                obj.Scripts.Add(new ArcballScript(arcballManipulater));
                {
                    BoundingBoxRenderer box = renderer.GetBoundingBoxRenderer();
                    var boxObj = box.WrapToSceneObject();
                    boxObj.Scripts.Add(new ArcballScript(arcballManipulater));
                    obj.Children.Add(boxObj);
                }
                this.scene.RootObject.Children.Add(obj);
            }
            {
                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(128, 128));
                uiAxis.Initialize();

                this.scene.UIRoot.Children.Add(uiAxis);
            }
            {
                var builder = new StringBuilder();
                builder.AppendLine("1: Scene's property grid.");
                builder.AppendLine("2: Canvas' property grid.");
                builder.AppendLine("3: Form's property grid.");
                MessageBox.Show(builder.ToString());
            }
            {
                this.scene.Start();
            }
        }
        private void Form_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetValues(typeof(GeometryType)))
            {
                this.cmbPickingGeometryType.Items.Add(item);
            }
            foreach (var item in Enum.GetValues(typeof(RenderModes)))
            {
                this.cmbRenderMode.Items.Add(item);
            }
            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.bulletinBoard = frmBulletinBoard;
            }
            {
                //this.glCanvas1.ShowSystemCursor = false;
            }
            {
                var camera = new Camera(
                    new vec3(15, 5, 0), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                var rotator = new FirstPerspectiveManipulater();
                rotator.StepLength = 0.5f;
                rotator.Bind(camera, this.glCanvas1);
                var scene = new Scene(camera, this.glCanvas1);
                //scene.Cursor.Enabled = false;
                this.scene             = scene;
                this.glCanvas1.Resize += scene.Resize;
            }
            {
                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(128, 128));
                uiAxis.Initialize();
                this.scene.UIRoot.Children.Add(uiAxis);
            }
            {
                var font   = new Font("Courier New", 32);
                var uiText = new UIText(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(0, 0, 0, 0), new Size(250, 20), -100, 100,
                                        font.GetFontBitmap("[index: 0123456789]").GetFontTexture());
                uiText.Text = "";
                this.uiText = uiText;
                this.scene.UIRoot.Children.Add(uiText);
            }
            {
                GroundRenderer ground = GroundRenderer.Create(new GroundModel(20));
                ground.Initialize();
                ground.Scale         = new vec3(20, 20, 20);
                ground.WorldPosition = new vec3(0, 0, 0);
                SceneObject obj = ground.WrapToSceneObject(name: "Ground", generateBoundingBox: true);
                this.scene.RootObject.Children.Add(obj);
            }
            {
                bool useHighlightedPickingEffect = false;
                if (MessageBox.Show("Use highlighted picking effect?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    useHighlightedPickingEffect = true;
                }
                List <PickableRenderer> list     = GetPickableRenderers();
                const float             distance = 10;
                float sideCount  = (float)Math.Sqrt(list.Count);
                int   sideCounti = (int)sideCount;
                float x          = -sideCount * distance / 2;
                float z          = -sideCount * distance / 2;
                //float x = 0, z = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    PickableRenderer item = list[i];
                    SceneObject      obj;
                    if (useHighlightedPickingEffect)
                    {
                        var model             = item.Model;
                        var highlightRenderer = new HighlightRenderer(model, item.PositionNameInIBufferable);
                        var renderer          = new HighlightedPickableRenderer(
                            highlightRenderer, item);
                        renderer.WorldPosition = new vec3(x, 2, z);
                        renderer.Initialize();
                        obj = renderer.WrapToSceneObject(generateBoundingBox: true);
                    }
                    else
                    {
                        item.WorldPosition = new vec3(x, 2, z);
                        obj = item.WrapToSceneObject(generateBoundingBox: true);
                    }
                    this.scene.RootObject.Children.Add(obj);

                    x += distance;
                    if (i % sideCounti == sideCounti - 1)
                    {
                        z += distance; x = -sideCount * distance / 2;
                    }
                }
            }
            {
                this.glCanvas1.MouseDown += glCanvas1_MouseDown;
                this.glCanvas1.MouseMove += glCanvas1_MouseMove;
                this.glCanvas1.MouseUp   += glCanvas1_MouseUp;
            }
            {
                var builder = new StringBuilder();
                builder.AppendLine("1: Scene's property grid.");
                builder.AppendLine("2: Canvas' property grid.");
                builder.AppendLine("3: Form's property grid.");
                builder.AppendLine("4: Save to bitmap file.");
                MessageBox.Show(builder.ToString());
            }
        }