Esempio n. 1
0
 public ReplaceRenderable(string NodeName, IRenderable NewRenderable)
 {
     this.NodeName      = NodeName;
     this.NewRenderable = NewRenderable;
     OldRenderable      = OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendant(NodeName).Renderable;
     _isPerformed       = false;
 }
Esempio n. 2
0
        /// <summary>
        /// Prepare to invoke a button press, if the mouse was over a button when pressed
        /// </summary>
        /// <param name="e"></param>
        public void OnMouseDown(MouseEventArgs e)
        {
            if (ActiveMenu == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                Vector2 viewSpacePixel = new Vector2(
                    (2.0f * e.X / OutsideSimulatorApp.GetInstance().Width - 1.0f),
                    (-2.0f * e.Y / OutsideSimulatorApp.GetInstance().Height + 1.0f));
                foreach (var Button in MenuButtons)
                {
                    if (Button.UpperLeft.X < viewSpacePixel.X && Button.LowerRight.X > viewSpacePixel.X &&
                        Button.LowerRight.Y < viewSpacePixel.Y && Button.UpperLeft.Y > viewSpacePixel.Y)
                    {
                        Button.IsMouseDown = true;
                    }
                    else
                    {
                        Button.IsMouseDown = false;
                    }
                }
            }
        }
Esempio n. 3
0
        public void MoveObjectToInFrontOfCamera(SceneGraph Node)
        {
            Cameras.Camera SceneCamera = OutsideSimulatorApp.GetInstance().SceneCamera;
            Vector3        lav         = (SceneCamera.LookAt - SceneCamera.Position);

            lav.Normalize();
            Node.Translation = OutsideSimulatorApp.GetInstance().SceneCamera.Position + lav * frontDist;
        }
 /// <summary>
 /// Create the action to create an object
 /// </summary>
 /// <param name="parent">The parent scene node to which to attach the object</param>
 /// <param name="renderable">The renderable to provide to the node</param>
 public CreateObject(IRenderable renderable, Matrix transform)
 {
     IsPerformed = false;
     ParentNode  = OutsideSimulatorApp.GetInstance().SceneRootNode;
     ChildName   = (ParentNode.GetHashCode() + DateTime.Now.GetHashCode()).ToString();
     Renderable  = renderable;
     Transform   = transform;
 }
Esempio n. 5
0
        public static ObjectMover getInstance()
        {
            if (_inst == null)
            {
                _inst = new ObjectMover();
                OutsideSimulatorApp.GetInstance().Subscribe(_inst);
            }

            return(_inst);
        }
Esempio n. 6
0
        public void Redo()
        {
            if (_isImplemented)
            {
                throw new InvalidOperationException("MoveObject action already performed!");
            }

            OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendant(Name).Translation = NewPos;

            _isImplemented = true;
        }
Esempio n. 7
0
        public void Undo()
        {
            if (!_isImplemented)
            {
                throw new InvalidOperationException("MoveObject action has not yet been performed!");
            }

            OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendant(Name).Translation = OldPos;

            _isImplemented = false;
        }
Esempio n. 8
0
        public void Undo()
        {
            if (!_isPerformed)
            {
                throw new InvalidOperationException("This action has not yet been performed");
            }

            _isPerformed = false;

            OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendant(NodeName).Renderable = OldRenderable;
        }
Esempio n. 9
0
        public void Redo()
        {
            if (_isPerformed)
            {
                throw new InvalidOperationException("This action has already been performed");
            }

            _isPerformed = true;

            OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendant(NodeName).Renderable = NewRenderable;
        }
Esempio n. 10
0
        public void Redo()
        {
            if (_isExecuted)
            {
                throw new InvalidOperationException("Cannot redo an acction that has already been performed!");
            }

            RemovedObject = OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendant(ObjectName);

            OutsideSimulatorApp.GetInstance().SceneRootNode.RemoveDescendent(ObjectName);

            _isExecuted = true;
        }
Esempio n. 11
0
        public void Undo()
        {
            if (!_isExecuted)
            {
                throw new InvalidOperationException("Cannot undo an action that has yet to be performed!");
            }

            _isExecuted = false;

            OutsideSimulatorApp.GetInstance().SceneRootNode.AttachChild(ObjectName, RemovedObject);

            RemovedObject = null;
        }
