Esempio n. 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;
        }
        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;
        }