/// <summary>
        /// Handles mouse-move events</summary>
        /// <param name="sender">Control that raised original event</param>
        /// <param name="e">Event args</param>
        /// <returns>true, if controller handled the event</returns>
        public override bool MouseMove(object sender, MouseEventArgs e)
        {
            if (m_dragging &&
                InputScheme.ActiveControlScheme.IsControllingCamera(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                Control c  = sender as Control;
                float   dx = (e.X - m_lastMousePoint.X) * (4.0f / c.Width);
                float   dy = (e.Y - m_lastMousePoint.Y) * (4.0f / c.Height);

                if (InputScheme.ActiveControlScheme.IsRotating(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)) &&
                    (Camera.ViewType == ViewTypes.Perspective || LockOrthographic == false))
                {
                    // elevation
                    m_elevation += dy;
                    if (m_elevation > PI)
                    {
                        m_elevation -= TwoPI;
                    }
                    else if (m_elevation < -PI)
                    {
                        m_elevation += TwoPI;
                    }

                    // azimuth
                    m_azimuth -= dx;
                    if (m_azimuth > PI)
                    {
                        m_azimuth -= TwoPI;
                    }
                    else if (m_azimuth < -PI)
                    {
                        m_azimuth += TwoPI;
                    }

                    if (Camera.ViewType != ViewTypes.Perspective)
                    {
                        Camera.ViewType = ViewTypes.Perspective;
                    }

                    ControllerToCamera();
                }
                else if (InputScheme.ActiveControlScheme.IsZooming(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
                {
                    float       zoom      = (-dy - dx);
                    const float ZoomScale = 0.7f; // fudge factor to get the right amount of zoom
                    m_distanceFromLookAt += zoom * CalculateZoomScale() * ZoomScale;
                    ControllerToCamera();
                }
                else if (InputScheme.ActiveControlScheme.IsPanning(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
                {
                    // The fudge factor was calculated so that an object that is fitted to view will have
                    // its pivot point stay under the cursor during panning. This was tested using the proxy
                    // cube. 0.25f was a bit too high.
                    float s = CalculateZoomScale() * 0.21f;
                    if (s > 0)
                    {
                        m_lookAtPoint += Camera.Up * dy * s;
                        m_lookAtPoint += Camera.Right * -dx * s * Camera.Aspect;
                    }
                    else
                    {
                        m_lookAtPoint -= Camera.Up * dy * s;
                        m_lookAtPoint -= Camera.Right * -dx * s * Camera.Aspect;
                    }

                    ControllerToCamera();
                }

                m_lastMousePoint = e.Location;
                return(true);
            }

            return(base.MouseMove(sender, e));
        }
예제 #2
0
 /// <summary>
 /// Should the camera do a panning (strafing) motion?</summary>
 /// <param name="controlScheme">The control scheme instance to extend</param>
 /// <param name="modifierKeys">The camera control's ModifierKeys property</param>
 /// <param name="e">The camera control's event handler's WfMouseEventArgs</param>
 /// <returns>True if the user wants to pan the camera</returns>
 /// <remarks>This is used by the arcball and trackball camera controllers.</remarks>
 public static bool IsPanning(this ControlScheme controlScheme, WfKeys modifierKeys, WfMouseEventArgs e)
 {
     return(controlScheme.IsPanning(KeysInterop.ToAtf(modifierKeys), MouseEventArgsInterop.ToAtf(e)));
 }
        /// <summary>
        /// Handles mouse-down events</summary>
        /// <param name="sender">Control that raised original event</param>
        /// <param name="e">Event args</param>
        /// <returns>true, if controller handled the event</returns>
        public override bool MouseDown(object sender, MouseEventArgs e)
        {
            if (InputScheme.ActiveControlScheme.IsControllingCamera(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                m_lastMousePoint = e.Location;
                m_dragging       = true;
                return(true);
            }

            return(base.MouseDown(sender, e));
        }
        /// <summary>
        /// Handles mouse wheel events for zooming in and out. By the standard of Microsoft
        /// and AutoCAD and others, scrolling the mouse wheel away from the user zooms in
        /// and scrolling the mouse wheel towards the user zooms out. </summary>
        /// <param name="sender">Control that raised original event</param>
        /// <param name="e">Event args</param>
        /// <returns>true, if controller handled the event</returns>
        public override bool MouseWheel(object sender, MouseEventArgs e)
        {
            if (!InputScheme.ActiveControlScheme.IsZooming(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                return(true);
            }



            // disable accelerated vertical scrolling.
            int eDelta = e.Delta > 0 ? 120 : -120;

            // on a Logitech mouse, scrolling back by one "notch" made e.Delta be -120.
            float delta = -eDelta *CalculateZoomScale() * 0.002f;

            // account for the fact that zooming in starts with a larger look-at distance
            if (eDelta > 0)
            {
                float origLookAtDist = m_distanceFromLookAt;
                m_distanceFromLookAt += delta;
                delta = -eDelta *CalculateZoomScale() * 0.002f;

                m_distanceFromLookAt = origLookAtDist;
            }

            //minimum distance to travel in world space with one wheel "notch". If this is too
            // small, zooming can feel too slow as we get close to the look-at-point.
            const float min_wheel_delta = 1.5f;

            if (delta > -min_wheel_delta && delta < min_wheel_delta)
            {
                if (delta < 0.0f)
                {
                    delta = -min_wheel_delta;
                }
                else
                {
                    delta = min_wheel_delta;
                }
            }

            m_distanceFromLookAt += delta;
            ControllerToCamera();
            return(true);
        }
예제 #5
0
        public override bool MouseDown(object sender, MouseEventArgs e)
        {
            if (InputScheme.ActiveControlScheme.IsControllingCamera(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                m_lastMousePointX = e.Location.X;
                m_lastMousePointY = e.Location.Y;
                m_dragging        = true;
                return(true);
            }

            if (Control.ModifierKeys.HasFlag(Keys.Control) && !Control.ModifierKeys.HasFlag(Keys.Shift) && e.Button == MouseButtons.Left)
            {
                // "control + l click" repositions the "focus" point of the camera
                //      -- it's just incredibly useful to be able to manually set the point, because it
                //          allows the user to specify both the speed of the movement of the camera and
                //          the orbit of the camera in a natural way
                //
                // We could expand "ActiveControlScheme" to allow this key binding to be rebound...
                // but just using fixed binding for now.
                // This is a very important key combination (it's just really useful to be able to move
                // the focus around quickly) -- so it should be accessable with any easy combination from
                // anywhere!

                ViewControl           c  = sender as ViewControl;
                GUILayer.IViewContext vc = sender as GUILayer.IViewContext;
                if (c != null && vc != null)
                {
                    // We can use XLEBridgeUtils to do the ray test. This will
                    // execute the native code (which in turn performs the intersection
                    // on the GPU)
                    // Note that we're using the more complex picking interface because
                    // we want to use explicitly pass "Camera" (rather than
                    // getting it from the view control)
                    var hit = XLEBridgeUtils.Picking.RayPick(
                        GUILayer.EngineDevice.GetInstance(),
                        vc.SceneManager, vc.TechniqueContext,
                        c.GetWorldRay(e.Location), XLEBridgeUtils.Utils.AsCameraDesc(Camera), c.ClientSize,
                        XLEBridgeUtils.Picking.Flags.AllWorldObjects);
                    if (hit != null && hit.Length > 0)
                    {
                        Vec3F transformedPt;
                        Camera.AxisSystem.Transform(hit[0].hitPt, out transformedPt);
                        Camera.Set(Camera.Eye, transformedPt, Camera.Up);
                    }
                }

                return(true);
            }

            return(base.MouseDown(sender, e));
        }
예제 #6
0
        public override bool MouseWheel(object sender, MouseEventArgs e)
        {
            if (!InputScheme.ActiveControlScheme.IsZooming(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                return(true);
            }

            float adj       = Camera.DistanceFromLookAt;
            var   zoomSpeed = .1f / 120.0f * adj;
            var   lookAtDir = Vec3F.Normalize(Camera.LookAt);
            var   movement  = Math.Min(e.Delta * zoomSpeed, Camera.DistanceFromLookAt - 0.1f);

            Camera.Set(Camera.Eye + lookAtDir * movement, Camera.LookAtPoint, Camera.Up);
            return(true);
        }
예제 #7
0
        public override bool MouseMove(object sender, MouseEventArgs e)
        {
            if (m_dragging &&
                InputScheme.ActiveControlScheme.IsControllingCamera(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
            {
                Control c  = sender as Control;
                float   dx = e.X - m_lastMousePointX;
                float   dy = e.Y - m_lastMousePointY;

                if (InputScheme.ActiveControlScheme.IsRotating(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)) &&
                    (Camera.ViewType == ViewTypes.Perspective || LockOrthographic == false))
                {
                    var orbitRotationSpeed = .0005f * (float)Math.PI;

                    // just do this orbitting calculation in spherical coords...
                    // it's much easier than any other method
                    var orbitCenter = Camera.LookAtPoint;
                    var spherical   = CartesianToSphericalYUp(orbitCenter - Camera.Eye);
                    spherical[0] += dy * orbitRotationSpeed;
                    spherical[0]  = Clamp(spherical[0], (float)Math.PI * 0.02f, (float)Math.PI * 0.98f);
                    spherical[1] += dx * orbitRotationSpeed;

                    var defaultUp = new Vec3F(0.0f, 1.0f, 0.0f);    // (geometry gets hopelessly unnormalized if we don't reset default-up here)
                    Camera.Set(orbitCenter - SphericalToCartesianYUp(spherical), orbitCenter, defaultUp);
                    if (Camera.ViewType != ViewTypes.Perspective)
                    {
                        Camera.ViewType = ViewTypes.Perspective;
                    }
                }
                else if (InputScheme.ActiveControlScheme.IsZooming(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
                {
                    float zoom = (-dy - dx);

                    float adj       = Camera.DistanceFromLookAt;
                    var   zoomSpeed = 0.01f * adj;
                    var   lookAtDir = Vec3F.Normalize(Camera.LookAt);
                    var   movement  = Math.Min(zoom * zoomSpeed, Camera.DistanceFromLookAt - 0.1f);
                    Camera.Set(Camera.Eye + lookAtDir * movement, Camera.LookAtPoint, Camera.Up);
                }
                else if (InputScheme.ActiveControlScheme.IsPanning(KeysInterop.ToAtf(Control.ModifierKeys), MouseEventArgsInterop.ToAtf(e)))
                {
                    float adj         = Camera.DistanceFromLookAt;
                    var   panSpeed    = 0.001f * adj;
                    var   lookAtPoint = Camera.LookAtPoint;
                    var   translation = (Camera.Up * dy * panSpeed) + (Camera.Right * -dx * panSpeed);
                    Camera.Set(Camera.Eye + translation, lookAtPoint + translation, Camera.Up);
                }

                m_lastMousePointX = e.Location.X;
                m_lastMousePointY = e.Location.Y;
                return(true);
            }

            return(base.MouseMove(sender, e));
        }