Esempio n. 12
0
        /// <summary>
        /// Create a new menu instance, including subscribing to keypresses and all.
        /// </summary>
        /// <param name="Title">The title of this menu</param>
        /// <param name="Hotkey">The hotkey which opens/closes this menu (null for no key)</param>
        public Menu(string MenuFilename, Keys?Hotkey)
        {
            // Set up member properties
            ActiveMenu        = null; // Null if no menu active - otherwise, the currently active menu or submenu
            this.MenuFilename = MenuFilename;
            Submenus          = new List <Submenu>();
            Actions           = new List <MenuAction>();
            this.Hotkey       = Hotkey;

            // Set up logic properties
            _isHotkeyPressed = false;

            // Subscribe to our main application...
            OutsideSimulatorApp.GetInstance().Subscribe(this);
        }
Esempio n. 13
0
        public void OnMouseDown(MouseEventArgs e)
        {
            if (OutsideSimulatorApp.GetInstance().MainMenu != null &&
                OutsideSimulatorApp.GetInstance().MainMenu.ActiveMenu != null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                ClickedNode = Picker.PickClosestObject(OutsideSimulatorApp.GetInstance().SceneRootNode, OutsideSimulatorApp.GetInstance().SceneCamera,
                                                       OutsideSimulatorApp.GetInstance().ProjectionMatrix, new SlimDX.Vector2(e.X, e.Y), new SlimDX.Vector2(
                                                           OutsideSimulatorApp.GetInstance().Width, OutsideSimulatorApp.GetInstance().Height));
            }
        }
Esempio n. 14
0
        public void DeleteSelected()
        {
            //
            // Delete selected node
            //

            // Get name of descendant
            var childName = OutsideSimulatorApp.GetInstance().SceneRootNode.Children.First((x) => x.Value == ClickedNode).Key;

            var removeAction = new Commands.Undoables.DeleteObject(childName);

            removeAction.Redo();

            OutsideSimulatorApp.GetInstance().CommandStack.Push(removeAction);
        }
Esempio n. 15
0
        /// <summary>
        /// Create a MoveAction for this node
        /// </summary>
        public void FinalizeMovement()
        {
            if (Node == null)
            {
                return;
            }

            var mo = new Commands.Undoables.MoveObject(
                OutsideSimulatorApp.GetInstance().SceneRootNode.GetDescendentName(Node),
                StartPos,
                Node.Translation
                );

            mo.Redo();
            OutsideSimulatorApp.GetInstance().CommandStack.Push(mo);

            Node = null;
        }
Esempio n. 16
0
        private void RenderNode(SceneGraph Node, Camera Camera, SlimDX.Matrix ProjMatrix, int indexOffset, int vertexOffset, out int indicesConsumed, out int verticesConsumed)
        {
            var ic = indexOffset;
            var vc = vertexOffset;

            if (Node.Renderable != null)
            {
                WorldViewProj = Node.WorldTransform * Camera.GetViewMatrix() * ProjMatrix;
                CPO_WorldViewProj.SetMatrix(WorldViewProj);
                SRV_BasicTexture.SetResource(Flyweights.TextureManager.GetInstance().GetResource(Device, Node.Renderable.GetTexturePath()));
                //ImmediateContext.PixelShader.SetShaderResource(Flyweights.TextureManager.GetInstance().GetResource(Device, Node.Renderable.GetTexturePath()), 0);

                int nIndices = Node.Renderable.GetIndexList(EffectName()).Length;
                int nVerts   = Node.Renderable.GetVertexList(EffectName()).Length;

                // If selected, set the color:
                if (OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode == Node)
                {
                    CPO_SelectionColor.Set(new Color4(0.75f, 0.34f, 0.66f, 1.0f));
                }
                else
                {
                    CPO_SelectionColor.Set(new Color4(0.0f, 0.0f, 0.0f, 0.0f));
                }

                Pass.Apply(ImmediateContext);
                ImmediateContext.DrawIndexed(nIndices, indexOffset, vertexOffset);

                ic += nIndices;
                vc += nVerts;
            }

            foreach (var Child in Node.Children)
            {
                int cic, cvc;
                RenderNode(Child.Value, Camera, ProjMatrix, indexOffset + ic, vertexOffset + vc, out cic, out cvc);
                ic = cic;
                vc = cvc;
            }

            indicesConsumed  = ic;
            verticesConsumed = vc;
        }
