Пример #1
0
        public void LeftMouseDown(MouseButtonEventArgs e, Visual3D[] ignoreVisuals)
        {
            // Fire a ray at the mouse point
            Point clickPoint = e.GetPosition(_visual);

            RayHitTestParameters   clickRay;
            List <MyHitTestResult> hits = UtilityWPF.CastRay(out clickRay, clickPoint, _visual, _camera, _viewport, true, ignoreVisuals);

            // See if they clicked on something
            var clickedItem = GetHit(hits);

            if (clickedItem != null)
            {
                ChangeSelectedItem(clickedItem, clickPoint);
            }
            else
            {
                UnselectItem();
            }

            // Update the drag plane
            ChangeDragPlane(clickRay);
        }
Пример #2
0
        private void grdViewPort_MouseDown(object sender, MouseButtonEventArgs e)
        {
            const double CLICKDISTANCE = BOUNDRYSIZE / 8;

            try
            {
                if (e.ChangedButton != MouseButton.Left)
                {
                    // All the special logic in this method is for the left button
                    return;
                }

                // Fire a ray at the mouse point
                Point clickPoint2D = e.GetPosition(grdViewPort);

                RayHitTestParameters   clickRay;
                List <MyHitTestResult> hits = UtilityWPF.CastRay(out clickRay, clickPoint2D, _viewport, _camera, _viewport, false);

                // Figure out where to place the point
                Point3D   clickPoint3D;
                ITriangle clickPlane = null;
                if (hits != null && hits.Count > 0)
                {
                    // They clicked on something, so use that
                    clickPoint3D = hits[0].Point;
                }
                else
                {
                    //TODO: If there is a mothership, choose a point in a plane that goes through it (orth to the click ray)
                    //
                    // If there isn't, but they click near a swarm, use that plane
                    //
                    // Or if they click near something (like an asteroid)

                    double?clickDistNearSwarm = GetClickDistanceNearSwarm(clickRay);

                    double clickDist;
                    if (clickDistNearSwarm == null)
                    {
                        clickDist = Math.Max(CLICKDISTANCE, _camera.Position.ToVector().Length / 1.1);
                    }
                    else
                    {
                        clickDist = clickDistNearSwarm.Value;
                    }

                    clickPoint3D = clickRay.Origin + clickRay.Direction.ToUnit() * clickDist;
                }

                // Update the click plane
                if (clickPlane == null)
                {
                    Vector3D standard = Math3D.GetArbitraryOrhonganal(clickRay.Direction);
                    Vector3D orth     = Vector3D.CrossProduct(standard, clickRay.Direction);
                    clickPlane = new Triangle(clickPoint3D, clickPoint3D + standard, clickPoint3D + orth);
                }

                // Store the point and plane
                _strokes.AddPointToStroke(clickPoint3D);
                _clickPlane = clickPlane;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }