Exemplo n.º 1
0
 public VixenPreviewDisplayD2D()
 {
     InitializeComponent();
     //direct2DControlWinForm1. = new DisplayScene(null, DisplayID);
     Scene             = new DisplayScene(null);
     Scene.IsAnimating = true;
 }
Exemplo n.º 2
0
 public VixenPreviewDisplayD2D()
 {
     InitializeComponent();
     BackColor = ThemeColorTable.BackgroundColor;
     //direct2DControlWinForm1. = new DisplayScene(null, DisplayID);
     Scene             = new DisplayScene(null);
     Scene.IsAnimating = true;
 }
Exemplo n.º 3
0
        private void DrawSelectedObjects()
        {
            if (DisplayScene.SelectedSceneObjects.SelectedObjectCount > 0)
            {
                foreach (SelectedObject selectedObject in DisplayScene.SelectedSceneObjects.ObjectList)
                {
                    if (selectedObject != null)
                    {
                        if (!selectedObject.Drawable.IsDeleted)
                        {
                            BoundingBox bounds = selectedObject.Drawable.WorldBoundingBox;
                            DisplayScene.SceneDebugRenderer.AddBoundingBox(bounds, Color.Red);
                            PulsarModel pulsarModel = selectedObject.SelectedNode.GetComponent <PulsarModel>();
                            if (pulsarModel != null)
                            {
                                var baseEntity = pulsarModel.GetBaseEntity();
                                var gizmoNode  = DisplayScene.GetChild(selectedObject.SelectedNode.Name + "_gizmo");
                                if (baseEntity != null)
                                {
                                    if (!baseEntity.IsSelected)
                                    {
                                        baseEntity.SetAsSelected();
                                    }
                                    else
                                    {
                                        //make sure the gizmo node has the correct orientation based on type
                                        switch (DragType)
                                        {
                                        case DragType.Translate:
                                            if (gizmoNode != null)
                                            {
                                                gizmoNode.Rotation = new Quaternion(0, 0, 0);
                                            }
                                            break;

                                        case DragType.Rotate:
                                        case DragType.Scale:
                                            if (gizmoNode != null)
                                            {
                                                gizmoNode.Rotation = selectedObject.SelectedNode.Rotation;
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ProcessMouseEvents()
        {
            //start by getting the main camera
            if (DisplayScene != null)
            {
                var camera = DisplayScene.GetMainCameraNode();
                if (camera != null)
                {
                    if (_input != null)
                    {
                        //zoom - middle mousewheel
                        var mouseWheelDelta = _input.MouseMoveWheel;
                        if (mouseWheelDelta != 0)
                        {
                            ProcessMouseWheel(mouseWheelDelta);
                        }

                        //Rotate - left mouse button down and mouse moving - but NOT if we are dragging!
                        if (!_dragger.IsDragging)
                        {
                            bool       mouseLeftButtonDown = _input.GetMouseButtonDown(MouseButton.Left);
                            IntVector2 mouseDeltaRotate    = _input.MouseMove; //movement is a delta from the last frame
                            if (mouseLeftButtonDown && mouseDeltaRotate != IntVector2.Zero)
                            {
                                ProcessMouseRotation(mouseDeltaRotate);
                            }
                        }

                        //panning - right mouse button down and mouse moving
                        bool       mouseRightButtonDown = _input.GetMouseButtonDown(MouseButton.Right);
                        bool       constrainKeyDown     = _input.GetKeyDown(Key.Shift) || _input.GetKeyDown(Key.LeftCtrl);
                        IntVector2 mouseDeltaPan        = _input.MouseMove;
                        if (mouseRightButtonDown && mouseDeltaPan != IntVector2.Zero)
                        {
                            ProcessMousePan(mouseDeltaPan, constrainKeyDown);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
 private void ProcessMouseEvents()
 {
     //zoom
     //start by getting the main camera
     if (DisplayScene != null)
     {
         var camera = DisplayScene.GetMainCameraNode();
         if (camera != null)
         {
             if (_input != null)
             {
                 var mouseDelta = _input.MouseMoveWheel;
                 if (mouseDelta > 0)
                 {
                     // zooming in
                     PulsarMessage pulsarMessage = new PulsarMessage
                     {
                         Type       = PulsarMessage.MessageType.MouseWheelZoomIn,
                         Iterations = 1
                     };
                     MessageQueue.PushMessage(pulsarMessage);
                 }
                 else
                 {
                     // zooming out
                     PulsarMessage pulsarMessage = new PulsarMessage
                     {
                         Type       = PulsarMessage.MessageType.MouseWheelZoomOut,
                         Iterations = 1
                     };
                     MessageQueue.PushMessage(pulsarMessage);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        private void DoGizmoTransform(Node selectedNode)
        {
            string objectName        = "";
            bool   leftButtonPressed = Input.GetMouseButtonDown(MouseButton.Left);

            if (selectedNode != null)
            {
                if (!_dragger.IsDragging)
                {
                    if (leftButtonPressed)
                    {
                        //get the main gizmo node (holds the three nodes which represent the axes)
                        var mainGizmo = selectedNode.Parent.Parent;
                        var axisName  = selectedNode.Name.Substring(0, 1);
                        //get the entity that this gizmo is associated with
                        var entityName = mainGizmo.Name.Split(new char[] { '_' });
                        if (entityName.Length > 0)
                        {
                            objectName = entityName[0];
                        }
                        if (!string.IsNullOrEmpty(objectName))
                        {
                            var selectedObject = DisplayScene.GetChild(objectName);
                            //get the current gizmo mode
                            var gizmoComponent = mainGizmo.GetComponent <Gizmo>();
                            if (gizmoComponent != null)
                            {
                                switch (DragType)
                                {
                                case DragType.Translate:
                                    DoGizmoTranslate(selectedObject, mainGizmo, axisName);
                                    break;

                                case DragType.Rotate:
                                    DoGizmoRotate(selectedObject, mainGizmo, axisName);
                                    break;

                                case DragType.Scale:
                                    DoGizmoScale(selectedObject, mainGizmo, axisName);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (leftButtonPressed && _dragger.IsDragging)
                    {
                        _dragger.MoveNodes(Input.MouseMove);
                    }
                    else
                    {
                        _dragger.IsDragging = false;
                        //Debug.Print("PuilsarApplication.DoGizmoTransform - Dragging has stopped, sending 'DraggingStopped' message");
                        SendDraggingStoppedMessage();
                    }
                }
            }
            else
            {
                if (leftButtonPressed)
                {
                    if (_dragger.IsDragging)
                    {
                        _dragger.MoveNodes(Input.MouseMove);
                    }
                    else
                    {
                        _dragger.IsDragging = false;
                        //Debug.Print("PuilsarApplication.DoGizmoTransform - Left button is pressed but dragging has stopped, sending 'DraggingStopped' message");
                        SendDraggingStoppedMessage();
                    }
                }
                else
                {
                    _dragger.IsDragging = false;
                    //Debug.Print("PuilsarApplication.DoGizmoTransform - Left button is NOT pressed, dragging has stopped, sending 'DraggingStopped' message");
                    SendDraggingStoppedMessage();
                }
            }
        }
Exemplo n.º 7
0
        protected override void OnUpdate(float timeStep)
        {
            base.OnUpdate(timeStep);

            var markedForDelete = DisplayScene.SelectedSceneObjects.ObjectList.Find(node => node.MarkForDelete == true);

            if (markedForDelete != null)
            {
                if (!markedForDelete.SelectedNode.IsDeleted)
                {
                    //is this an ACTUAL deletion from the scene
                    if (markedForDelete.RemoveFromScene)
                    {
                        var node = markedForDelete.SelectedNode;
                        if (node != null)
                        {
                            var gizmo = DisplayScene.GetChild(node.Name + "_gizmo");
                            try
                            {
                                if (gizmo != null)
                                {
                                    DisplayScene.RemoveChild(gizmo);
                                }
                            }
                            catch (Exception ex)
                            {
                                Debug.Print("An access violation occurred here attempting to remove '" + node.Name + "_gizmo'\n" + ex.Message);
                            }

                            DisplayScene.RemoveChild(node);

                            PulsarMessage pulsarMessage = new PulsarMessage
                            {
                                Type       = PulsarMessage.MessageType.RefreshTreeView,
                                Iterations = 1
                            };
                            MessageQueue.PushMessage(pulsarMessage);
                        }
                    }
                    else
                    {
                        PulsarModel pulsarModel = markedForDelete.SelectedNode?.GetComponent <PulsarModel>();
                        if (pulsarModel != null)
                        {
                            BaseEntity baseEntity = pulsarModel.GetBaseEntity();
                            if (baseEntity != null)
                            {
                                baseEntity.UnSelect();
                                DisplayScene.SelectedSceneObjects.ObjectList.Remove(markedForDelete);
                            }
                        }
                    }
                }
            }

            //TEST INPUT TO MOVE CAMERA AROUND

            Input input = Input;

            //get the camera to look at the box
            PulsarCamera camera  = DisplayScene.SceneCamera;
            Node         boxNode = DisplayScene.BoxNode;

            //camera.Camera.Node.LookAt(Vector3.Zero, Vector3.Up);

            if (_hudText == null)
            {
                _hudText = new Text();
                _hudText.SetColor(Color.Black);
                _hudText.SetFont(ResourceCache.GetFont("Fonts/arial.ttf", false), 24);

                UI.Root.AddChild(_hudText);
            }

            Node hitNode = null;


            if (Raycast(1000.0f, camera.Camera, out Vector3 hitPos, out Drawable hitDrawable))
            {
                if (hitDrawable != null)
                {
                    hitNode = hitDrawable.Node;
                    if (hitNode != null)
                    {
                        //exclude the wireFrame
                        if (!hitNode.Name.Contains("wirePlane"))
                        {
                            _hudText.Value = "Hit - " + hitNode.Name;
                            BoundingBox bounds = hitDrawable.WorldBoundingBox;
                            DisplayScene.SceneDebugRenderer.AddBoundingBox(bounds, Color.Red);
                        }
                    }
                }
            }

            // Movement speed as world units per second
            const float moveSpeed = 10.0f;
            // Read WASD keys and move the camera scene node to the
            // corresponding direction if they are pressed
            Node cameraNode = camera.Camera.Node;

            if (cameraNode != null)
            {
                if (input.GetKeyDown(Key.S))
                {
                    cameraNode.Translate(Vector3.UnitY * moveSpeed * timeStep, TransformSpace.Local);
                }
                if (input.GetKeyDown(Key.W))
                {
                    cameraNode.Translate(new Vector3(0.0f, -1.0f, 0.0f) * moveSpeed * timeStep, TransformSpace.Local);
                }
                if (input.GetKeyDown(Key.D))
                {
                    cameraNode.Translate(new Vector3(-1.0f, 0.0f, 0.0f) * moveSpeed * timeStep, TransformSpace.Local);
                }
                if (input.GetKeyDown(Key.A))
                {
                    cameraNode.Translate(Vector3.UnitX * moveSpeed * timeStep, TransformSpace.Local);
                }

                camera.BaseEntity.Position = cameraNode.Position;
                camera.BaseEntity.Rotation = cameraNode.Rotation.ToEulerAngles();
            }

            ProcessMouseEvents();

            CheckForSelection(hitNode, hitDrawable, _treeviewNodeClicked);

            DrawSelectedObjects();

            if (_dragger.IsDragging)
            {
                DoGizmoTransform(null);
            }
            else if (hitNode != null)
            {
                if (hitNode.Name.Contains("GizmoNode"))
                {
                    DoGizmoTransform(hitNode);
                }
            }
        }