Exemple #1
0
        private void CreateSceneCamera()
        {
            //Debug.Print("PulsarScene.CreateSceneCamera - Creating new PulsarCamera");
            SceneCamera = new PulsarCamera("mainCamera", this, SceneDebugRenderer)
            {
                PulsarComponentClass = PulsarComponent.ComponentClass.Node,
                PulsarComponentType  = PulsarComponent.ComponentType.Camera,
                IsMainCamera         = true
            };
            ((ISystem)SceneCamera).IsSytem = true;

            SceneCamera.CreateEntity();

            SceneCamera.SetPosition(new Vector3(0, 10, -40));
            SceneCamera.Camera.Node.LookAt(Vector3.Zero, Vector3.Up);

            //Debug.Print("PulsarScene.CreateSceneCamera - Set position of main camera to - " + SceneCamera.Node.Position.ToString());

            //Debug.Print("PulsarScene.CreateSceneCamera - Calling camera BaseEntity.SetupProperties");
            SceneCamera.SetExtendedProperties();
            SceneCamera.BaseEntity.SetupProperties();
            SceneCamera.BaseEntity.IsSystem = true;

            SceneDebugRenderer.SetView(SceneCamera.Camera);
        }
Exemple #2
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);
                }
            }
        }