void IMouseHandler.canvas_MouseUp(object sender, GLMouseEventArgs e)
 {
     if ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None)
     {
         this.mouseDownFlag = false;
     }
 }
Beispiel #2
0
        void IMouseHandler.canvas_MouseDown(object sender, GLMouseEventArgs e)
        {
            this.lastBindingMouseButtons = this.BindingMouseButtons;
            if ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None)
            {
                var control = sender as Control;
                this.SetBounds(control.Width, control.Height);

                if (!cameraState.IsSameState(this.camera))
                {
                    SetCamera(this.camera.Position, this.camera.Target, this.camera.UpVector);
                }

                this._startPosition = GetArcBallPosition(e.X, e.Y);

                mouseDownFlag = true;

                {
                    var mouseDown = this.MouseDown;
                    if (mouseDown != null)
                    {
                        mouseDown(this, e);
                    }
                }
            }
        }
        void IMouseHandler.canvas_MouseMove(object sender, GLMouseEventArgs e)
        {
            if (mouseDownFlag && ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None))
            {
                if (!cameraState.IsSameState(this.camera))
                {
                    SetCamera(this.camera.Position, this.camera.Target, this.camera.UpVector);
                }

                this._endPosition = GetArcBallPosition(e.X, e.Y);
                var cosRadian = _startPosition.dot(_endPosition) / (_startPosition.length() * _endPosition.length());
                if (cosRadian > 1.0f)
                {
                    cosRadian = 1.0f;
                }
                else if (cosRadian < -1)
                {
                    cosRadian = -1.0f;
                }
                float angle = MouseSensitivity * (float)(Math.Acos(cosRadian) / Math.PI * 180);
                _normalVector = _startPosition.cross(_endPosition).normalize();
                if (!
                    ((_normalVector.x == 0 && _normalVector.y == 0 && _normalVector.z == 0) ||
                     float.IsNaN(_normalVector.x) || float.IsNaN(_normalVector.y) || float.IsNaN(_normalVector.z)))
                {
                    _startPosition = _endPosition;

                    mat4 newRotation = glm.rotate(angle, _normalVector);
                    this.totalRotation = newRotation * totalRotation;
                }
            }
        }
Beispiel #4
0
        void IMouseHandler.canvas_MouseMove(object sender, GLMouseEventArgs e)
        {
            if (mouseDownFlag && ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None))
            {
                if (!cameraState.IsSameState(this.camera))
                {
                    SetCamera(this.camera.Position, this.camera.Target, this.camera.UpVector);
                }

                Point location           = new Point(e.X, this.canvas.Height - e.Y - 1);
                Point differenceOnScreen = new Point(location.X - this._lastPosition.X, location.Y - this._lastPosition.Y);
                mat4  model      = this.renderer.GetModelMatrix();
                mat4  view       = this.camera.GetViewMatrix();
                mat4  projection = this.camera.GetProjectionMatrix();
                vec4  viewport;
                {
                    var result = new int[4];
                    GL.Instance.GetIntegerv((uint)GetTarget.Viewport, result);
                    viewport = new vec4(result[0], result[1], result[2], result[3]);
                }
                var  position         = new vec3(0.0f);// imangine we have a point at (0, 0, 0).
                vec3 windowPos        = glm.project(position, view * model, projection, viewport);
                var  newWindowPos     = new vec3(windowPos.x + differenceOnScreen.X, windowPos.y + differenceOnScreen.Y, windowPos.z);
                vec3 newPosition      = glm.unProject(newWindowPos, view * model, projection, viewport);
                var  worldPosition    = new vec3(model * new vec4(position, 1.0f));
                var  newWorldPosition = new vec3(model * new vec4(newPosition, 1.0f));
                this.renderer.WorldPosition += newWorldPosition - worldPosition;

                this._lastPosition = location;
            }
        }
        void IMouseHandler.canvas_MouseMove(object sender, GLMouseEventArgs e)
        {
            if (this.mouseDownFlag &&
                ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None) &&
                (e.X != lastPosition.x || e.Y != lastPosition.y))
            {
                IViewCamera camera = this.camera;
                if (camera == null)
                {
                    return;
                }

                vec3    back         = this.back;
                vec3    right        = this.right;
                vec3    up           = this.up;
                GUISize bound        = this.bound;
                ivec2   downPosition = this.lastPosition;
                {
                    float deltaX  = -this.HorizontalRotationFactor * (e.X - downPosition.x) / (float)bound.Width;
                    float cos     = (float)Math.Cos(deltaX);
                    float sin     = (float)Math.Sin(deltaX);
                    vec3  newBack = new vec3(
                        back.x * cos + right.x * sin,
                        back.y * cos + right.y * sin,
                        back.z * cos + right.z * sin);
                    back  = newBack;
                    right = up.cross(back);
                    back  = back.normalize();
                    right = right.normalize();
                }
                {
                    float deltaY  = this.VerticalRotationFactor * (e.Y - downPosition.y) / (float)bound.Height;
                    float cos     = (float)Math.Cos(deltaY);
                    float sin     = (float)Math.Sin(deltaY);
                    vec3  newBack = new vec3(
                        back.x * cos - up.x * sin,
                        back.y * cos - up.y * sin,
                        back.z * cos - up.z * sin);
                    back = newBack;
                    up   = back.cross(right);
                    back = back.normalize();
                    up   = up.normalize();
                }

                //camera.Position = camera.Target +
                //    back * (float)((camera.Position - camera.Target).length());
                rootNode.RotationAxis = up;
                camera.UpVector       = up;
                this.back             = back;
                this.right            = right;
                this.up           = up;
                this.lastPosition = e.Location;

                IGLCanvas canvas = this.canvas;
                if (canvas != null && canvas.RenderTrigger == RenderTrigger.Manual)
                {
                    canvas.Repaint();
                }
            }
        }