Esempio n. 17
0
        public void GetNextRenderable()
        {
            //
            // Cycle through generation chain, swap out objects.
            //
            if (!(OutsideSimulatorApp.GetInstance().SceneRootNode.Children.Count((x) => x.Value == ClickedNode) > 0))
            {
                return;
            }

            var childName = OutsideSimulatorApp.GetInstance().SceneRootNode.Children.First((x) => x.Value == ClickedNode).Key;
            var nextChain = Renderable.RenderableFactory.GetNextRenderableInModificationChain(ClickedNode.Renderable);

            if (nextChain != null)
            {
                var swapoutaction = new Commands.Undoables.ReplaceRenderable(childName, nextChain);
                swapoutaction.Redo();
                OutsideSimulatorApp.GetInstance().CommandStack.Push(swapoutaction);
            }
        }
Esempio n. 18
0
        public FlightCamera(SlimDX.Vector3 startPos) : base()
        {
            _lastMousePos = new Point(0, 0);
            _isWDown      = false;
            _isSDown      = false;
            _isADown      = false;
            _isDDown      = false;
            _isShiftDown  = false;

            _isRightMouseDown = false;

            _forwardSpeed = 0.0f;
            _rightSpeed   = 0.0f;

            _phi   = MathF.PI / 2.0f;
            _theta = 0.0f;

            BasePosition = startPos;

            OutsideSimulatorApp.GetInstance().Subscribe(this);
        }
        public void NewPlaceAction()
        {
            if (IsPlacing)
            {
                PlacingID++;
                PlacingID %= RenderableList.Count;

                IRenderable CreatedRenderable;
                CreatedRenderable = System.Activator.CreateInstance(RenderableList[PlacingID]) as IRenderable;
                CreateObject.Undo();
                OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode = LastPickedObject;
                Cameras.Camera SceneCamera = OutsideSimulatorApp.GetInstance().SceneCamera;
                Vector3        lav         = (SceneCamera.LookAt - SceneCamera.Position);
                lav.Normalize();
                CreateObject = new CreateObject(
                    CreatedRenderable,
                    Matrix.Translation(SceneCamera.Position
                                       + lav * ObjectMover.frontDist));
                CreateObject.Redo();
                OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode = CreateObject.ParentNode.Children[CreateObject.ChildName];
            }
            else
            {
                IsPlacing = true;
                PlacingID = 0;

                IRenderable CreatedRenderable;
                CreatedRenderable = System.Activator.CreateInstance(RenderableList[PlacingID]) as IRenderable;
                Cameras.Camera SceneCamera = OutsideSimulatorApp.GetInstance().SceneCamera;
                Vector3        lav         = (SceneCamera.LookAt - SceneCamera.Position);
                lav.Normalize();
                LastPickedObject = OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode;
                CreateObject     = new CreateObject(
                    CreatedRenderable,
                    Matrix.Translation(SceneCamera.Position
                                       + lav * ObjectMover.frontDist));
                CreateObject.Redo();
                OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode = CreateObject.ParentNode.Children[CreateObject.ChildName];
            }
        }
        protected void PlaceObject()
        {
            //
            // Create a new CreateObject, for the newest location
            //
            var coToSave = new CreateObject(CreateObject.ParentNode.Children[CreateObject.ChildName].Renderable,
                                            CreateObject.ParentNode.Children[CreateObject.ChildName].Transform);

            CreateObject.Undo();
            CreateObject = coToSave;
            CreateObject.Redo();

            //
            // Place
            //
            OutsideSimulatorApp.GetInstance().CommandStack.Push(CreateObject);
            IsPlacing = false;

            // Place new object (undo-able action) in our scene,
            //  at its current location (15 units in front of camera, axis-aligned to world)
            OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode = null;
        }
Esempio n. 21
0
        /// <summary>
        /// Invoke a button press, if the mouse was over a button both when pressed and released
        /// </summary>
        /// <param name="e"></param>
        public void OnMouseUp(MouseEventArgs e)
        {
            if (ActiveMenu == null)
            {
                return;
            }

            if (e.Button == MouseButtons.Left)
            {
                Vector2 viewSpacePixel = new Vector2(
                    (2.0f * e.X / OutsideSimulatorApp.GetInstance().Width - 1.0f),
                    (-2.0f * e.Y / OutsideSimulatorApp.GetInstance().Height + 1.0f));
                foreach (var Button in MenuButtons)
                {
                    if (Button.UpperLeft.X < viewSpacePixel.X && Button.LowerRight.X > viewSpacePixel.X &&
                        Button.LowerRight.Y < viewSpacePixel.Y && Button.UpperLeft.Y > viewSpacePixel.Y &&
                        Button.IsMouseDown)
                    {
                        // Invoke action!
                        if ((ActiveMenu ?? this).Submenus.Count((x) => x.Button == Button) > 0)
                        {
                            ActiveMenu = (ActiveMenu ?? this).Submenus.First((x) => x.Button == Button).Menu;
                        }
                        else if ((ActiveMenu ?? this).Actions.Count((x) => x.Button == Button) > 0)
                        {
                            (ActiveMenu ?? this).Actions.First((x) => x.Button == Button).Action.Invoke();
                            ActiveMenu = null;
                        }
                        else
                        {
                            throw new Exception("Um... Action not recognized?");
                        }
                    }
                    Button.IsMouseDown = false;
                }
            }
        }
