Inheritance: System.Windows.Forms.Form
コード例 #1
0
        private void ControlDown(MouseEventArgs e)
        {
            List <Tuple <Point, PickedGeometry> > allPickedGeometrys = this.scene.Pick(
                e.Location, this.PickingGeometryType);
            PickedGeometry pickedGeometry = null;

            if (allPickedGeometrys != null && allPickedGeometrys.Count > 0)
            {
                pickedGeometry = allPickedGeometrys[0].Item2;
            }

            if (pickedGeometry != null)
            {
                PickableRenderer pickableRenderer = null;
                var renderer = pickedGeometry.FromRenderer as HighlightedPickableRenderer;
                if (renderer != null)
                {
                    renderer.Highlighter.SetHighlightIndexes(
                        this.PickingGeometryType.ToDrawMode(), pickedGeometry.VertexIds);
                    this.highlightedRenderer = renderer;
                    pickableRenderer         = renderer.PickableRenderer;
                }
                else
                {
                    pickableRenderer = pickedGeometry.FromRenderer as PickableRenderer;
                }

                FormBulletinBoard bulletinBoard = this.bulletinBoard;
                if ((bulletinBoard != null) && (!bulletinBoard.IsDisposed))
                {
                    ICamera camera     = this.scene.FirstCamera;
                    mat4    projection = camera.GetProjectionMatrix();
                    mat4    view       = camera.GetViewMatrix();
                    mat4    model      = pickableRenderer.GetModelMatrix().Value;
                    this.bulletinBoard.SetContent(pickedGeometry.ToString(
                                                      projection, view, model));
                }

                this.glCanvas1.Cursor = Cursors.Hand;
            }
            else
            {
                HighlightedPickableRenderer renderer = this.highlightedRenderer;
                if (renderer != null)
                {
                    renderer.Highlighter.ClearHighlightIndexes();
                }
                this.bulletinBoard.SetContent("picked nothing.");

                this.glCanvas1.Cursor = Cursors.Default;
            }
            this.pickedGeometry = pickedGeometry;
        }
コード例 #2
0
 private void Form01ModernRenderer_Load(object sender, EventArgs e)
 {
     {
         var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
         camera.Position = new vec3(0, 0, 5);
         var rotator = new SatelliteRotator(camera);
         this.camera  = camera;
         this.rotator = rotator;
     }
     {
         IBufferable  bufferable = new BigDipperAdapter(new BigDipper());
         ShaderCode[] shaders    = new ShaderCode[2];
         shaders[0] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.vert"), ShaderType.VertexShader);
         shaders[1] = new ShaderCode(File.ReadAllText(@"Shaders\BigDipper.frag"), ShaderType.FragmentShader);
         var propertyNameMap = new PropertyNameMap();
         propertyNameMap.Add("in_Position", "position");
         propertyNameMap.Add("in_Color", "color");
         var renderer = new ModernRenderer(bufferable, shaders, propertyNameMap, "position");
         renderer.Initialize();
         GLSwitch lineWidthSwitch = new LineWidthSwitch(10.0f);
         renderer.SwitchList.Add(lineWidthSwitch);
         GLSwitch pointSizeSwitch = new PointSizeSwitch(10.0f);
         renderer.SwitchList.Add(pointSizeSwitch);
         this.renderer = renderer;
     }
     {
         var frmBulletinBoard = new FormBulletinBoard();
         frmBulletinBoard.Dump = true;
         frmBulletinBoard.Show();
         this.bulletinBoard = frmBulletinBoard;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.renderer);
         frmPropertyGrid.Show();
         this.rendererPropertyGrid = frmPropertyGrid;
     }
     {
         var frmPropertyGrid = new FormProperyGrid();
         frmPropertyGrid.DisplayObject(this.camera);
         frmPropertyGrid.Show();
         this.cameraPropertyGrid = frmPropertyGrid;
     }
 }
