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;
     }
 }
Пример #2
0
 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();
     }
 }
Пример #3
0
        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) / 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) / 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());
                camera.UpVector   = up;
                this.back         = back;
                this.right        = right;
                this.up           = up;
                this.lastPosition = e.Location;
            }
        }
Пример #4
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;
            }
        }
Пример #5
0
        /// <summary>
        /// Define a picking region.
        /// </summary>
        /// <param name="center">The center.</param>
        /// <param name="delta">The delta.</param>
        /// <param name="viewport">The viewport.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        public static mat4 pickMatrix(ivec2 center, ivec2 delta, ivec4 viewport)
        {
            if (delta.x <= 0 || delta.y <= 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            var Result = new mat4(1.0f);

            if (!(delta.x > (0f) && delta.y > (0f)))
            {
                return(Result); // Error
            }
            vec3 Temp = new vec3(
                ((viewport[2]) - (2f) * (center.x - (viewport[0]))) / delta.x,
                ((viewport[3]) - (2f) * (center.y - (viewport[1]))) / delta.y,
                (0f));

            // Translate and scale the picked region to the entire window
            Result = translate(Result, Temp);
            return(scale(Result, new vec3((float)(viewport[2]) / delta.x, (float)(viewport[3]) / delta.y, (1))));
        }
Пример #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="xy"></param>
 /// <param name="z"></param>
 public ivec3(ivec2 xy, int z)
 {
     this.x = xy.x;
     this.y = xy.y;
     this.z = z;
 }