コード例 #1
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)
            {
                if (this.operationState == OperationState.PickingDraging)
                {
                    // move vertex
                    DragParam dragParam = this.dragParam;
                    if (dragParam != null && this.pickedGeometry != null)
                    {
                        var node = this.pickedGeometry.FromRenderer as PickableNode;
                        var currentWindowSpacePos  = new vec3(e.X, this.winGLCanvas1.Height - e.Y - 1, this.pickedGeometry.PickedPosition.z);
                        var currentModelSpacePos   = glm.unProject(currentWindowSpacePos, dragParam.viewMatrix * node.GetModelMatrix(), dragParam.projectionMatrix, dragParam.viewport);
                        var modelSpacePositionDiff = currentModelSpacePos - dragParam.lastModelSpacePos;
                        dragParam.lastModelSpacePos = currentModelSpacePos;
                        IList <vec3> newPositions = node.MovePositions(
                            modelSpacePositionDiff,
                            dragParam.pickedVertexIds);

                        this.UpdateHightlight(newPositions);
                    }
                }
            }
            else
            {
                int x = e.X;
                int y = this.winGLCanvas1.Height - e.Y - 1;
                this.pickedGeometry = this.pickingAction.Pick(x, y, true, true, false);

                if (this.pickedGeometry != null)
                {
                    var text = string.Format("picked: {0}", this.pickedGeometry.FromRenderer);
                    this.toolStripStatusLabel1.Text = text;
                    this.textNode.Text = text;
                }
                else
                {
                    var text = string.Format("picked: nothing");
                    this.toolStripStatusLabel1.Text = text;
                    this.textNode.Text = text;
                }

                this.UpdateHightlight();
            }

            this.lastMousePosition = e.Location;
        }
コード例 #2
0
        private void glCanvas1_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                //// operate camera
                //rotator.MouseUp(e.X, e.Y);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                // move vertex
                if (this.operationState == OperationState.PickingDraging)
                {
                    this.dragParam = null;
                }
            }

            this.lastMousePosition = e.Location;
        }
コード例 #3
0
        private void glCanvas1_MouseDown(object sender, MouseEventArgs e)
        {
            this.lastMousePosition = e.Location;

            if (this.operationState == OperationState.PickingDraging)
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Right)
                {
                    //// operate camera
                    //rotator.SetBounds(this.glCanvas1.Width, this.glCanvas1.Height);
                    //rotator.MouseDown(e.X, e.Y);
                }
                else if (e.Button == System.Windows.Forms.MouseButtons.Left)
                {
                    // move vertex
                    if (pickedGeometry != null)
                    {
                        Rectangle rect               = this.scene.Canvas.ClientRectangle;
                        var       viewport           = new vec4(rect.X, rect.Y, rect.Width, rect.Height);
                        var       lastWindowSpacePos = new vec3(e.X, this.winGLCanvas1.Height - e.Y - 1, pickedGeometry.PickedPosition.z);
                        mat4      projectionMatrix   = this.scene.Camera.GetProjectionMatrix();
                        mat4      viewMatrix         = this.scene.Camera.GetViewMatrix();
                        mat4      modelMatrix        = (pickedGeometry.FromRenderer as PickableNode).GetModelMatrix();
                        var       lastModelSpacePos  = glm.unProject(lastWindowSpacePos, viewMatrix * modelMatrix, projectionMatrix, viewport);

                        var dragParam = new DragParam(
                            lastModelSpacePos,
                            this.scene.Camera.GetProjectionMatrix(),
                            this.scene.Camera.GetViewMatrix(),
                            viewport,
                            new ivec2(e.X, this.winGLCanvas1.Height - e.Y - 1));
                        dragParam.pickedVertexIds.AddRange(pickedGeometry.VertexIds);
                        this.dragParam = dragParam;
                    }
                }
            }
        }