コード例 #3
0
        private void glCanvas1_MouseMove(object sender, MouseEventArgs e)
        {
            if (lastMousePosition == e.Location)
            {
                return;
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.MouseMove(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex
                DragParam dragParam = this.dragParam;
                if (dragParam != null)
                {
                    var   current            = new Point(e.X, glCanvas1.Height - e.Y - 1);
                    Point differenceOnScreen = new Point(
                        current.X - dragParam.lastMousePositionOnScreen.X,
                        current.Y - dragParam.lastMousePositionOnScreen.Y);
                    dragParam.lastMousePositionOnScreen = current;
                    PickableRenderer renderer = null;
                    {
                        var tmp = this.pickedGeometry.From as HighlightedPickableRenderer;
                        if (tmp != null)
                        {
                            renderer = tmp.PickableRenderer;
                        }
                    }

                    if (renderer == null)
                    {
                        renderer = this.pickedGeometry.From as PickableRenderer;
                    }

                    renderer.MovePositions(
                        differenceOnScreen,
                        dragParam.viewMatrix, dragParam.projectionMatrix,
                        dragParam.viewport,
                        dragParam.pickedVertexIds);
                }
            }
            else
            {
                UpdateColorInformationAtMouse(e.X, e.Y);

                PickedGeometry pickedGeometry = this.scene.ColorCodedPicking(
                    e.Location, this.PickingGeometryType);
                if (pickedGeometry != null)
                {
                    PickableRenderer pickableRenderer = null;
                    var renderer = pickedGeometry.From as HighlightedPickableRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.SetHighlightIndexes(
                            this.PickingGeometryType.ToDrawMode(), pickedGeometry.VertexIds);
                        this.highlightedRenderer = renderer;
                        pickableRenderer         = renderer.PickableRenderer;
                    }
                    else
                    {
                        pickableRenderer = pickedGeometry.From as PickableRenderer;
                    }

                    FormBulletinBoard bulletinBoard = this.bulletinBoard;
                    if ((bulletinBoard != null) && (!bulletinBoard.IsDisposed))
                    {
                        ICamera camera     = this.scene.Camera;
                        mat4    projection = camera.GetProjectionMatrix();
                        mat4    view       = camera.GetViewMatrix();
                        mat4    model      = pickableRenderer.GetModelMatrix();
                        this.bulletinBoard.SetContent(pickedGeometry.ToString(
                                                          projection, view, model));
                    }

                    this.glCanvas1.Cursor = Cursors.Hand;
                }
                else
                {
                    HighlightedPickableRenderer renderer = this.highlightedRenderer;
                    if (renderer != null)
                    {
                        renderer.Highlighter.ClearHighlightIndexes();
                    }
                    this.bulletinBoard.SetContent("picked nothing.");

                    this.glCanvas1.Cursor = Cursors.Default;
                }
                this.pickedGeometry = pickedGeometry;
            }

            this.lastMousePosition = e.Location;
        }
コード例 #4
0
        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());
            }
        }
コード例 #5
0
        private void Form01Renderer_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                camera.Position = new vec3(0, 0, 5);
                var rotator = new SatelliteRotator(camera);
                this.camera  = camera;
                this.rotator = rotator;
            }
            {
                // build several models
                Random random      = new Random();
                var    bufferables = new IBufferable[] {
                    new Axis(),
                    new BigDipper(),
                    new Chain(new ChainModel(random.Next(7, 100), 5, 5)),
                    new Tetrahedron(),
                    new Cube(),
                    new Sphere(),
                    new Teapot(),
                };
                var keys = new GeometryModel[]
                {
                    GeometryModel.Axis,
                    GeometryModel.BigDipper,
                    GeometryModel.Chain,
                    GeometryModel.Tetrahedron,
                    GeometryModel.Cube,
                    GeometryModel.Sphere,
                    GeometryModel.Teapot,
                };
                ShaderCode[] simpleShader = new ShaderCode[2];
                simpleShader[0] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.vert"), ShaderType.VertexShader);
                simpleShader[1] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.frag"), ShaderType.FragmentShader);
                ShaderCode[] emitNormalLineShader = new ShaderCode[3];
                emitNormalLineShader[0] = new ShaderCode(File.ReadAllText(@"01Renderer\EmitNormalLine.vert"), ShaderType.VertexShader);
                emitNormalLineShader[1] = new ShaderCode(File.ReadAllText(@"01Renderer\EmitNormalLine.geom"), ShaderType.GeometryShader);
                emitNormalLineShader[2] = new ShaderCode(File.ReadAllText(@"01Renderer\EmitNormalLine.frag"), ShaderType.FragmentShader);
                var shaderCodesGroup = new ShaderCode[][]
                {
                    simpleShader,
                    simpleShader,
                    simpleShader,
                    emitNormalLineShader,
                    emitNormalLineShader,
                    emitNormalLineShader,
                    emitNormalLineShader,
                };
                var simpleShaderPropertyNameMap = new PropertyNameMap();
                simpleShaderPropertyNameMap.Add("in_Position", "position");
                simpleShaderPropertyNameMap.Add("in_Color", "color");
                var emitNormalLineShaderPropertyNameMap = new PropertyNameMap();
                emitNormalLineShaderPropertyNameMap.Add("in_Position", "position");
                emitNormalLineShaderPropertyNameMap.Add("in_Normal", "normal");
                var propertyNameMaps = new PropertyNameMap[]
                {
                    simpleShaderPropertyNameMap,
                    simpleShaderPropertyNameMap,
                    simpleShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                };
                var positionNameInIBufferables = new string[]
                {
                    "position",
                    "position",
                    "position",
                    "position",
                    "position",
                    "position",
                    "position",
                };
                var uniformTupleList = new List <Tuple <string, ValueType> >()
                {
                    new Tuple <string, ValueType>("normalLength", 0.5f),
                    new Tuple <string, ValueType>("showModel", true),
                    new Tuple <string, ValueType>("showNormal", false),
                };
                var uniformVariablesList = new List <List <Tuple <string, ValueType> > >()
                {
                    new List <Tuple <string, ValueType> >(),
                    new List <Tuple <string, ValueType> >(),
                    new List <Tuple <string, ValueType> >(),
                    uniformTupleList,
                    uniformTupleList,
                    uniformTupleList,
                    uniformTupleList,
                };
                for (int i = 0; i < bufferables.Length; i++)
                {
                    GeometryModel key                       = keys[i];
                    IBufferable   bufferable                = bufferables[i];
                    ShaderCode[]  shaders                   = shaderCodesGroup[i];
                    var           propertyNameMap           = propertyNameMaps[i];
                    string        positionNameInIBufferable = positionNameInIBufferables[i];
                    var           highlightRenderer         = new HighlightRenderer(
                        bufferable, positionNameInIBufferable);
                    highlightRenderer.Name = string.Format("Highlight: [{0}]", key);
                    highlightRenderer.Initialize();
                    var pickableRenderer = new PickableRenderer(
                        bufferable, shaders, propertyNameMap, positionNameInIBufferable);
                    pickableRenderer.Name = string.Format("Pickable: [{0}]", key);
                    pickableRenderer.Initialize();
                    var uniformVariables = uniformVariablesList[i];
                    foreach (var item in uniformVariables)
                    {
                        pickableRenderer.SetUniform(item.Item1, item.Item2);
                    }

                    HighlightedPickableRenderer renderer = new HighlightedPickableRenderer(
                        highlightRenderer, pickableRenderer);
                    renderer.Initialize();
                    {
                        GLSwitch lineWidthSwitch = new LineWidthSwitch(5);
                        pickableRenderer.SwitchList.Add(lineWidthSwitch);
                        GLSwitch pointSizeSwitch = new PointSizeSwitch(10);
                        pickableRenderer.SwitchList.Add(pointSizeSwitch);
                        GLSwitch polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled);
                        pickableRenderer.SwitchList.Add(polygonModeSwitch);
                        //GLSwitch blendSwitch = new BlendSwitch();
                        //pickableRenderer.SwitchList.Add(blendSwitch);
                    }
                    this.rendererDict.Add(key, renderer);
                }
                this.SelectedModel = GeometryModel.Tetrahedron;
            }
            {
                // build the axis
                var bufferables = new IBufferable[] {
                    new Axis(),
                };
                var keys = new GeometryModel[]
                {
                    GeometryModel.Axis,
                };
                ShaderCode[] simpleShader = new ShaderCode[2];
                simpleShader[0] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.vert"), ShaderType.VertexShader);
                simpleShader[1] = new ShaderCode(File.ReadAllText(@"01Renderer\Simple.frag"), ShaderType.FragmentShader);
                var shaderCodesGroup = new ShaderCode[][]
                {
                    simpleShader,
                };
                var simpleShaderPropertyNameMap = new PropertyNameMap();
                simpleShaderPropertyNameMap.Add("in_Position", "position");
                simpleShaderPropertyNameMap.Add("in_Color", "color");
                var propertyNameMaps = new PropertyNameMap[]
                {
                    simpleShaderPropertyNameMap,
                };
                var positionNameInIBufferables = new string[]
                {
                    "position",
                };
                var uniformVariablesList = new List <List <Tuple <string, ValueType> > >()
                {
                    new List <Tuple <string, ValueType> >(),
                };
                for (int i = 0; i < bufferables.Length; i++)
                {
                    GeometryModel key                       = keys[i];
                    IBufferable   bufferable                = bufferables[i];
                    ShaderCode[]  shaders                   = shaderCodesGroup[i];
                    var           propertyNameMap           = propertyNameMaps[i];
                    string        positionNameInIBufferable = positionNameInIBufferables[i];
                    var           pickableRenderer          = new PickableRenderer(
                        bufferable, shaders, propertyNameMap, positionNameInIBufferable);
                    pickableRenderer.Name = string.Format("Pickable: [{0}]", key);
                    pickableRenderer.Initialize();
                    var uniformVariables = uniformVariablesList[i];
                    foreach (var item in uniformVariables)
                    {
                        pickableRenderer.SetUniform(item.Item1, item.Item2);
                    }
                }
            }
            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.pickedGeometryBoard = frmBulletinBoard;
            }
            {
                var UIRoot = new GLControl(this.glCanvas1.Size, -100, 100);
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var glAxis = new GLAxis(AnchorStyles.Right | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(70, 70), -100, 100);
                glAxis.Initialize();
                this.glAxis = glAxis;

                UIRoot.Controls.Add(glAxis);
            }
            {
                var frmPropertyGrid = new FormProperyGrid();
                frmPropertyGrid.DisplayObject(this.rendererDict[this.SelectedModel].PickableRenderer);
                frmPropertyGrid.Show();
                this.pickableRendererPropertyGrid = frmPropertyGrid;
            }
            {
                var frmPropertyGrid = new FormProperyGrid();
                frmPropertyGrid.DisplayObject(this.rendererDict[this.SelectedModel].Highlighter);
                frmPropertyGrid.Show();
                this.highlightRendererPropertyGrid = frmPropertyGrid;
            }
            {
                var frmPropertyGrid = new FormProperyGrid();
                frmPropertyGrid.DisplayObject(this);
                frmPropertyGrid.Show();
                this.formPropertyGrid = frmPropertyGrid;
            }
            {
                var frmIndexBufferPtrBoard = new FormIndexBufferPtrBoard();
                frmIndexBufferPtrBoard.SetTarget(this.rendererDict[this.SelectedModel].PickableRenderer.IndexBufferPtr);
                frmIndexBufferPtrBoard.Show();
                this.frmIndexBufferPtrBoard = frmIndexBufferPtrBoard;
            }
        }
