예제 #1
0
        public AIMousePlate(DragHitShape dragPlane, double scale = 1, double maxXY = 100)
        {
            _dragPlane = dragPlane;
            this.Scale = scale;
            this.MaxXY = maxXY;

            this.Position = new Point3D(0, 0, 0);
            this.Up = new Vector3D(0, 1, 0);
            this.Look = new Vector3D(0, 0, -1);
        }
예제 #2
0
        public NPCNest(NPCNestDNA dna, double radius, World world, Map map, KeepItems2D keepItems2D, MaterialIDs materialIDs, Viewport3D viewport, EditorOptions editorOptions, ItemOptionsArco itemOptions, IGravityField gravity, DragHitShape dragPlane)
        {
            // Store stuff
            _world = world;
            _map = map;
            _keepItems2D = keepItems2D;
            _materialIDs = materialIDs;
            _viewport = viewport;
            _editorOptions = editorOptions;
            _itemOptions = itemOptions;
            _gravity = gravity;
            _dragPlane = dragPlane;

            // DNA
            NPCNestDNA fixedDNA = GetFinalDNA(dna);
            _shellColors = fixedDNA.ShellColors;
            _botDNA = fixedDNA.BotDNA;
            _weaponDNA = fixedDNA.WeaponDNA;

            //TODO: Hand this a winner list, and filter criteria
            _dreamer = new EvolutionDreamer(_itemOptions, _shellColors, 4);     //TODO: Num bots should come from item options
            _dreamer.WeaponDNA = EvolutionDreamer.GetRandomDNA().Item2;

            #region WPF Model

            var models = GetModel(_shellColors, radius);
            this.Model = models.Item1;
            _eggModels = models.Item2;

            _rotateTransform = new QuaternionRotation3D();
            _translateTransform = new TranslateTransform3D();

            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(_rotateTransform));
            transform.Children.Add(_translateTransform);

            ModelVisual3D visual = new ModelVisual3D();
            visual.Transform = transform;
            visual.Content = this.Model;

            this.Visuals3D = new Visual3D[] { visual };

            #endregion

            // Energy tank
            _energy = new Container();
            _energy.QuantityMax = _itemOptions.Nest_Energy_Max * radius;
            _energy.QuantityCurrent = _energy.QuantityMax * .5d;

            // Finish
            this.Token = TokenGenerator.NextToken();
            this.Radius = radius;
            this.CreationTime = DateTime.UtcNow;
        }
예제 #3
0
        public override void StartDrag(RayHitTestParameters ray)
        {
            if (this.DragAxis == null)
            {
                throw new InvalidOperationException("DragAxis needs to be set before calling this method");
            }

            if (_dragHitShape == null)
            {
                _dragHitShape = new DragHitShape();
            }
            _dragHitShape.SetShape_Line(this.DragAxis);

            _dragMouseDownClickRay = ray;
            _dragMouseDownCenterRay = new RayHitTestParameters(this.DragAxis.Origin, ray.Direction);		//TODO: the ray through the center of the part really isn't parallel to the click ray (since the perspective camera sees in a cone)
        }
예제 #4
0
        public override void StartDrag(RayHitTestParameters ray)
        {
            if (_sphereCenter == null || _sphereOrientation == null)
            {
                throw new InvalidOperationException("SphereCenter and SphereOrientation need to be set before calling this method");
            }

            if (_dragHitShape == null)
            {
                _dragHitShape = new DragHitShape();
            }
            _dragHitShape.SetShape_Sphere(this.SphereCenter, this.Radius);

            _dragMouseDownClickRay = ray;
            _dragMouseDownCenterRay = ray;
            //_dragMouseDownCenterRay = new RayHitTestParameters(this.DragAxis.Origin, ray.Direction);		//TODO: the ray through the center of the part really isn't parallel to the click ray (since the perspective camera sees in a cone)

            // Remember where they clicked (to be able to calculate the rotation in DragItem)
            Point3D? hitPoint = _dragHitShape.CastRay(ray);
            if (hitPoint == null)
            {
                // This will never happen for sphere
                _mouseDownHitPoint = new Point3D(0, 0, 0);
            }
            else
            {
                _mouseDownHitPoint = hitPoint.Value;
            }

            _mouseDownOrientation = this.SphereOrientation.ToUnit();
        }
        private void ChangeDragPlane(RayHitTestParameters clickRay)
        {
            _dragHistory.Clear();

            if (_selectedItem == null)
            {
                _dragPlane = null;
                return;
            }

            //NOTE: This was copied from Game.Newt.v2.GameItems.ShipEditor.Editor.ChangeDragHitShape()

            Point3D point = _selectedItem.Item.PositionWorld;

            RayHitTestParameters cameraLookCenter = UtilityWPF.RayFromViewportPoint(_camera, _viewport, new Point(_viewport.ActualWidth * .5d, _viewport.ActualHeight * .5d));

            // Come up with the right plane
            Vector3D standard = Math3D.GetArbitraryOrhonganal(cameraLookCenter.Direction);
            Vector3D orth = Vector3D.CrossProduct(standard, cameraLookCenter.Direction);
            ITriangle plane = new Triangle(point, point + standard, point + orth);

            _dragPlane = new DragHitShape();
            _dragPlane.SetShape_Plane(plane);

            _dragMouseDownClickRay = clickRay;
            _dragMouseDownCenterRay = new RayHitTestParameters(point, clickRay.Direction);		//TODO: the ray through the center of the part really isn't parallel to the click ray (since the perspective camera sees in a cone)
        }
        public void UnselectItem()
        {
            if (_selectedItem != null)
            {
                _selectedItem.Item.PhysicsBody.Disposing -= new EventHandler(PhysicsBody_Disposing);

                // Let overridden versions of the selected items remove any selection visuals
                _selectedItem.Dispose();
            }

            ClearDebugVisuals();

            _selectedItem = null;
            _dragPlane = null;
            _dragHistory.Clear();
        }
        public void LeftMouseUp(MouseButtonEventArgs e)
        {
            if (_selectedItem != null)
            {
                _selectedItem.StopDragging();
            }

            ClearDebugVisuals();

            _dragPlane = null;
            _dragHistory.Clear();
        }
        private void DrawLines_Plate(int numSamples, double half, double lineThickness, AxisFor axisX, AxisFor axisY, AxisFor axisZ)
        {
            const double ELAPSEDURATIONSECONDS = 1;

            // Figure out how wide to make the plate
            int totalSamples = numSamples * numSamples * numSamples;        // numsamples is per axis, so cube it
            int cellsPerSlice = _field.Size * _field.Size;
            int numSlices = Convert.ToInt32(Math.Round(Convert.ToDouble(totalSamples) / Convert.ToDouble(cellsPerSlice)));
            if (numSlices == 0)
            {
                numSlices = 1;
            }

            int toOffset = numSlices / 2;
            int fromOffset = numSlices - toOffset - 1;

            DateTime now = DateTime.UtcNow;

            bool isOverField = false;

            if (_mousePoint != null)
            {
                #region Snap to mouse

                // Cast a ray (Copied this from ItemSelectDragLogic.ChangeDragPlane, DragItem)

                Point3D point = new Point3D(0, 0, 0);

                RayHitTestParameters cameraLookCenter = UtilityWPF.RayFromViewportPoint(_camera, _viewport, new Point(_viewport.ActualWidth * .5d, _viewport.ActualHeight * .5d));

                // Come up with a snap plane
                Vector3D standard = Math3D.GetArbitraryOrhonganal(cameraLookCenter.Direction);
                Vector3D orth = Vector3D.CrossProduct(standard, cameraLookCenter.Direction);
                ITriangle plane = new Triangle(point, point + standard, point + orth);

                DragHitShape dragPlane = new DragHitShape();
                dragPlane.SetShape_Plane(plane);

                // Cast a ray onto that plane from the current mouse position
                RayHitTestParameters mouseRay = UtilityWPF.RayFromViewportPoint(_camera, _viewport, _mousePoint.Value);
                Point3D? hitPoint = dragPlane.CastRay(mouseRay);

                if (hitPoint != null)
                {
                    // Find the nearest Z cell
                    double halfSize = (_field.Size * _sizeMult) / 2d;
                    double cellSize = (_field.Size * _sizeMult) / _field.Size;

                    int zIndex = Convert.ToInt32((halfSize - axisZ.GetValue(hitPoint.Value)) / cellSize);

                    if (zIndex >= 0 && zIndex < _field.Size)
                    {
                        isOverField = true;

                        // Cap to field
                        _plateCurrentIndex = _field.Size - zIndex;        // it's actually the opposite
                        if (_plateCurrentIndex - fromOffset < 0)
                        {
                            _plateCurrentIndex = fromOffset;
                        }
                        else if (_plateCurrentIndex + toOffset > _field.Size - 1)
                        {
                            _plateCurrentIndex = _field.Size - toOffset - 1;
                        }

                        _sceneRemaining = now + TimeSpan.FromSeconds(ELAPSEDURATIONSECONDS);
                    }
                }

                #endregion
            }

            if (!isOverField)
            {
                #region Shift the plate

                if (_plateCurrentIndex + toOffset > _field.Size - 1)
                {
                    _plateCurrentIndex = _field.Size - toOffset - 1;
                    _sceneRemaining = now + TimeSpan.FromSeconds(ELAPSEDURATIONSECONDS);
                }
                else if (now > _sceneRemaining)
                {
                    _plateCurrentIndex--;

                    if (_plateCurrentIndex - fromOffset <= 0)
                    {
                        _plateCurrentIndex = _field.Size - toOffset - 1;
                    }

                    _sceneRemaining = now + TimeSpan.FromSeconds(ELAPSEDURATIONSECONDS);
                }

                #endregion
            }

            double[] velX = _field.VelocityX;
            double[] velY = _field.VelocityY;
            double[] velZ = _field.VelocityZ;

            bool[] blocked = _field.Blocked;

            _velocityLines.BeginAddingLines();

            for (int z = _plateCurrentIndex - fromOffset; z <= _plateCurrentIndex + toOffset; z++)
            {
                for (int x = 0; x < _field.Size; x++)
                {
                    for (int y = 0; y < _field.Size; y++)
                    {
                        int xRef = -1;
                        int yRef = -1;
                        int zRef = -1;

                        axisX.Set3DIndex(ref xRef, ref yRef, ref zRef, x);
                        axisY.Set3DIndex(ref xRef, ref yRef, ref zRef, y);
                        axisZ.Set3DIndex(ref xRef, ref yRef, ref zRef, z);

                        int index1D = _field.Get1DIndex(xRef, yRef, zRef);

                        if (blocked[index1D])
                        {
                            continue;
                        }

                        DrawLinesSprtAddLine(xRef, yRef, zRef, index1D, half, lineThickness, velX, velY, velZ);
                    }
                }
            }

            _velocityLines.EndAddingLines();
        }
예제 #9
0
 public ArcBotNPC(BotDNA dna, int level, Point3D position, World world, Map map, KeepItems2D keepItems2D, MaterialIDs materialIDs, Viewport3D viewport, EditorOptions editorOptions, ItemOptionsArco itemOptions, IGravityField gravity, DragHitShape dragPlane, Point3D homingPoint, double homingRadius, bool runNeural, bool repairPartPositions)
     : base(dna, level, position, world, map, keepItems2D, materialIDs, viewport, editorOptions, itemOptions, gravity, dragPlane, homingPoint, homingRadius, runNeural, repairPartPositions) { }
예제 #10
0
        //TODO: This functionality should be part of MapObjectChaseVelocity
        private static Point3D? AdjustIfOffPlane(Point3D itemPos, double itemRadius, DragHitShape dragPlane, Point3D? chasePoint)
        {
            const double MAXOFFSET = 1.5;
            const double PERCENTATMAX = .01;        // even if they are really far off the plane, don't completely chase the plane, some percent needs to go toward the chase point passed in

            Point3D? pointOnPlane = dragPlane.CastRay(itemPos);
            if (pointOnPlane == null)
            {
                // Don't know where they are relative to the plane (this should never happen)
                return chasePoint;
            }
            else if (Math3D.IsNearValue(pointOnPlane.Value, itemPos))
            {
                // They're position is the same as the point on the plane (they are already on the plane)
                return chasePoint;
            }

            Vector3D vectToPlane = (itemPos - pointOnPlane.Value);
            double distToPlane = vectToPlane.Length;
            if (distToPlane < itemRadius * .01)
            {
                // They are less than a percent of their body size off the plane, just return the point passed in
                return chasePoint;
            }

            if (chasePoint == null)
            {
                // Null was passed in, just go straight for the plane (this should never happen)
                return pointOnPlane;
            }

            // Figure out how much to dive for the plane vs go for the chase point
            double offset = distToPlane / itemRadius;
            double percent = PERCENTATMAX;
            if (offset < MAXOFFSET)
            {
                // They are less than the max allowable distance from the plane
                percent = UtilityCore.GetScaledValue_Capped(PERCENTATMAX, 1d, 0, MAXOFFSET, MAXOFFSET - offset);
            }

            Vector3D direction = chasePoint.Value - pointOnPlane.Value;

            return pointOnPlane.Value + (direction * percent);
        }