Beispiel #6
0
 void CtrlButton_MouseUp(object sender, GLMouseEventArgs e)
 {
     if (e.Button == GLMouseButtons.Left)
     {
         this.Location = this.originalLocation;
         this.Size     = this.originalSize;
     }
 }
Beispiel #7
0
 void winCanvas_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (this.currentControl != null)
     {
         GLMouseEventArgs args = e.Translate();
         this.currentControl.InvokeEvent(EventType.MouseUp, args);
     }
 }
 void IMouseHandler.canvas_MouseDown(object sender, GLMouseEventArgs e)
 {
     this.lastBindingMouseButtons = this.BindingMouseButtons;
     if ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None)
     {
         this.mouseDownFlag = true;
         this.lastPosition  = e.Location;
     }
 }
Beispiel #9
0
        void winCanvas_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            GLMouseEventArgs args = e.Translate();

            foreach (var item in this.Children)
            {
                item.InvokeEvent(EventType.MouseMove, args);
            }
        }
        void WinGLCanvas_MouseUp(object sender, MouseEventArgs e)
        {
            GLEventHandler <GLMouseEventArgs> MouseUp = this.glMouseUp;

            if (MouseUp != null)
            {
                GLMouseEventArgs arg = e.Translate();
                MouseUp(sender, arg);
            }
        }
        void WinSoftGLCanvas_MouseMove(object sender, MouseEventArgs e)
        {
            GLEventHandler <GLMouseEventArgs> MouseMove = this.glMouseMove;

            if (MouseMove != null)
            {
                GLMouseEventArgs arg = e.Translate();
                MouseMove(sender, arg);
            }
        }
        void IMouseHandler.canvas_MouseWheel(object sender, GLMouseEventArgs e)
        {
            this.camera.MouseWheel(e.Delta);

            IGLCanvas canvas = this.canvas;

            if (canvas != null && canvas.RenderTrigger == RenderTrigger.Manual)
            {
                canvas.Repaint();
            }
        }
Beispiel #13
0
 void CtrlButton_MouseDown(object sender, GLMouseEventArgs e)
 {
     if (e.Button == GLMouseButtons.Left)
     {
         this.originalLocation = this.Location;
         this.originalSize     = this.Size;
         this.Size             = new GUISize((int)(this.Width * 0.9f), (int)(this.Height * 0.9f));
         this.Location         = new GUIPoint(
             (int)(this.Location.X + this.Width * 0.05f),
             (int)(this.Location.Y + this.Height * 0.05f));
     }
 }
 void IMouseHandler.canvas_MouseDown(object sender, GLMouseEventArgs e)
 {
     this.lastBindingMouseButtons = this.BindingMouseButtons;
     if ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None)
     {
         this.lastPosition = e.Location;
         var control = sender as Control;
         this.SetBounds(control.Width, control.Height);
         this.mouseDownFlag = true;
         PrepareCamera();
     }
 }
Beispiel #15
0
        void winCanvas_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            int       x = e.X, y = this.BindingCanvas.Height - e.Y - 1;
            GLControl control = GetControlAt(x, y, this);

            this.currentControl = control;
            if (control != null)
            {
                GLMouseEventArgs args = e.Translate();
                control.InvokeEvent(EventType.MouseDown, args);
            }
        }
Beispiel #16
0
        void IMouseHandler.canvas_MouseMove(object sender, GLMouseEventArgs e)
        {
            if (mouseDownFlag && ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None))
            {
                if (!cameraState.IsSameState(this.camera))
                {
                    SetCamera(this.camera.Position, this.camera.Target, this.camera.UpVector);
                }

                this._endPosition = GetArcBallPosition(e.X, e.Y);
                var cosRadian = _startPosition.dot(_endPosition) / (_startPosition.length() * _endPosition.length());
                if (cosRadian > 1.0f)
                {
                    cosRadian = 1.0f;
                }
                else if (cosRadian < -1)
                {
                    cosRadian = -1.0f;
                }
                float angle = MouseSensitivity * (float)(Math.Acos(cosRadian) / Math.PI * 180);
                _normalVector = _startPosition.cross(_endPosition).normalize();
                if (!
                    ((_normalVector.x == 0 && _normalVector.y == 0 && _normalVector.z == 0) ||
                     float.IsNaN(_normalVector.x) || float.IsNaN(_normalVector.y) || float.IsNaN(_normalVector.z)))
                {
                    _startPosition = _endPosition;

                    mat4 newRotation = glm.rotate(angle, _normalVector);
                    this.totalRotation = newRotation * this.totalRotation;


                    {
                        var rotated = this.Rotated;
                        if (rotated != null)
                        {
                            Quaternion quaternion = this.totalRotation.ToQuaternion();
                            float      angleInDegree;
                            vec3       axis;
                            quaternion.Parse(out angleInDegree, out axis);
                            rotated(this, new Rotation(axis, angleInDegree, e.Button, e.Clicks, e.X, e.Y, e.Delta));
                        }
                    }
                }

                IGLCanvas canvas = this.canvas;
                if (canvas != null && canvas.RenderTrigger == RenderTrigger.Manual)
                {
                    canvas.Repaint();
                }
            }
        }
Beispiel #17
0
        void winCanvas_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            GLMouseEventArgs args = e.Translate();

            foreach (var item in this.Children)
            {
                int x = e.X, y = this.BindingCanvas.Height - e.Y;
                if (item.ContainsPoint(x, y))
                {
                    this.mouseDownControl = item;
                    item.InvokeEvent(EventType.MouseDown, args);
                }
            }
        }
Beispiel #18
0
        void IMouseHandler.canvas_MouseUp(object sender, GLMouseEventArgs e)
        {
            if ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None)
            {
                mouseDownFlag = false;

                {
                    var mouseUp = this.MouseUp;
                    if (mouseUp != null)
                    {
                        mouseUp(this, e);
                    }
                }
            }
        }
Beispiel #19
0
        void IMouseHandler.canvas_MouseMove(object sender, GLMouseEventArgs e)
        {
            if (this.mouseDownFlag &&
                ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None) &&
                (e.X != this.lastPosition.x || e.Y != this.lastPosition.y))
            {
                mat4 rotationMatrix = glm.rotate(this.HorizontalRotationSpeed * (e.X - this.lastPosition.x), -this.camera.UpVector);
                var  front          = new vec4(this.camera.GetFront(), 1.0f);
                vec4 front1         = rotationMatrix * front;
                rotationMatrix = glm.rotate(this.VerticalRotationSpeed * (this.lastPosition.y - e.Y), this.camera.GetRight());
                vec4 front2 = rotationMatrix * front1;
                //front2 = front2.normalize();
                this.camera.Target = this.camera.Position + new vec3(front2);

                this.lastPosition = e.Location;
            }
        }
Beispiel #20
0
        void IMouseHandler.canvas_MouseDown(object sender, GLMouseEventArgs e)
        {
            this.lastBindingMouseButtons = this.BindingMouseButtons;
            if ((e.Button & this.lastBindingMouseButtons) != GLMouseButtons.None)
            {
                var control = sender as Control;
                this.SetBounds(control.Width, control.Height);

                if (!cameraState.IsSameState(this.camera))
                {
                    SetCamera(this.camera.Position, this.camera.Target, this.camera.UpVector);
                }

                this._lastPosition = new Point(e.X, this.canvas.Height - e.Y - 1);

                mouseDownFlag = true;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public static GLMouseEventArgs Translate(this System.Windows.Forms.MouseEventArgs e)
        {
            var args = new GLMouseEventArgs((GLMouseButtons)e.Button, e.Clicks, e.X, e.Y, e.Delta);

            return(args);
        }
 void IMouseHandler.canvas_MouseWheel(object sender, GLMouseEventArgs e)
 {
     this.camera.MouseWheel(e.Delta);
 }
Beispiel #23
0
 void IMouseHandler.canvas_MouseWheel(object sender, GLMouseEventArgs e)
 {
 }