コード例 #6
0
        private void Form_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetValues(typeof(PickingGeometryType)))
            {
                this.cmbPickingGeometryType.Items.Add(item);
            }
            this.cmbPickingGeometryType.SelectedIndex = 1;

            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.bulletinBoard = frmBulletinBoard;
            }
            {
                //this.glCanvas1.ShowSystemCursor = false;
            }
            {
                // default(perspective)
                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;
                ViewPort rootViewPort = scene.RootViewPort;
                rootViewPort.ClearColor = Color.White;
                ViewPort viewPort = rootViewPort.Children[0];
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += perspectiveViewPort_AfterLayout;
                this.glCanvas1.Resize += scene.Resize;
            }
            {
                // top
                var camera = new Camera(
                new vec3(0, 0, 25), new vec3(0, 0, 0), new vec3(0, 1, 0),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += topViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                // front
                var camera = new Camera(
                new vec3(0, 25, 0), new vec3(0, 0, 0), new vec3(0, 0, -1),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += frontViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                // left
                var camera = new Camera(
                new vec3(-25, 0, 0), new vec3(0, 0, 0), new vec3(0, 0, -1),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += leftViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
              new Padding(3, 3, 3, 3), new Size(128, 128));
                uiAxis.Initialize();
                this.scene.RootUI.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.RootUI.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.DataSource;
                        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.");
                builder.AppendLine("Ctrl+Mouse: Picking.");
                MessageBox.Show(builder.ToString());
            }
        }
コード例 #7
0
        private void Form_Load(object sender, EventArgs e)
        {
            {
                var camera = new Camera(
                    new vec3(0, 0, 5), new vec3(), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                var rotator = new SatelliteManipulater();
                rotator.Bind(camera, this.glCanvas1);
                this.camera = camera;
            }
            {
                // build several models
                Random random      = new Random();
                var    bufferables = new IBufferable[] {
                    new Axis(),
                    new BigDipper(),
                    new Chain(new ChainModel(random.Next(7, 100), 5, 5)),
                    new Tetrahedron(),
                    new Cube(),
                    new Sphere(),
                    new Teapot(),
                };
                var keys = new GeometryModel[]
                {
                    GeometryModel.Axis,
                    GeometryModel.BigDipper,
                    GeometryModel.Chain,
                    GeometryModel.Tetrahedron,
                    GeometryModel.Cube,
                    GeometryModel.Sphere,
                    GeometryModel.Teapot,
                };
                ShaderCode[] simpleShader = new ShaderCode[2];
                simpleShader[0] = new ShaderCode(File.ReadAllText(@"shaders\Simple.vert"), ShaderType.VertexShader);
                simpleShader[1] = new ShaderCode(File.ReadAllText(@"shaders\Simple.frag"), ShaderType.FragmentShader);
                ShaderCode[] emitNormalLineShader = new ShaderCode[3];
                emitNormalLineShader[0] = new ShaderCode(File.ReadAllText(@"shaders\EmitNormalLine.vert"), ShaderType.VertexShader);
                emitNormalLineShader[1] = new ShaderCode(File.ReadAllText(@"shaders\EmitNormalLine.geom"), ShaderType.GeometryShader);
                emitNormalLineShader[2] = new ShaderCode(File.ReadAllText(@"shaders\EmitNormalLine.frag"), ShaderType.FragmentShader);
                var shaderCodesGroup = new ShaderCode[][]
                {
                    simpleShader,
                    simpleShader,
                    simpleShader,
                    emitNormalLineShader,
                    emitNormalLineShader,
                    emitNormalLineShader,
                    emitNormalLineShader,
                };
                var simpleShaderPropertyNameMap = new PropertyNameMap();
                simpleShaderPropertyNameMap.Add("in_Position", "position");
                simpleShaderPropertyNameMap.Add("in_Color", "color");
                var emitNormalLineShaderPropertyNameMap = new PropertyNameMap();
                emitNormalLineShaderPropertyNameMap.Add("in_Position", "position");
                emitNormalLineShaderPropertyNameMap.Add("in_Normal", "normal");
                var propertyNameMaps = new PropertyNameMap[]
                {
                    simpleShaderPropertyNameMap,
                    simpleShaderPropertyNameMap,
                    simpleShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                    emitNormalLineShaderPropertyNameMap,
                };
                var positionNameInIBufferables = new string[]
                {
                    "position",
                    "position",
                    "position",
                    "position",
                    "position",
                    "position",
                    "position",
                };
                for (int i = 0; i < bufferables.Length; i++)
                {
                    GeometryModel key                       = keys[i];
                    IBufferable   bufferable                = bufferables[i];
                    ShaderCode[]  shaders                   = shaderCodesGroup[i];
                    var           propertyNameMap           = propertyNameMaps[i];
                    string        positionNameInIBufferable = positionNameInIBufferables[i];
                    var           highlightRenderer         = new HighlightRenderer(
                        bufferable, positionNameInIBufferable);
                    highlightRenderer.Name = string.Format("Highlight: [{0}]", key);
                    highlightRenderer.Initialize();
                    var pickableRenderer = new PickableRenderer(
                        bufferable, shaders, propertyNameMap, positionNameInIBufferable);
                    pickableRenderer.Name = string.Format("Pickable: [{0}]", key);
                    pickableRenderer.Initialize();
                    if (i > 2)
                    {
                        pickableRenderer.SetUniform("normalLength", 0.5f);
                        pickableRenderer.SetUniform("showModel", true);
                        pickableRenderer.SetUniform("showNormal", false);
                    }

                    HighlightedPickableRenderer renderer = new HighlightedPickableRenderer(
                        highlightRenderer, pickableRenderer);
                    renderer.Initialize();
                    {
                        GLSwitch lineWidthSwitch = new LineWidthSwitch(5);
                        pickableRenderer.SwitchList.Add(lineWidthSwitch);
                        GLSwitch pointSizeSwitch = new PointSizeSwitch(10);
                        pickableRenderer.SwitchList.Add(pointSizeSwitch);
                        GLSwitch polygonModeSwitch = new PolygonModeSwitch(PolygonModes.Filled);
                        pickableRenderer.SwitchList.Add(polygonModeSwitch);
                        //GLSwitch blendSwitch = new BlendSwitch();
                        //pickableRenderer.SwitchList.Add(blendSwitch);
                    }
                    this.rendererDict.Add(key, renderer);
                }
                this.SelectedModel = GeometryModel.Tetrahedron;
            }
            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.pickedGeometryBoard = frmBulletinBoard;
            }
            {
                var UIRoot = new UIRoot();
                UIRoot.Initialize();
                this.uiRoot = UIRoot;

                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(128, 128), -100, 100);
                uiAxis.Initialize();
                UIRoot.Children.Add(uiAxis);
                this.uiAxis = 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 = "";
                uiRoot.Children.Add(uiText);
                this.uiText = uiText;
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.rendererDict[this.SelectedModel].PickableRenderer);
                frmPropertyGrid.Show();
                this.pickableRendererPropertyGrid = frmPropertyGrid;
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.rendererDict[this.SelectedModel].Highlighter);
                frmPropertyGrid.Show();
                this.highlightRendererPropertyGrid = frmPropertyGrid;
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this);
                frmPropertyGrid.Show();
                this.formPropertyGrid = frmPropertyGrid;
            }
            {
                var frmPropertyGrid = new FormProperyGrid(this.uiText);
                frmPropertyGrid.Show();
            }
            {
                var frmIndexBufferPtrBoard = new FormIndexBufferPtrBoard();
                frmIndexBufferPtrBoard.SetTarget(this.rendererDict[this.SelectedModel].PickableRenderer.IndexBufferPtr);
                frmIndexBufferPtrBoard.Show();
                this.frmIndexBufferPtrBoard = frmIndexBufferPtrBoard;
            }
        }