예제 #11
0
        public Editor()
        {
            //TODO: Research loading/saving in xaml
            //System.Windows.Markup.XamlReader test2 = new System.Windows.Markup.XamlReader();
            //System.Windows.Markup.XamlWriter test3;
            //MeshGeometry3D test;

            InitializeComponent();

            // Without this, the xaml can't bind to the custom dependency properties
            this.DataContext = this;

            #region Camera Trackball

            _trackball = new TrackBallRoam(_camera);
            _trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
            _trackball.AllowZoomOnMouseWheel = true;
            _trackball.ZoomScale *= .25d;
            _trackball.KeyPanScale *= .1d;

            //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
            #region copied from MouseComplete_NoLeft - middle button changed

            TrackBallMapping complexMapping = null;

            // Middle Button
            complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection_AutoScroll);
            complexMapping.Add(MouseButton.Middle);
            complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
            complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
            _trackball.Mappings.Add(complexMapping);
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.RotateAroundLookDirection, MouseButton.Middle, new Key[] { Key.LeftCtrl, Key.RightCtrl }));

            complexMapping = new TrackBallMapping(CameraMovement.Zoom_AutoScroll);
            complexMapping.Add(MouseButton.Middle);
            complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
            complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
            _trackball.Mappings.Add(complexMapping);
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Zoom, MouseButton.Middle, new Key[] { Key.LeftShift, Key.RightShift }));

            //retVal.Add(new TrackBallMapping(CameraMovement.Pan_AutoScroll, MouseButton.Middle));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan, MouseButton.Middle));

            // Left+Right Buttons (emulate middle)
            complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection_AutoScroll);
            complexMapping.Add(MouseButton.Left);
            complexMapping.Add(MouseButton.Right);
            complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
            complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
            _trackball.Mappings.Add(complexMapping);

            complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection);
            complexMapping.Add(MouseButton.Left);
            complexMapping.Add(MouseButton.Right);
            complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
            _trackball.Mappings.Add(complexMapping);

            complexMapping = new TrackBallMapping(CameraMovement.Zoom_AutoScroll);
            complexMapping.Add(MouseButton.Left);
            complexMapping.Add(MouseButton.Right);
            complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
            complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
            _trackball.Mappings.Add(complexMapping);

            complexMapping = new TrackBallMapping(CameraMovement.Zoom);
            complexMapping.Add(MouseButton.Left);
            complexMapping.Add(MouseButton.Right);
            complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
            _trackball.Mappings.Add(complexMapping);

            //complexMapping = new TrackBallMapping(CameraMovement.Pan_AutoScroll);
            complexMapping = new TrackBallMapping(CameraMovement.Pan);
            complexMapping.Add(MouseButton.Left);
            complexMapping.Add(MouseButton.Right);
            _trackball.Mappings.Add(complexMapping);

            // Right Button
            complexMapping = new TrackBallMapping(CameraMovement.RotateInPlace_AutoScroll);
            complexMapping.Add(MouseButton.Right);
            complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
            complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
            _trackball.Mappings.Add(complexMapping);
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.RotateInPlace, MouseButton.Right, new Key[] { Key.LeftCtrl, Key.RightCtrl }));

            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit_AutoScroll, MouseButton.Right, new Key[] { Key.LeftAlt, Key.RightAlt }));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Right));

            #endregion

            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_In, Key.OemPlus));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_In, Key.Add));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_Out, Key.OemMinus));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_Out, Key.Subtract));

            _trackball.ShouldHitTestOnOrbit = true;

            _trackball.UserMovedCamera += new EventHandler<UserMovedCameraArgs>(Trackball_UserMovedCamera);

            #endregion

            _dragHitShape = new DragHitShape();
            //TODO: Add this to the options (the visual should let the user drag a cone)
            //_dragHitShape.ConstrainMinDotProduct = _options.DragHitShape_ConstrainMinDotProduct;
            ChangeDragHitShape();

            // Compass Rose
            _compassRose = GetCompassRose(_options.EditorColors);
            _viewport.Children.Add(_compassRose);

            #region Ship name textbox

            // The textbox's cursor can't be set directly, but is the opposite of background.  If I just use null or transparent, the cursor is still
            // black, so I'm making the background transparent black, which makes the cursor white;
            //txtName.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
            //txtShipName.Background = new SolidColorBrush(Color.FromArgb(0, _options.EditorColors.Background.R, _options.EditorColors.Background.G, _options.EditorColors.Background.B));
            txtDesignName.Background = new SolidColorBrush(Color.FromArgb(25, _options.EditorColors.Panel_Background.R, _options.EditorColors.Panel_Background.G, _options.EditorColors.Panel_Background.B));

            txtDesignName.Foreground = new SolidColorBrush(_options.EditorColors.PartVisual_TextColor);

            #endregion

            _isInitialized = true;

            btnNewLayer_Click(this, new RoutedEventArgs());		// all layers
            btnNewLayer_Click(this, new RoutedEventArgs());		// first real layer
        }