Esempio n. 22
0
 public ObjectPicker()
 {
     ClickedNode = null;
     OutsideSimulatorApp.GetInstance().Subscribe(this);
 }
Esempio n. 23
0
        public static Menu BuildMainMenu()
        {
            Menu MainMenu           = new Menu("../../assets/MenuBases/MainMenu.dds", System.Windows.Forms.Keys.Escape);
            Menu ModifySelectedMenu = new Menu("../../assets/MenuBases/ModifySelected.dds", null);

            //
            // Modify Selected Menu
            //
            ModifySelectedMenu.AddAction("../../assets/MenuButtons/MoveObject.dds", () =>
            {
                if (OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode == null)
                {
                    return;
                }

                Scene.UserInteractions.ObjectMover.getInstance().SetNode(
                    OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode
                    );
            });

            ModifySelectedMenu.AddAction("../../assets/MenuButtons/UseNextTexture.dds", () =>
            {
                OutsideSimulatorApp.GetInstance().ObjectPicker.GetNextRenderable();
            });

            ModifySelectedMenu.AddAction("../../assets/MenuButtons/DuplicateObject.dds", () =>
            {
                // Create a new object, but at a small distance away from where the currently selected
                //  object is placed.

                var active = OutsideSimulatorApp.GetInstance().ObjectPicker.ClickedNode;

                Renderable.IRenderable newRenderable;
                SlimDX.Matrix newTransform;

                if (active == null)
                {
                    return;
                }

                // RenderableFactory to create a duplicate
                // Cheap trick, I know...
                newRenderable = Renderable.RenderableFactory.Deserialize(Renderable.RenderableFactory.Serialize(active.Renderable).ToString());

                // Transformation will be simply bounding box x direction
                newTransform = SlimDX.Matrix.Identity * active.Transform;

                newTransform *= SlimDX.Matrix.Translation(
                    new SlimDX.Vector3(
                        active.GetBoundingBox().Value.Maximum.X * 2.0f,
                        0.0f,
                        0.0f
                        )
                    );

                var co = new Commands.Undoables.CreateObject(newRenderable, newTransform);
                co.Redo();
                OutsideSimulatorApp.GetInstance().CommandStack.Push(co);
            });

            ModifySelectedMenu.AddAction("../../assets/MenuButtons/DeleteObject.dds", () =>
            {
                OutsideSimulatorApp.GetInstance().ObjectPicker.DeleteSelected();
            });

            //
            // Main Menu
            //
            MainMenu.AddAction("../../assets/MenuButtons/NewSimulation.dds", () =>
            {
                // Create a new simulation
                OutsideSimulatorApp.GetInstance().CreateNewScene();
            });

            MainMenu.AddAction("../../assets/MenuButtons/ChangeFillColor.dds", () =>
            {
                // Open a color dialog
                var ColorDialog   = new System.Windows.Forms.ColorDialog();
                ColorDialog.Color = (System.Drawing.Color)OutsideSimulatorApp.GetInstance().FillColor;

                if (ColorDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    OutsideSimulatorApp.GetInstance().FillColor = ColorDialog.Color;
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("Pick background color aborted", "Outside Simulator 2015");
                }
            });

            MainMenu.AddAction("../../assets/MenuButtons/Undo.dds", () =>
            {
                OutsideSimulatorApp.GetInstance().CommandStack.Undo();
            });

            MainMenu.AddAction("../../assets/MenuButtons/Screenshot.dds", () =>
            {
                OutsideSimulatorApp.GetInstance().MainMenu.ClearMenu();
                OutsideSimulatorApp.GetInstance().PrintScreen();
            });

            MainMenu.AddSubmenu("../../assets/MenuButtons/ModifySelected.dds", ModifySelectedMenu);

            MainMenu.AddAction("../../assets/MenuButtons/ExitButton.dds", () => { OutsideSimulatorApp.GetInstance().Close(); });

            return(MainMenu);
        }